Skip to content

Commit 15f5d4e

Browse files
SougandhSmickaelistria
authored andcommitted
Automatic cleanup - instanceof pattern matching in Debug.core
This commit implements automatic cleanup using instanceof pattern matching in the debug.core package of the platform debug module.
1 parent 90faa8e commit 15f5d4e

11 files changed

+18
-34
lines changed

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,7 @@ public int hashCode() {
12721272

12731273
@Override
12741274
public boolean equals(Object obj) {
1275-
if (obj instanceof StatusHandlerKey) {
1276-
StatusHandlerKey s = (StatusHandlerKey)obj;
1275+
if (obj instanceof StatusHandlerKey s) {
12771276
return fCode == s.fCode && fPluginId.equals(s.fPluginId);
12781277
}
12791278
return false;

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/Launch.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,9 @@ public void disconnect() throws DebugException {
527527
readLock.lock();
528528
try {
529529
for (IProcess process : getProcesses0()) {
530-
if (process instanceof IDisconnect) {
531-
IDisconnect dis = (IDisconnect) process;
532-
if (dis.canDisconnect()) {
533-
dis.disconnect();
530+
if (process instanceof IDisconnect disc) {
531+
if (disc.canDisconnect()) {
532+
disc.disconnect();
534533
}
535534
}
536535
}

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/commands/AbstractDebugCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ public boolean contains(ISchedulingRule rule) {
187187

188188
@Override
189189
public boolean isConflicting(ISchedulingRule rule) {
190-
if (rule instanceof SerialPerObjectRule) {
191-
SerialPerObjectRule vup = (SerialPerObjectRule) rule;
190+
if (rule instanceof SerialPerObjectRule vup) {
192191
return fObject == vup.fObject;
193192
}
194193
return false;

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/AbstractSourceLookupDirector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,7 @@ protected List<Object> doSourceLookup(Object element) {
474474
List<Object> sources = query.getSourceElements();
475475
Throwable exception = query.getException();
476476
if (exception != null) {
477-
if (exception instanceof CoreException) {
478-
CoreException ce = (CoreException) exception;
477+
if (exception instanceof CoreException ce) {
479478
if (ce.getStatus().getSeverity() == IStatus.ERROR) {
480479
DebugPlugin.log(ce);
481480
}

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/AbstractSourceContainer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,9 @@ protected ISourceLookupDirector getDirector() {
109109
protected boolean isFindDuplicates() {
110110
ISourceLookupDirector director = getDirector();
111111
if (director != null) {
112-
if (director instanceof AbstractSourceLookupDirector) {
113-
AbstractSourceLookupDirector asld = (AbstractSourceLookupDirector) director;
112+
if (director instanceof AbstractSourceLookupDirector asld) {
114113
ISourceLookupParticipant participant = asld.getCurrentParticipant();
115-
if (participant instanceof AbstractSourceLookupParticipant ) {
116-
AbstractSourceLookupParticipant aslp = (AbstractSourceLookupParticipant) participant;
114+
if (participant instanceof AbstractSourceLookupParticipant aslp ) {
117115
return aslp.isFindDuplicates();
118116
}
119117
}

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ContainerSourceContainer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ public String getName() {
148148

149149
@Override
150150
public boolean equals(Object obj) {
151-
if (obj != null && obj instanceof ContainerSourceContainer) {
152-
ContainerSourceContainer loc = (ContainerSourceContainer) obj;
151+
if (obj != null && obj instanceof ContainerSourceContainer loc) {
153152
return loc.getContainer().equals(getContainer());
154153
}
155154
return false;

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/DirectorySourceContainer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public boolean isComposite() {
132132

133133
@Override
134134
public boolean equals(Object obj) {
135-
if (obj instanceof DirectorySourceContainer) {
136-
DirectorySourceContainer container = (DirectorySourceContainer) obj;
135+
if (obj instanceof DirectorySourceContainer container) {
137136
return container.getDirectory().equals(getDirectory());
138137
}
139138
return false;

debug/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ public boolean visit(IResourceDelta delta) {
356356
return false;
357357
}
358358
IResource resource = delta.getResource();
359-
if (resource instanceof IFile) {
360-
IFile file = (IFile)resource;
359+
if (resource instanceof IFile file) {
361360
if (ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION.equals(file.getFileExtension()) || ILaunchConfiguration.LAUNCH_CONFIGURATION_PROTOTYPE_FILE_EXTENSION.equals(file.getFileExtension())) {
362361
ILaunchConfiguration handle = new LaunchConfiguration(file);
363362
switch (delta.getKind()) {
@@ -2199,8 +2198,7 @@ public void shutdown() {
21992198
for (ILaunch launch : getLaunches()) {
22002199
if(launch != null) {
22012200
try {
2202-
if (launch instanceof IDisconnect) {
2203-
IDisconnect disconnect = (IDisconnect)launch;
2201+
if (launch instanceof IDisconnect disconnect) {
22042202
if (disconnect.canDisconnect()) {
22052203
disconnect.disconnect();
22062204
}

debug/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LogicalStructureType.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ protected ILogicalStructureTypeDelegate getDelegate() {
135135
@Override
136136
public String getDescription(IValue value) {
137137
ILogicalStructureTypeDelegate delegate = getDelegate();
138-
if (delegate instanceof ILogicalStructureTypeDelegate2) {
139-
ILogicalStructureTypeDelegate2 d2 = (ILogicalStructureTypeDelegate2) delegate;
138+
if (delegate instanceof ILogicalStructureTypeDelegate2 d2) {
140139
return d2.getDescription(value);
141140
}
142141
if (!fVerifiedDescription) {

debug/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/XMLMemento.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ public XMLMemento getChild(String type) {
195195
// Find the first node which is a child of this node.
196196
for (int nX = 0; nX < size; nX++) {
197197
Node node = nodes.item(nX);
198-
if (node instanceof Element) {
199-
Element element1 = (Element) node;
198+
if (node instanceof Element element1) {
200199
if (element1.getNodeName().equals(type)) {
201200
return new XMLMemento(factory, element1);
202201
}
@@ -223,8 +222,7 @@ public XMLMemento[] getChildren(String type) {
223222
ArrayList<Element> list = new ArrayList<>(size);
224223
for (int nX = 0; nX < size; nX++) {
225224
Node node = nodes.item(nX);
226-
if (node instanceof Element) {
227-
Element element1 = (Element) node;
225+
if (node instanceof Element element1) {
228226
if (element1.getNodeName().equals(type)) {
229227
list.add(element1);
230228
}

debug/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/commands/StepFiltersCommand.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,11 @@ protected Object getTarget(Object element) {
5252
}
5353

5454
private IDebugTarget[] getDebugTargets(Object element) {
55-
if (element instanceof IDebugElement) {
56-
IDebugElement debugElement = (IDebugElement) element;
55+
if (element instanceof IDebugElement debugElement) {
5756
return new IDebugTarget[] { debugElement.getDebugTarget() };
58-
} else if (element instanceof ILaunch) {
59-
ILaunch launch = (ILaunch) element;
57+
} else if (element instanceof ILaunch launch) {
6058
return launch.getDebugTargets();
61-
} else if (element instanceof IProcess) {
62-
IProcess process = (IProcess) element;
59+
} else if (element instanceof IProcess process) {
6360
return process.getLaunch().getDebugTargets();
6461
} else {
6562
return new IDebugTarget[0];

0 commit comments

Comments
 (0)