Skip to content

Commit

Permalink
Supplying JDK version to disambiguate types to open
Browse files Browse the repository at this point in the history
#121

This commit filters specified JDK version on java stack traces to open
exact version

Fixes : #121
  • Loading branch information
SougandhS authored and jukzi committed Jan 27, 2025
1 parent 8384474 commit e8da403
Showing 1 changed file with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 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
Expand Down Expand Up @@ -42,6 +42,8 @@
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
import org.eclipse.jdt.internal.debug.ui.actions.OpenFromClipboardAction;
import org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
Expand Down Expand Up @@ -295,6 +297,7 @@ public IStatus processAmbiguousResults(List<Object> matches, String typeName, in
return openClipboard(matches, line, typeName);
}
}

/**
* Handles exceptions details
*
Expand Down Expand Up @@ -352,6 +355,7 @@ private boolean filterClasses(Object obj, String methodSignature, String methodN
* @return Returns a standard OK status with an "ok" message.
*/
private IStatus openClipboard(List<Object> results, int lineNumber, String type) {
results = filterBinaryTypes(results, generatedLink.get());
OpenFromClipboardAction.handleMatches(results, lineNumber, type, ConsoleMessages.JavaDebugStackTraceHyperlink_dialog_title);
return Status.OK_STATUS;
}
Expand Down Expand Up @@ -746,4 +750,46 @@ private static String removeModuleInfo(String typeName) {
}
return typeName;
}

/**
* Intermediate method to filter Binary Types based on given version
*
* @return List of Objects with filtered Binary types
* @param extracted
* Filtered or Processed Binary/Source Types
* @param link
* Stack trace from the console
*/
private List<Object> filterBinaryTypes(List<Object> extracted, String link) {
if (link != null) {
List<Object> filteredResults = new ArrayList<>();
int binaryInserted = 0;
try {
Pattern pattern = Pattern.compile("@(.*?)\\/"); //$NON-NLS-1$
Matcher match = pattern.matcher(link);
if (match.find()) {
String jdkVersion = match.group(1);
for (Object ob : extracted) {
if (ob instanceof IType type && type.isBinary()) {
IVMInstall installedJava = JavaRuntime.getVMInstall(type.getJavaProject());
String jdkAvailable = installedJava.getInstallLocation().getAbsolutePath();
if (jdkAvailable.contains(jdkVersion)) {
filteredResults.add(ob);
binaryInserted++;
}
} else {
filteredResults.add(ob);
}
}
}
} catch (CoreException e) {
return extracted;
}
if (binaryInserted == 0) {
return extracted;
}
return filteredResults;
}
return extracted;
}
}

0 comments on commit e8da403

Please sign in to comment.