-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Primitives in Detail Formatter #586
Open
SougandhS
wants to merge
1
commit into
eclipse-jdt:master
Choose a base branch
from
SougandhS:DetalFormatter_for_Primitives_and_Arrays
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+564
−31
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
org.eclipse.jdt.debug.tests/testsource-j2se-1.5/a/b/c/primitivesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package a.b.c; | ||
|
||
public class primitivesTest { | ||
public static void main(String[] args) { | ||
Double xd = Double.valueOf(1); | ||
int x = 12; | ||
float f = 10; | ||
int[] arInt = { 1, 2, 3 }; | ||
char[] aCh = { 'a', 'b' }; | ||
boolean b = false; | ||
double[] d = { 1, 3, 4 }; | ||
int[][] mul = { { 1, 3, 4 }, { 1, 3, 4 } }; | ||
int p1 = 120; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2000, 2015 IBM Corporation and others. | ||
* Copyright (c) 2000, 2025 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -51,6 +51,9 @@ | |
import org.eclipse.jface.text.IDocumentListener; | ||
import org.eclipse.jface.text.contentassist.IContentAssistProcessor; | ||
import org.eclipse.jface.text.source.ISourceViewer; | ||
import org.eclipse.jface.viewers.ArrayContentProvider; | ||
import org.eclipse.jface.viewers.LabelProvider; | ||
import org.eclipse.jface.window.Window; | ||
import org.eclipse.osgi.util.NLS; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.ModifyEvent; | ||
|
@@ -67,6 +70,7 @@ | |
import org.eclipse.ui.IWorkbench; | ||
import org.eclipse.ui.IWorkbenchCommandConstants; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.dialogs.ListDialog; | ||
import org.eclipse.ui.dialogs.SelectionDialog; | ||
import org.eclipse.ui.handlers.IHandlerActivation; | ||
import org.eclipse.ui.handlers.IHandlerService; | ||
|
@@ -168,11 +172,10 @@ protected Control createDialogArea(Composite parent) { | |
Font font = parent.getFont(); | ||
Composite container = (Composite)super.createDialogArea(parent); | ||
|
||
SWTFactory.createLabel(container, DebugUIMessages.DetailFormatterDialog_Qualified_type__name__2, 1); | ||
SWTFactory.createLabel(container, DebugUIMessages.DetailFormatterDialog_Qualified_type__name__2, 2); | ||
|
||
Composite innerContainer = SWTFactory.createComposite(container, font, 2, 1, GridData.FILL_HORIZONTAL); | ||
|
||
fTypeNameText = SWTFactory.createSingleText(innerContainer, 1); | ||
fTypeNameText = SWTFactory.createSingleText(innerContainer, 2); | ||
fTypeNameText.setEditable(fEditTypeName); | ||
fTypeNameText.setText(fDetailFormatter.getTypeName()); | ||
fTypeNameText.addModifyListener(new ModifyListener() { | ||
|
@@ -182,16 +185,31 @@ public void modifyText(ModifyEvent e) { | |
checkValues(); | ||
} | ||
}); | ||
Button primitiveSearchButton = SWTFactory.createPushButton(innerContainer, DebugUIMessages.DetailFormatterPrimitiveSelect, null); | ||
primitiveSearchButton.setEnabled(fEditTypeName); | ||
|
||
GridData gridLayout = new GridData(GridData.FILL_HORIZONTAL); | ||
gridLayout.horizontalSpan = 1; | ||
gridLayout.grabExcessHorizontalSpace = true; | ||
primitiveSearchButton.setLayoutData(gridLayout); | ||
primitiveSearchButton.addListener(SWT.Selection, new Listener() { | ||
@Override | ||
public void handleEvent(Event e) { | ||
selectPrimitiveType(); | ||
} | ||
}); | ||
|
||
Button typeSearchButton = SWTFactory.createPushButton(innerContainer, DebugUIMessages.DetailFormatterDialog_Select__type_4, null); | ||
typeSearchButton.setEnabled(fEditTypeName); | ||
typeSearchButton.setLayoutData(gridLayout); | ||
typeSearchButton.addListener(SWT.Selection, new Listener() { | ||
@Override | ||
public void handleEvent(Event e) { | ||
selectType(); | ||
} | ||
}); | ||
|
||
|
||
String labelText = null; | ||
IBindingService bindingService = workbench.getAdapter(IBindingService.class); | ||
String binding = bindingService.getBestActiveBindingFormattedFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST); | ||
|
@@ -281,7 +299,7 @@ private void checkValues() { | |
status.setError(DebugUIMessages.DetailFormatterDialog_A_detail_formatter_is_already_defined_for_this_type_2); | ||
} else if (fSnippetViewer.getDocument().get().trim().length() == 0) { | ||
status.setError(DebugUIMessages.DetailFormatterDialog_Associated_code_must_not_be_empty_3); | ||
} else if (fType == null && fTypeSearched) { | ||
} else if (fType == null && fTypeSearched && !getPrimitiveTypes().contains(typeName)) { | ||
status.setWarning(DebugUIMessages.No_type_with_the_given_name_found_in_the_workspace__1); | ||
} | ||
updateStatus(status); | ||
|
@@ -306,15 +324,13 @@ private void selectType() { | |
Shell shell= getShell(); | ||
SelectionDialog dialog= null; | ||
try { | ||
dialog= JavaUI.createTypeDialog(shell, PlatformUI.getWorkbench().getProgressService(), | ||
SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false, fTypeNameText.getText()); | ||
dialog = JavaUI.createTypeDialog(shell, PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false, fTypeNameText.getText()); | ||
} catch (JavaModelException jme) { | ||
String title= DebugUIMessages.DetailFormatterDialog_Select_type_6; | ||
String message= DebugUIMessages.DetailFormatterDialog_Could_not_open_type_selection_dialog_for_detail_formatters_7; | ||
ExceptionHandler.handle(jme, title, message); | ||
return; | ||
} | ||
|
||
dialog.setTitle(DebugUIMessages.DetailFormatterDialog_Select_type_8); | ||
dialog.setMessage(DebugUIMessages.DetailFormatterDialog_Select_a_type_to_format_when_displaying_its_detail_9); | ||
if (dialog.open() == IDialogConstants.CANCEL_ID) { | ||
|
@@ -329,6 +345,43 @@ private void selectType() { | |
} | ||
} | ||
|
||
/** | ||
* Open the 'select type' dialog, and set the primitive into the formatter. | ||
*/ | ||
private void selectPrimitiveType() { | ||
Shell shell = getShell(); | ||
ListDialog listDialog = new ListDialog(shell); | ||
listDialog.setTitle(DebugUIMessages.DetailFormatterDialog_Select_type_8); | ||
listDialog.setMessage(DebugUIMessages.DetailFormatterPrimitiveSelectionLabel); | ||
listDialog.setInput(getPrimitiveTypes().toArray()); | ||
listDialog.setContentProvider(ArrayContentProvider.getInstance()); | ||
listDialog.setLabelProvider(new LabelProvider() { | ||
@Override | ||
public String getText(Object element) { | ||
return (String) element; | ||
} | ||
}); | ||
if (listDialog.open() == Window.CANCEL) { | ||
return; | ||
} | ||
Object[] types = listDialog.getResult(); | ||
if (types != null && types.length > 0) { | ||
String s = (String) types[0]; | ||
fTypeNameText.setText(s); | ||
fTypeSearched = true; | ||
} | ||
} | ||
|
||
/** | ||
* Returns a List of available primitives and arrays | ||
* | ||
* @return List primitives and arrays | ||
*/ | ||
@SuppressWarnings("nls") | ||
private List<String> getPrimitiveTypes() { | ||
return List.of("int", "long", "short", "float", "double", "boolean", "char", "byte", "int[]", "long[]", "short[]", "float[]", "double[]", "boolean[]", "char[]", "byte[]"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it work with arrays of multiple dimensions? for example char[][] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it works.. added test case for that too |
||
} | ||
|
||
/** | ||
* Use the Java search engine to find the type which corresponds | ||
* to the given name. | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are this lines removed intantionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.. to get detail formatter option in variables view