@@ -301,6 +301,7 @@ private static Pair<String, Callable> processCallableDeclaration(CallableDeclara
301
301
callableNode .setCalledMethodDeclaringTypes (getCalledMethodDeclaringTypes (body ));
302
302
callableNode .setAccessedFields (getAccessedFields (body , classFields , typeName ));
303
303
callableNode .setCallSites (getCallSites (body ));
304
+ callableNode .setVariableDeclarations (getVariableDeclarations (body ));
304
305
305
306
String callableSignature = (callableDecl instanceof MethodDeclaration ) ? callableDecl .getSignature ().asString () : callableDecl .getSignature ().asString ().replace (callableDecl .getSignature ().getName (), "<init>" );
306
307
return Pair .of (callableSignature , callableNode );
@@ -359,7 +360,41 @@ private static List<String> getReferencedTypes(Optional<BlockStmt> blockStmt) {
359
360
}
360
361
361
362
/**
362
- * Computes and returns the list if fields accessed in the given callable body. The returned values contain
363
+ * Returns information about variable declarations in the given callable. The information includes
364
+ * var name, var type, var initializer, and position.
365
+ *
366
+ * @param blockStmt Callable to compute var declaration information for
367
+ * @return list of variable declarations
368
+ */
369
+ private static List <VariableDeclaration > getVariableDeclarations (Optional <BlockStmt > blockStmt ) {
370
+ List <VariableDeclaration > varDeclarations = new ArrayList <>();
371
+ if (blockStmt .isEmpty ()) {
372
+ return varDeclarations ;
373
+ }
374
+ for (VariableDeclarator declarator : blockStmt .get ().findAll (VariableDeclarator .class )) {
375
+ VariableDeclaration varDeclaration = new VariableDeclaration ();
376
+ varDeclaration .setName (declarator .getNameAsString ());
377
+ varDeclaration .setType (resolveType (declarator .getType ()));
378
+ varDeclaration .setInitializer (declarator .getInitializer ().isPresent () ?
379
+ declarator .getInitializer ().get ().toString () : "" );
380
+ if (declarator .getRange ().isPresent ()) {
381
+ varDeclaration .setStartLine (declarator .getRange ().get ().begin .line );
382
+ varDeclaration .setStartColumn (declarator .getRange ().get ().begin .column );
383
+ varDeclaration .setEndLine (declarator .getRange ().get ().end .line );
384
+ varDeclaration .setEndColumn (declarator .getRange ().get ().end .column );
385
+ } else {
386
+ varDeclaration .setStartLine (-1 );
387
+ varDeclaration .setStartColumn (-1 );
388
+ varDeclaration .setEndLine (-1 );
389
+ varDeclaration .setEndColumn (-1 );
390
+ }
391
+ varDeclarations .add (varDeclaration );
392
+ }
393
+ return varDeclarations ;
394
+ }
395
+
396
+ /**
397
+ * Computes and returns the list of fields accessed in the given callable body. The returned values contain
363
398
* field names qualified by names of the declaring types.
364
399
*
365
400
* @param callableBody Callable body to compute accessed fields for
0 commit comments