Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public void initialize(IDebugAdapterContext context, Map<String, Object> props)
throw new IllegalArgumentException("argument is null");
}
options.putAll(props);
// During initialization, trigger a background job to load the source containers to improve the perf.
// During initialization, trigger a background job to load the source containers
// to improve the perf.
new Thread(() -> {
getSourceContainers();
}).start();
Expand Down Expand Up @@ -142,15 +143,16 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
return Stream.of(locations).map(location -> {
if (location.className() != null && location.methodName() != null) {
return location.className()
.concat("#").concat(location.methodName())
.concat("#").concat(location.methodSignature());
.concat("#").concat(location.methodName())
.concat("#").concat(location.methodSignature());
}
return location.className();
}).toArray(String[]::new);
}

@Override
public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceBreakpoint[] sourceBreakpoints) throws DebugException {
public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceBreakpoint[] sourceBreakpoints)
throws DebugException {
if (sourceUri == null) {
throw new IllegalArgumentException("sourceUri is null");
}
Expand All @@ -161,8 +163,8 @@ public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceB

CompilationUnit astUnit = asCompilationUnit(sourceUri);
JavaBreakpointLocation[] sourceLocations = Stream.of(sourceBreakpoints)
.map(sourceBreakpoint -> new JavaBreakpointLocation(sourceBreakpoint.line, sourceBreakpoint.column))
.toArray(JavaBreakpointLocation[]::new);
.map(sourceBreakpoint -> new JavaBreakpointLocation(sourceBreakpoint.line, sourceBreakpoint.column))
.toArray(JavaBreakpointLocation[]::new);
if (astUnit != null) {
Map<Integer, BreakpointLocation[]> resolvedLocations = new HashMap<>();
for (JavaBreakpointLocation sourceLocation : sourceLocations) {
Expand All @@ -171,7 +173,7 @@ public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceB
if (sourceColumn > -1) {
// if we have a column, try to find the lambda expression at that column
LambdaExpressionLocator lambdaExpressionLocator = new LambdaExpressionLocator(astUnit,
sourceLine, sourceColumn);
sourceLine, sourceColumn);
astUnit.accept(lambdaExpressionLocator);
if (lambdaExpressionLocator.isFound()) {
sourceLocation.setClassName(lambdaExpressionLocator.getFullyQualifiedTypeName());
Expand Down Expand Up @@ -232,7 +234,8 @@ public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceB

private BreakpointLocation[] getInlineBreakpointLocations(final CompilationUnit astUnit, int sourceLine) {
List<BreakpointLocation> locations = new ArrayList<>();
// The starting position of each line is the default breakpoint location for that line.
// The starting position of each line is the default breakpoint location for
// that line.
locations.add(new BreakpointLocation(sourceLine, 0));
astUnit.accept(new ASTVisitor() {
@Override
Expand Down Expand Up @@ -284,18 +287,18 @@ private CompilationUnit asCompilationUnit(String uri) {
parser.setProject(JavaCore.create(resource.getProject()));
} else {
parser.setEnvironment(new String[0], new String[0], null, true);
/**
* See the java doc for { @link ASTParser#setSource(char[]) },
* the user need specify the compiler options explicitly.
*/
Map<String, String> javaOptions = JavaCore.getOptions();
javaOptions.put(JavaCore.COMPILER_SOURCE, this.latestJavaVersion);
javaOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, this.latestJavaVersion);
javaOptions.put(JavaCore.COMPILER_COMPLIANCE, this.latestJavaVersion);
javaOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
parser.setCompilerOptions(javaOptions);
}
parser.setUnitName(Paths.get(filePath).getFileName().toString());
/**
* See the java doc for { @link ASTParser#setSource(char[]) },
* the user need specify the compiler options explicitly.
*/
Map<String, String> javaOptions = JavaCore.getOptions();
javaOptions.put(JavaCore.COMPILER_SOURCE, this.latestJavaVersion);
javaOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, this.latestJavaVersion);
javaOptions.put(JavaCore.COMPILER_COMPLIANCE, this.latestJavaVersion);
javaOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
parser.setCompilerOptions(javaOptions);
astUnit = (CompilationUnit) parser.createAST(null);
} else {
// For non-file uri (e.g. jdt://contents/rt.jar/java.io/PrintStream.class),
Expand Down Expand Up @@ -336,7 +339,8 @@ public String getJavaRuntimeVersion(String projectName) {

return resolveSystemLibraryVersion(project, vmInstall);
} catch (CoreException e) {
logger.log(Level.SEVERE, "Failed to get Java runtime version for project '" + projectName + "': " + e.getMessage(), e);
logger.log(Level.SEVERE,
"Failed to get Java runtime version for project '" + projectName + "': " + e.getMessage(), e);
}
}

Expand All @@ -345,6 +349,7 @@ public String getJavaRuntimeVersion(String projectName) {

/**
* Get the project associated source containers.
*
* @return the initialized source container list
*/
public synchronized ISourceContainer[] getSourceContainers() {
Expand Down Expand Up @@ -373,7 +378,8 @@ private String getContents(IClassFile cf) {
source = buffer.getContents();
}
} catch (JavaModelException e) {
logger.log(Level.SEVERE, String.format("Failed to parse the source contents of the class file: %s", e.toString()), e);
logger.log(Level.SEVERE,
String.format("Failed to parse the source contents of the class file: %s", e.toString()), e);
}
if (source == null) {
source = "";
Expand All @@ -388,7 +394,7 @@ private static String getFileURI(IClassFile classFile) {
try {
return new URI(JDT_SCHEME, "contents", PATH_SEPARATOR + jarName + PATH_SEPARATOR + packageName
+ PATH_SEPARATOR + classFile.getElementName(), classFile.getHandleIdentifier(), null)
.toASCIIString();
.toASCIIString();
} catch (URISyntaxException e) {
return null;
}
Expand Down Expand Up @@ -425,8 +431,7 @@ private static IClassFile resolveClassFile(String uriString) {

private static String readFile(String filePath) {
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferReader =
new BufferedReader(new InputStreamReader(new FileInputStream(filePath)))) {
try (BufferedReader bufferReader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath)))) {
final int BUFFER_SIZE = 4096;
char[] buffer = new char[BUFFER_SIZE];
while (true) {
Expand All @@ -442,7 +447,8 @@ private static String readFile(String filePath) {
return builder.toString();
}

private static String resolveSystemLibraryVersion(IJavaProject project, IVMInstall vmInstall) throws JavaModelException {
private static String resolveSystemLibraryVersion(IJavaProject project, IVMInstall vmInstall)
throws JavaModelException {
LibraryLocation[] libraries = JavaRuntime.getLibraryLocations(vmInstall);
if (libraries != null && libraries.length > 0) {
IPackageFragmentRoot root = project.findPackageFragmentRoot(libraries[0].getSystemLibraryPath());
Expand Down