Skip to content

Commit 7af6eb3

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of debug/org.eclipse.debug.examples.ui
1 parent 56380df commit 7af6eb3

File tree

15 files changed

+31
-57
lines changed

15 files changed

+31
-57
lines changed

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/ControlCellModifier.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public boolean canModify(Object element, String property) {
3838
@Override
3939
public Object getValue(Object element, String property) {
4040
if (SequencerColumnPresentation.COL_VALUE.equals(property)) {
41-
if (element instanceof SequencerControl) {
42-
SequencerControl control = (SequencerControl) element;
41+
if (element instanceof SequencerControl control) {
4342
return control.getValue();
4443
}
4544
}
@@ -51,9 +50,8 @@ public void modify(Object element, String property, Object value) {
5150
Object oldValue = getValue(element, property);
5251
if (!value.equals(oldValue)) {
5352
if (SequencerColumnPresentation.COL_VALUE.equals(property)) {
54-
if (element instanceof SequencerControl) {
53+
if (element instanceof SequencerControl control) {
5554
if (value instanceof String) {
56-
SequencerControl control = (SequencerControl) element;
5755
control.setValue((String) value);
5856
}
5957
}

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiEventLabelProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ protected String getLabel(TreePath elementPath, IPresentationContext presentatio
4545
}
4646
return buffer.toString();
4747
} else if (TrackColumnPresentation.COL_COMMAND.equals(columnId)) {
48-
if (message instanceof ShortMessage) {
49-
ShortMessage sm = (ShortMessage) message;
48+
if (message instanceof ShortMessage sm) {
5049
StringBuilder buf = new StringBuilder();
5150
appendByte(buf, (byte)sm.getCommand());
5251
return buf.toString();

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/launcher/MidiLaunchShortcut.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ public class MidiLaunchShortcut implements ILaunchShortcut {
4444

4545
@Override
4646
public void launch(ISelection selection, String mode) {
47-
if (selection instanceof IStructuredSelection) {
48-
IStructuredSelection ss = (IStructuredSelection) selection;
47+
if (selection instanceof IStructuredSelection ss) {
4948
if (ss.size() == 1) {
5049
Object element = ss.getFirstElement();
51-
if (element instanceof IFile) {
52-
IFile file = (IFile) element;
50+
if (element instanceof IFile file) {
5351
ILaunchConfiguration configuration = getConfiguration(file);
5452
if (configuration != null) {
5553
DebugUITools.launch(configuration, mode);

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/launcher/MidiTabGroup.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
1717
import org.eclipse.debug.ui.CommonTab;
1818
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
19-
import org.eclipse.debug.ui.ILaunchConfigurationTab;
2019

2120
/**
2221
* Tab group for a MIDI file.
@@ -26,9 +25,6 @@
2625
public class MidiTabGroup extends AbstractLaunchConfigurationTabGroup {
2726
@Override
2827
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
29-
setTabs(new ILaunchConfigurationTab[] {
30-
new MidiMainTab(),
31-
new CommonTab()
32-
});
28+
setTabs(new MidiMainTab(), new CommonTab());
3329
}
3430
}

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/AddPDAMemoryBlockAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public void run(IAction action) {
5959
* @return debug target from the selection or <code>null</code>
6060
*/
6161
private PDADebugTarget getTarget(ISelection selection) {
62-
if (selection instanceof IStructuredSelection) {
63-
IStructuredSelection ss = (IStructuredSelection) selection;
62+
if (selection instanceof IStructuredSelection ss) {
6463
if (ss.size() == 1) {
6564
Object element = ss.getFirstElement();
6665
if (element instanceof PDADebugTarget) {

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDABreakpointAdapter.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selectio
7676
* given part, or <code>null</code> if none
7777
*/
7878
private ITextEditor getEditor(IWorkbenchPart part) {
79-
if (part instanceof ITextEditor) {
80-
ITextEditor editorPart = (ITextEditor) part;
79+
if (part instanceof ITextEditor editorPart) {
8180
IResource resource = editorPart.getEditorInput().getAdapter(IResource.class);
8281
if (resource != null) {
8382
String extension = resource.getFileExtension();
@@ -101,8 +100,7 @@ public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection select
101100
@Override
102101
public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
103102
String[] variableAndFunctionName = getVariableAndFunctionName(part, selection);
104-
if (variableAndFunctionName != null && part instanceof ITextEditor && selection instanceof ITextSelection) {
105-
ITextEditor editorPart = (ITextEditor)part;
103+
if (variableAndFunctionName != null && part instanceof ITextEditor editorPart && selection instanceof ITextSelection) {
106104
int lineNumber = ((ITextSelection)selection).getStartLine();
107105
IResource resource = editorPart.getEditorInput().getAdapter(IResource.class);
108106
String var = variableAndFunctionName[0];
@@ -123,8 +121,7 @@ protected void toggleWatchpoint(IResource resource, int lineNumber, String fcn,
123121
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(DebugCorePlugin.ID_PDA_DEBUG_MODEL);
124122
for (int i = 0; i < breakpoints.length; i++) {
125123
IBreakpoint breakpoint = breakpoints[i];
126-
if (breakpoint instanceof PDAWatchpoint && resource.equals(breakpoint.getMarker().getResource())) {
127-
PDAWatchpoint watchpoint = (PDAWatchpoint)breakpoint;
124+
if (breakpoint instanceof PDAWatchpoint watchpoint && resource.equals(breakpoint.getMarker().getResource())) {
128125
String otherVar = watchpoint.getVariableName();
129126
String otherFcn = watchpoint.getFunctionName();
130127
if (otherVar.equals(var) && otherFcn.equals(fcn)) {
@@ -148,8 +145,7 @@ protected void toggleWatchpoint(IResource resource, int lineNumber, String fcn,
148145
*/
149146
protected String[] getVariableAndFunctionName(IWorkbenchPart part, ISelection selection) {
150147
ITextEditor editor = getEditor(part);
151-
if (editor != null && selection instanceof ITextSelection) {
152-
ITextSelection textSelection = (ITextSelection) selection;
148+
if (editor != null && selection instanceof ITextSelection textSelection) {
153149
IDocumentProvider documentProvider = editor.getDocumentProvider();
154150
try {
155151
documentProvider.connect(this);

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAToggleWatchpointsTarget.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public class PDAToggleWatchpointsTarget extends PDABreakpointAdapter {
5454
public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
5555
if (super.canToggleWatchpoints(part, selection)) {
5656
return true;
57-
} else if (selection instanceof IStructuredSelection) {
58-
IStructuredSelection ss = (IStructuredSelection)selection;
57+
} else if (selection instanceof IStructuredSelection ss) {
5958
return ss.getFirstElement() instanceof PDAVariable;
6059
}
6160
return false;
@@ -65,10 +64,9 @@ public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
6564
public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
6665
String[] variableAndFunctionName = getVariableAndFunctionName(part, selection);
6766

68-
if (variableAndFunctionName != null && part instanceof ITextEditor && selection instanceof ITextSelection) {
67+
if (variableAndFunctionName != null && part instanceof ITextEditor editorPart && selection instanceof ITextSelection) {
6968
// Selection inside text editor. Create a watchpoint based on
7069
// current source line.
71-
ITextEditor editorPart = (ITextEditor)part;
7270
int lineNumber = ((ITextSelection)selection).getStartLine();
7371
IResource resource = editorPart.getEditorInput().getAdapter(IResource.class);
7472
String var = variableAndFunctionName[0];

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAScanner.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.eclipse.debug.examples.ui.pda.DebugUIPlugin;
1818
import org.eclipse.jface.text.TextAttribute;
1919
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
20-
import org.eclipse.jface.text.rules.IRule;
2120
import org.eclipse.jface.text.rules.IWordDetector;
2221
import org.eclipse.jface.text.rules.Token;
2322
import org.eclipse.jface.text.rules.WordRule;
@@ -82,6 +81,6 @@ public PDAScanner() {
8281
// labels
8382
token = new Token(new TextAttribute(DebugUIPlugin.getDefault().getColor(DebugUIPlugin.LABEL)));
8483
WordRule labels = new WordRule(new PDALabelDetector(), token);
85-
setRules(new IRule[]{keywords, labels});
84+
setRules(keywords, labels);
8685
}
8786
}

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PopFrameActionDelegate.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ public void run(IAction action) {
4949

5050
@Override
5151
public void selectionChanged(IAction action, ISelection selection) {
52-
if (selection instanceof IStructuredSelection) {
53-
IStructuredSelection ss = (IStructuredSelection) selection;
52+
if (selection instanceof IStructuredSelection ss) {
5453
Object element = ss.getFirstElement();
55-
if (element instanceof PDAStackFrame) {
56-
PDAStackFrame frame = (PDAStackFrame) element;
54+
if (element instanceof PDAStackFrame frame) {
5755
//#ifdef ex5
5856
//# // TODO: Exercise 5 - enable the action if the frame's thread supports it
5957
//#else

debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/TextHover.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
4949
IAdaptable debugContext = DebugUITools.getDebugContext();
5050
if (debugContext instanceof PDAStackFrame) {
5151
frame = (PDAStackFrame) debugContext;
52-
} else if (debugContext instanceof PDAThread) {
53-
PDAThread thread = (PDAThread) debugContext;
52+
} else if (debugContext instanceof PDAThread thread) {
5453
try {
5554
frame = (PDAStackFrame) thread.getTopStackFrame();
5655
} catch (DebugException e) {
5756
return null;
5857
}
59-
} else if (debugContext instanceof PDADebugTarget) {
60-
PDADebugTarget target = (PDADebugTarget) debugContext;
58+
} else if (debugContext instanceof PDADebugTarget target) {
6159
try {
6260
IThread[] threads = target.getThreads();
6361
if (threads.length > 0) {

0 commit comments

Comments
 (0)