Skip to content

Commit

Permalink
Manual Code Cleanup: Java 16 instanceof pattern matching
Browse files Browse the repository at this point in the history
Performed manual code cleanup in pattern matching using
instanceof operator according to Java 16 guidelines,
making the code more concise for classes in jdt.launching package.
  • Loading branch information
SougandhS committed Nov 7, 2024
1 parent c73de59 commit a4f035a
Show file tree
Hide file tree
Showing 24 changed files with 983 additions and 970 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ protected boolean getLaunchConfigurationUseClasspathOnlyJarAttribute() throws Co
}

public static String getJavaVersion(IVMInstall vmInstall) {
if (vmInstall instanceof IVMInstall2) {
IVMInstall2 install = (IVMInstall2) vmInstall;
if (vmInstall instanceof IVMInstall2 install) {
return install.getJavaVersion();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
*/
public class CommandLineShortener implements IProcessTempFileCreator {
public static String getJavaVersion(IVMInstall vmInstall) {
if (vmInstall instanceof IVMInstall2) {
IVMInstall2 install = (IVMInstall2) vmInstall;
if (vmInstall instanceof IVMInstall2 install) {
return install.getJavaVersion();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(boolean excludeTestCo
IRuntimeClasspathEntry[] runtimeEntries = new IRuntimeClasspathEntry[classpathEntries.size()];
for (int i = 0; i < runtimeEntries.length; i++) {
Object e = classpathEntries.get(i);
if (e instanceof IClasspathEntry) {
IClasspathEntry cpe = (IClasspathEntry)e;
if (e instanceof IClasspathEntry cpe) {
runtimeEntries[i] = new RuntimeClasspathEntry(cpe);
} else {
runtimeEntries[i] = (IRuntimeClasspathEntry)e;
Expand Down Expand Up @@ -290,8 +289,7 @@ public static void expandProjectInternal(IClasspathEntry projectEntry, List<Obje
ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(r.getPath().segment(0));
for (int i = 0; i < expandedPath.size(); i++) {
Object o = expandedPath.get(i);
if (o instanceof IRuntimeClasspathEntry) {
IRuntimeClasspathEntry re = (IRuntimeClasspathEntry)o;
if (o instanceof IRuntimeClasspathEntry re) {
if (re.getType() == IRuntimeClasspathEntry.CONTAINER) {
if (container instanceof IRuntimeContainerComparator) {
duplicate = ((IRuntimeContainerComparator)container).isDuplicate(re.getPath());
Expand Down Expand Up @@ -405,8 +403,7 @@ public String getName() {
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof DefaultProjectClasspathEntry) {
DefaultProjectClasspathEntry entry = (DefaultProjectClasspathEntry) obj;
if (obj instanceof DefaultProjectClasspathEntry entry) {
return entry.getJavaProject().equals(getJavaProject()) &&
entry.isExportedEntriesOnly() == isExportedEntriesOnly();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public RuleKey(IVMInstall install, String environmentId) {
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof RuleKey) {
RuleKey key = (RuleKey) obj;
if (obj instanceof RuleKey key) {
return fEnvironmentId.equals(key.fEnvironmentId) && fInstall.equals(key.fInstall);
}
return false;
Expand Down Expand Up @@ -236,8 +235,7 @@ public void vmRemoved(IVMInstall removedVm) {
* @param obj an object which should be castable to IVMInstall
*/
private void removeRuleEntry(Object obj) {
if(obj instanceof IVMInstall) {
IVMInstall install = (IVMInstall) obj;
if (obj instanceof IVMInstall install) {
fgClasspathEntriesWithRules.keySet().removeIf(key -> key.fInstall.equals(install));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ public void handleDebugEvents(DebugEvent[] events) {
case DebugEvent.TERMINATE :
if (eventSource != null) {
ILaunch launch = null;
if (eventSource instanceof IProcess) {
IProcess process = (IProcess) eventSource;
if (eventSource instanceof IProcess process) {
launch = process.getLaunch();
} else if (eventSource instanceof IDebugTarget) {
IDebugTarget debugTarget = (IDebugTarget) eventSource;
} else if (eventSource instanceof IDebugTarget debugTarget) {
launch = debugTarget.getLaunch();
}
if (launch != null) {
Expand Down
Loading

0 comments on commit a4f035a

Please sign in to comment.