Skip to content

Commit fc69018

Browse files
SougandhSakurtakov
authored andcommitted
Cleanup : Use instanceof Pattern matching in
Use InstanceOf pattern matching in few classes in o.e.jdt.internal.debug.ui.actions
1 parent d1d0e57 commit fc69018

19 files changed

+30
-61
lines changed

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/AttachSourceAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ protected boolean updateSelection(IStructuredSelection selection) {
6868
int i = 0;
6969
while (iterator.hasNext()) {
7070
Object selected= iterator.next();
71-
if (selected instanceof IRuntimeClasspathEntry) {
72-
IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry)selected;
71+
if (selected instanceof IRuntimeClasspathEntry entry) {
7372
int type = entry.getType();
7473
switch (type) {
7574
case IRuntimeClasspathEntry.VARIABLE:

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/EditClasspathEntryAction.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ public void run() {
8989
protected boolean updateSelection(IStructuredSelection selection) {
9090
if (selection.size() == 1) {
9191
Object element = selection.getFirstElement();
92-
if (element instanceof IRuntimeClasspathEntry) {
93-
IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) element;
92+
if (element instanceof IRuntimeClasspathEntry entry) {
9493
IClasspathEditor editor = getEditor(entry);
9594
if (editor != null) {
9695
return editor.canEdit(fConfiguration, new IRuntimeClasspathEntry[]{((ClasspathEntry)entry).getDelegate()});
@@ -101,8 +100,7 @@ protected boolean updateSelection(IStructuredSelection selection) {
101100
}
102101

103102
protected IClasspathEditor getEditor(IRuntimeClasspathEntry entry) {
104-
if (entry instanceof IAdaptable) {
105-
IAdaptable adaptable = (IAdaptable) entry;
103+
if (entry instanceof IAdaptable adaptable) {
106104
return adaptable.getAdapter(IClasspathEditor.class);
107105
}
108106
return null;

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ExcludeExceptionLocationAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public void run(IAction action) {
5252
}
5353
for (int i = 0; i < breakpoints.length; i++) {
5454
IBreakpoint breakpoint = breakpoints[i];
55-
if (breakpoint instanceof IJavaExceptionBreakpoint) {
56-
IJavaExceptionBreakpoint exBreakpoint= (IJavaExceptionBreakpoint)breakpoint;
55+
if (breakpoint instanceof IJavaExceptionBreakpoint exBreakpoint) {
5756
String[] current= exBreakpoint.getExclusionFilters();
5857
String[] newFilters= new String[current.length+1];
5958
System.arraycopy(current, 0, newFilters, 0, current.length);

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/InstanceFiltersAction.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,10 @@ public void run(IAction action) {
128128
}
129129

130130
Object o = selection.getFirstElement();
131-
if (o instanceof IJavaVariable) {
132-
final IJavaVariable var = (IJavaVariable)o;
131+
if (o instanceof final IJavaVariable var) {
133132
try {
134133
IValue value = var.getValue();
135-
if (value instanceof IJavaObject) {
136-
final IJavaObject object = (IJavaObject)value;
134+
if (value instanceof final IJavaObject object) {
137135
final List<IJavaBreakpoint> breakpoints = getApplicableBreakpoints(var, object);
138136
final IDebugModelPresentation modelPresentation= DebugUITools.newDebugModelPresentation();
139137

@@ -238,12 +236,9 @@ protected List<IJavaBreakpoint> getApplicableBreakpoints(IJavaVariable variable,
238236

239237
IBreakpoint[] allBreakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints();
240238
for (int i = 0; i < allBreakpoints.length; i++) {
241-
if (allBreakpoints[i] instanceof IJavaBreakpoint) {
242-
IJavaBreakpoint jbp = (IJavaBreakpoint)allBreakpoints[i];
239+
if (allBreakpoints[i] instanceof IJavaBreakpoint jbp) {
243240
IJavaBreakpoint valid = null;
244-
if (jbp instanceof IJavaWatchpoint && variable instanceof IJavaFieldVariable) {
245-
IJavaWatchpoint wp = (IJavaWatchpoint)jbp;
246-
IJavaFieldVariable fv = (IJavaFieldVariable)variable;
241+
if (jbp instanceof IJavaWatchpoint wp && variable instanceof IJavaFieldVariable fv) {
247242
if (variable.getName().equals(wp.getFieldName()) && fv.getDeclaringType().getName().equals(wp.getTypeName())) {
248243
valid = wp;
249244
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaBreakpointPropertiesAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public void run(IAction action) {
5555
*/
5656
@Override
5757
public void selectionChanged(IAction action, ISelection selection) {
58-
if (selection instanceof IStructuredSelection) {
59-
IStructuredSelection ss= (IStructuredSelection)selection;
58+
if (selection instanceof IStructuredSelection ss) {
6059
if (ss.isEmpty() || ss.size() > 1) {
6160
return;
6261
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,11 @@ private EvaluationResult convert(EvaluationResult evaluationResult, IVariable va
221221
return evaluationResult;
222222
}
223223
var value = evaluationResult.getValue();
224-
if (value instanceof IJavaPrimitiveValue) {
225-
var primValue = (IJavaPrimitiveValue) value;
224+
if (value instanceof IJavaPrimitiveValue primValue) {
226225
if (variable instanceof IJavaVariable) {
227226
try {
228227
var type = ((IJavaVariable) variable).getJavaType();
229-
if (type instanceof IJavaClassType) {
230-
var classType = (IJavaClassType) type;
228+
if (type instanceof IJavaClassType classType) {
231229
var javaDebug = thread.getDebugTarget().getAdapter(IJavaDebugTarget.class);
232230
switch (classType.getName()) {
233231
case "java.lang.Long": //$NON-NLS-1$
@@ -283,8 +281,7 @@ private void updateEvaluation(EvaluationResult evaluationResult, IJavaValue newV
283281
* (copied from EvaluateAction)
284282
*/
285283
protected String getExceptionMessage(Throwable exception) {
286-
if (exception instanceof CoreException) {
287-
CoreException ce = (CoreException)exception;
284+
if (exception instanceof CoreException ce) {
288285
Throwable throwable= ce.getStatus().getException();
289286
if (throwable instanceof com.sun.jdi.InvocationException) {
290287
return getInvocationExceptionMessage((com.sun.jdi.InvocationException)throwable);

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public boolean saveVariable(IVariable variable, String expression, Shell shell)
6666
}
6767

6868
// set the value of chars directly if expression is a single character (not an expression to evaluate)
69-
if (expression.length() == 1 && variable instanceof IJavaVariable){
70-
IJavaVariable javaVariable = (IJavaVariable)variable;
69+
if (expression.length() == 1 && variable instanceof IJavaVariable javaVariable){
7170
try {
7271
if (javaVariable.getJavaType() != null && javaVariable.getJavaType().getSignature() == Signature.SIG_CHAR){
7372
javaVariable.setValue(expression);
@@ -87,8 +86,7 @@ public boolean saveVariable(IVariable variable, String expression, Shell shell)
8786
* @return {@code false} to prohibit editing a variable
8887
*/
8988
protected boolean isAllowedToModifyValue(IVariable variable) {
90-
if (variable instanceof IJavaModifiers) {
91-
IJavaModifiers modifiers = (IJavaModifiers) variable;
89+
if (variable instanceof IJavaModifiers modifiers) {
9290
boolean allowed = isAllowedToModifyFinalValue(modifiers);
9391
if (!allowed) {
9492
// prohibit editing a variable that is declared as final

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenDeclaringTypeAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public class OpenDeclaringTypeAction extends OpenStackFrameAction {
2929
*/
3030
@Override
3131
protected IJavaType getTypeToOpen(IDebugElement element) throws CoreException {
32-
if (element instanceof IJavaStackFrame) {
33-
IJavaStackFrame frame = (IJavaStackFrame) element;
32+
if (element instanceof IJavaStackFrame frame) {
3433
return frame.getReferenceType();
3534
}
3635
return null;

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ protected IDialogSettings getDialogBoundsSettings() {
523523
private static void openJavaElements(Object[] elements, int line) {
524524
for (int i = 0; i < elements.length; i++) {
525525
Object ob = elements[i];
526-
if (ob instanceof IJavaElement) {
527-
IJavaElement element = (IJavaElement) ob;
526+
if (ob instanceof IJavaElement element) {
528527
try {
529528
IEditorPart editorPart = JavaUI.openInEditor(element);
530529
gotoLine(editorPart, line, element);

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenReceivingTypeAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public class OpenReceivingTypeAction extends OpenStackFrameAction {
3030
*/
3131
@Override
3232
protected IJavaType getTypeToOpen(IDebugElement element) throws CoreException {
33-
if (element instanceof IJavaStackFrame) {
34-
IJavaStackFrame frame = (IJavaStackFrame) element;
33+
if (element instanceof IJavaStackFrame frame) {
3534
if (frame.isStatic()) {
3635
return frame.getReferenceType();
3736
}

0 commit comments

Comments
 (0)