@@ -100,7 +100,8 @@ public void initialize(IDebugAdapterContext context, Map<String, Object> props)
100
100
throw new IllegalArgumentException ("argument is null" );
101
101
}
102
102
options .putAll (props );
103
- // During initialization, trigger a background job to load the source containers to improve the perf.
103
+ // During initialization, trigger a background job to load the source containers
104
+ // to improve the perf.
104
105
new Thread (() -> {
105
106
getSourceContainers ();
106
107
}).start ();
@@ -142,15 +143,16 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
142
143
return Stream .of (locations ).map (location -> {
143
144
if (location .className () != null && location .methodName () != null ) {
144
145
return location .className ()
145
- .concat ("#" ).concat (location .methodName ())
146
- .concat ("#" ).concat (location .methodSignature ());
146
+ .concat ("#" ).concat (location .methodName ())
147
+ .concat ("#" ).concat (location .methodSignature ());
147
148
}
148
149
return location .className ();
149
150
}).toArray (String []::new );
150
151
}
151
152
152
153
@ Override
153
- public JavaBreakpointLocation [] getBreakpointLocations (String sourceUri , SourceBreakpoint [] sourceBreakpoints ) throws DebugException {
154
+ public JavaBreakpointLocation [] getBreakpointLocations (String sourceUri , SourceBreakpoint [] sourceBreakpoints )
155
+ throws DebugException {
154
156
if (sourceUri == null ) {
155
157
throw new IllegalArgumentException ("sourceUri is null" );
156
158
}
@@ -161,8 +163,8 @@ public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceB
161
163
162
164
CompilationUnit astUnit = asCompilationUnit (sourceUri );
163
165
JavaBreakpointLocation [] sourceLocations = Stream .of (sourceBreakpoints )
164
- .map (sourceBreakpoint -> new JavaBreakpointLocation (sourceBreakpoint .line , sourceBreakpoint .column ))
165
- .toArray (JavaBreakpointLocation []::new );
166
+ .map (sourceBreakpoint -> new JavaBreakpointLocation (sourceBreakpoint .line , sourceBreakpoint .column ))
167
+ .toArray (JavaBreakpointLocation []::new );
166
168
if (astUnit != null ) {
167
169
Map <Integer , BreakpointLocation []> resolvedLocations = new HashMap <>();
168
170
for (JavaBreakpointLocation sourceLocation : sourceLocations ) {
@@ -171,7 +173,7 @@ public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceB
171
173
if (sourceColumn > -1 ) {
172
174
// if we have a column, try to find the lambda expression at that column
173
175
LambdaExpressionLocator lambdaExpressionLocator = new LambdaExpressionLocator (astUnit ,
174
- sourceLine , sourceColumn );
176
+ sourceLine , sourceColumn );
175
177
astUnit .accept (lambdaExpressionLocator );
176
178
if (lambdaExpressionLocator .isFound ()) {
177
179
sourceLocation .setClassName (lambdaExpressionLocator .getFullyQualifiedTypeName ());
@@ -232,7 +234,8 @@ public JavaBreakpointLocation[] getBreakpointLocations(String sourceUri, SourceB
232
234
233
235
private BreakpointLocation [] getInlineBreakpointLocations (final CompilationUnit astUnit , int sourceLine ) {
234
236
List <BreakpointLocation > locations = new ArrayList <>();
235
- // The starting position of each line is the default breakpoint location for that line.
237
+ // The starting position of each line is the default breakpoint location for
238
+ // that line.
236
239
locations .add (new BreakpointLocation (sourceLine , 0 ));
237
240
astUnit .accept (new ASTVisitor () {
238
241
@ Override
@@ -284,18 +287,18 @@ private CompilationUnit asCompilationUnit(String uri) {
284
287
parser .setProject (JavaCore .create (resource .getProject ()));
285
288
} else {
286
289
parser .setEnvironment (new String [0 ], new String [0 ], null , true );
290
+ /**
291
+ * See the java doc for { @link ASTParser#setSource(char[]) },
292
+ * the user need specify the compiler options explicitly.
293
+ */
294
+ Map <String , String > javaOptions = JavaCore .getOptions ();
295
+ javaOptions .put (JavaCore .COMPILER_SOURCE , this .latestJavaVersion );
296
+ javaOptions .put (JavaCore .COMPILER_CODEGEN_TARGET_PLATFORM , this .latestJavaVersion );
297
+ javaOptions .put (JavaCore .COMPILER_COMPLIANCE , this .latestJavaVersion );
298
+ javaOptions .put (JavaCore .COMPILER_PB_ENABLE_PREVIEW_FEATURES , JavaCore .ENABLED );
299
+ parser .setCompilerOptions (javaOptions );
287
300
}
288
301
parser .setUnitName (Paths .get (filePath ).getFileName ().toString ());
289
- /**
290
- * See the java doc for { @link ASTParser#setSource(char[]) },
291
- * the user need specify the compiler options explicitly.
292
- */
293
- Map <String , String > javaOptions = JavaCore .getOptions ();
294
- javaOptions .put (JavaCore .COMPILER_SOURCE , this .latestJavaVersion );
295
- javaOptions .put (JavaCore .COMPILER_CODEGEN_TARGET_PLATFORM , this .latestJavaVersion );
296
- javaOptions .put (JavaCore .COMPILER_COMPLIANCE , this .latestJavaVersion );
297
- javaOptions .put (JavaCore .COMPILER_PB_ENABLE_PREVIEW_FEATURES , JavaCore .ENABLED );
298
- parser .setCompilerOptions (javaOptions );
299
302
astUnit = (CompilationUnit ) parser .createAST (null );
300
303
} else {
301
304
// For non-file uri (e.g. jdt://contents/rt.jar/java.io/PrintStream.class),
@@ -336,7 +339,8 @@ public String getJavaRuntimeVersion(String projectName) {
336
339
337
340
return resolveSystemLibraryVersion (project , vmInstall );
338
341
} catch (CoreException e ) {
339
- logger .log (Level .SEVERE , "Failed to get Java runtime version for project '" + projectName + "': " + e .getMessage (), e );
342
+ logger .log (Level .SEVERE ,
343
+ "Failed to get Java runtime version for project '" + projectName + "': " + e .getMessage (), e );
340
344
}
341
345
}
342
346
@@ -345,6 +349,7 @@ public String getJavaRuntimeVersion(String projectName) {
345
349
346
350
/**
347
351
* Get the project associated source containers.
352
+ *
348
353
* @return the initialized source container list
349
354
*/
350
355
public synchronized ISourceContainer [] getSourceContainers () {
@@ -373,7 +378,8 @@ private String getContents(IClassFile cf) {
373
378
source = buffer .getContents ();
374
379
}
375
380
} catch (JavaModelException e ) {
376
- logger .log (Level .SEVERE , String .format ("Failed to parse the source contents of the class file: %s" , e .toString ()), e );
381
+ logger .log (Level .SEVERE ,
382
+ String .format ("Failed to parse the source contents of the class file: %s" , e .toString ()), e );
377
383
}
378
384
if (source == null ) {
379
385
source = "" ;
@@ -388,7 +394,7 @@ private static String getFileURI(IClassFile classFile) {
388
394
try {
389
395
return new URI (JDT_SCHEME , "contents" , PATH_SEPARATOR + jarName + PATH_SEPARATOR + packageName
390
396
+ PATH_SEPARATOR + classFile .getElementName (), classFile .getHandleIdentifier (), null )
391
- .toASCIIString ();
397
+ .toASCIIString ();
392
398
} catch (URISyntaxException e ) {
393
399
return null ;
394
400
}
@@ -425,8 +431,7 @@ private static IClassFile resolveClassFile(String uriString) {
425
431
426
432
private static String readFile (String filePath ) {
427
433
StringBuilder builder = new StringBuilder ();
428
- try (BufferedReader bufferReader =
429
- new BufferedReader (new InputStreamReader (new FileInputStream (filePath )))) {
434
+ try (BufferedReader bufferReader = new BufferedReader (new InputStreamReader (new FileInputStream (filePath )))) {
430
435
final int BUFFER_SIZE = 4096 ;
431
436
char [] buffer = new char [BUFFER_SIZE ];
432
437
while (true ) {
@@ -442,7 +447,8 @@ private static String readFile(String filePath) {
442
447
return builder .toString ();
443
448
}
444
449
445
- private static String resolveSystemLibraryVersion (IJavaProject project , IVMInstall vmInstall ) throws JavaModelException {
450
+ private static String resolveSystemLibraryVersion (IJavaProject project , IVMInstall vmInstall )
451
+ throws JavaModelException {
446
452
LibraryLocation [] libraries = JavaRuntime .getLibraryLocations (vmInstall );
447
453
if (libraries != null && libraries .length > 0 ) {
448
454
IPackageFragmentRoot root = project .findPackageFragmentRoot (libraries [0 ].getSystemLibraryPath ());
0 commit comments