@@ -299,7 +299,6 @@ private static Pair<String, Callable> processCallableDeclaration(CallableDeclara
299
299
callableNode .setReferencedTypes (getReferencedTypes (body ));
300
300
callableNode .setCode (body .isPresent () ? body .get ().toString () : "" );
301
301
302
- callableNode .setCalledMethodDeclaringTypes (getCalledMethodDeclaringTypes (body ));
303
302
callableNode .setAccessedFields (getAccessedFields (body , classFields , typeName ));
304
303
callableNode .setCallSites (getCallSites (body ));
305
304
callableNode .setVariableDeclarations (getVariableDeclarations (body ));
@@ -434,34 +433,6 @@ private static List<String> getAccessedFields(Optional<BlockStmt> callableBody,
434
433
return new ArrayList <>(accessedFields );
435
434
}
436
435
437
- /**
438
- * For method calls occurring in the given callable, computes the set of declaring types and returns
439
- * their qualified names.
440
- *
441
- * @param callableBody Callable to compute declaring types for called methods
442
- * @return List of qualified type names for method calls
443
- */
444
- private static List <String > getCalledMethodDeclaringTypes (Optional <BlockStmt > callableBody ) {
445
- Set <String > calledMethodDeclaringTypes = new HashSet <>();
446
- callableBody .ifPresent (cb -> cb .findAll (MethodCallExpr .class )
447
- .stream ()
448
- .map (expr -> {
449
- String resolvedExpr = "" ;
450
- if (expr .getScope ().isPresent ()) {
451
- resolvedExpr = resolveExpression (expr .getScope ().get ());
452
- if (resolvedExpr .contains (" | " )) {
453
- return resolvedExpr .split (" \\ | " );
454
- }
455
- }
456
- return new String []{resolvedExpr };
457
- })
458
- .flatMap (type -> Arrays .stream (type ))
459
- .filter (type -> !type .isEmpty ())
460
- .forEach (calledMethodDeclaringTypes ::add )
461
- );
462
- return new ArrayList <>(calledMethodDeclaringTypes );
463
- }
464
-
465
436
/**
466
437
* Returns information about call sites in the given callable. The information includes:
467
438
* the method name, the declaring type name, and types of arguments used in method call.
@@ -478,9 +449,11 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
478
449
// resolve declaring type for called method
479
450
boolean isStaticCall = false ;
480
451
String declaringType = "" ;
452
+ String receiverName = "" ;
481
453
if (methodCallExpr .getScope ().isPresent ()) {
482
454
Expression scopeExpr = methodCallExpr .getScope ().get ();
483
- declaringType = resolveExpression (methodCallExpr .getScope ().get ());
455
+ receiverName = scopeExpr .toString ();
456
+ declaringType = resolveExpression (scopeExpr );
484
457
if (declaringType .contains (" | " )) {
485
458
declaringType = declaringType .split (" \\ | " )[0 ];
486
459
}
@@ -494,7 +467,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
494
467
List <String > arguments = methodCallExpr .getArguments ().stream ()
495
468
.map (arg -> resolveExpression (arg )).collect (Collectors .toList ());
496
469
// add a new call site object
497
- callSites .add (createCallSite (methodCallExpr , methodCallExpr .getNameAsString (), declaringType ,
470
+ callSites .add (createCallSite (methodCallExpr , methodCallExpr .getNameAsString (), receiverName , declaringType ,
498
471
arguments , isStaticCall , false ));
499
472
}
500
473
@@ -512,6 +485,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
512
485
513
486
// add a new call site object
514
487
callSites .add (createCallSite (objectCreationExpr , "<init>" ,
488
+ objectCreationExpr .getScope ().isPresent () ? objectCreationExpr .getScope ().get ().toString () : "" ,
515
489
instantiatedType , arguments , false , true ));
516
490
}
517
491
@@ -524,17 +498,20 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
524
498
*
525
499
* @param callExpr
526
500
* @param calleeName
527
- * @param declaringType
501
+ * @param receiverExpr
502
+ * @param receiverType
528
503
* @param arguments
529
504
* @param isStaticCall
530
505
* @param isConstructorCall
531
506
* @return
532
507
*/
533
- private static CallSite createCallSite (Expression callExpr , String calleeName , String declaringType ,
534
- List <String > arguments , boolean isStaticCall , boolean isConstructorCall ) {
508
+ private static CallSite createCallSite (Expression callExpr , String calleeName , String receiverExpr ,
509
+ String receiverType , List <String > arguments , boolean isStaticCall ,
510
+ boolean isConstructorCall ) {
535
511
CallSite callSite = new CallSite ();
536
512
callSite .setMethodName (calleeName );
537
- callSite .setDeclaringType (declaringType );
513
+ callSite .setReceiverExpr (receiverExpr );
514
+ callSite .setReceiverType (receiverType );
538
515
callSite .setArgumentTypes (arguments );
539
516
callSite .setStaticCall (isStaticCall );
540
517
callSite .setConstructorCall (isConstructorCall );
0 commit comments