@@ -300,6 +300,7 @@ private static Pair<String, Callable> processCallableDeclaration(CallableDeclara
300
300
301
301
callableNode .setCalledMethodDeclaringTypes (getCalledMethodDeclaringTypes (body ));
302
302
callableNode .setAccessedFields (getAccessedFields (body , classFields , typeName ));
303
+ callableNode .setCallSites (getCallSites (body ));
303
304
304
305
String callableSignature = (callableDecl instanceof MethodDeclaration ) ? callableDecl .getSignature ().asString () : callableDecl .getSignature ().asString ().replace (callableDecl .getSignature ().getName (), "<init>" );
305
306
return Pair .of (callableSignature , callableNode );
@@ -425,6 +426,53 @@ private static List<String> getCalledMethodDeclaringTypes(Optional<BlockStmt> ca
425
426
return new ArrayList <>(calledMethodDeclaringTypes );
426
427
}
427
428
429
+ /**
430
+ * Returns information about call sites in the given callable. The information includes:
431
+ * the method name, the declaring type name, and types of arguments used in method call.
432
+ *
433
+ * @param callableBody callable to compute call-site information for
434
+ * @return list of call sites
435
+ */
436
+ private static List <CallSite > getCallSites (Optional <BlockStmt > callableBody ) {
437
+ List <CallSite > callSites = new ArrayList <>();
438
+ if (callableBody .isEmpty ()) {
439
+ return callSites ;
440
+ }
441
+ for (MethodCallExpr methodCallExpr : callableBody .get ().findAll (MethodCallExpr .class )) {
442
+ // resolve declaring type for called method
443
+ String declaringType = "" ;
444
+ if (methodCallExpr .getScope ().isPresent ()) {
445
+ declaringType = resolveExpression (methodCallExpr .getScope ().get ());
446
+ if (declaringType .contains (" | " )) {
447
+ declaringType = declaringType .split (" \\ | " )[0 ];
448
+ }
449
+ }
450
+
451
+ // resolve arguments of the method call to types
452
+ List <String > arguments = methodCallExpr .getArguments ().stream ()
453
+ .map (arg -> resolveExpression (arg )).collect (Collectors .toList ());
454
+
455
+ // add a new call site object
456
+ CallSite callSite = new CallSite ();
457
+ callSite .setMethodName (methodCallExpr .getNameAsString ());
458
+ callSite .setDeclaringType (declaringType );
459
+ callSite .setArgumentTypes (arguments );
460
+ if (methodCallExpr .getRange ().isPresent ()) {
461
+ callSite .setStartLine (methodCallExpr .getRange ().get ().begin .line );
462
+ callSite .setStartColumn (methodCallExpr .getRange ().get ().begin .column );
463
+ callSite .setEndLine (methodCallExpr .getRange ().get ().end .line );
464
+ callSite .setEndColumn (methodCallExpr .getRange ().get ().end .column );
465
+ } else {
466
+ callSite .setStartLine (-1 );
467
+ callSite .setStartColumn (-1 );
468
+ callSite .setEndLine (-1 );
469
+ callSite .setEndColumn (-1 );
470
+ }
471
+ callSites .add (callSite );
472
+ }
473
+ return callSites ;
474
+ }
475
+
428
476
/**
429
477
* Calculates type for the given expression and returns the resolved type name, or empty string if
430
478
* exception occurs during type resolution.
0 commit comments