@@ -299,7 +299,6 @@ private static Pair<String, Callable> processCallableDeclaration(CallableDeclara
299299 callableNode .setReferencedTypes (getReferencedTypes (body ));
300300 callableNode .setCode (body .isPresent () ? body .get ().toString () : "" );
301301
302- callableNode .setCalledMethodDeclaringTypes (getCalledMethodDeclaringTypes (body ));
303302 callableNode .setAccessedFields (getAccessedFields (body , classFields , typeName ));
304303 callableNode .setCallSites (getCallSites (body ));
305304 callableNode .setVariableDeclarations (getVariableDeclarations (body ));
@@ -434,34 +433,6 @@ private static List<String> getAccessedFields(Optional<BlockStmt> callableBody,
434433 return new ArrayList <>(accessedFields );
435434 }
436435
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-
465436 /**
466437 * Returns information about call sites in the given callable. The information includes:
467438 * 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) {
478449 // resolve declaring type for called method
479450 boolean isStaticCall = false ;
480451 String declaringType = "" ;
452+ String receiverName = "" ;
481453 if (methodCallExpr .getScope ().isPresent ()) {
482454 Expression scopeExpr = methodCallExpr .getScope ().get ();
483- declaringType = resolveExpression (methodCallExpr .getScope ().get ());
455+ receiverName = scopeExpr .toString ();
456+ declaringType = resolveExpression (scopeExpr );
484457 if (declaringType .contains (" | " )) {
485458 declaringType = declaringType .split (" \\ | " )[0 ];
486459 }
@@ -494,7 +467,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
494467 List <String > arguments = methodCallExpr .getArguments ().stream ()
495468 .map (arg -> resolveExpression (arg )).collect (Collectors .toList ());
496469 // add a new call site object
497- callSites .add (createCallSite (methodCallExpr , methodCallExpr .getNameAsString (), declaringType ,
470+ callSites .add (createCallSite (methodCallExpr , methodCallExpr .getNameAsString (), receiverName , declaringType ,
498471 arguments , isStaticCall , false ));
499472 }
500473
@@ -512,6 +485,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
512485
513486 // add a new call site object
514487 callSites .add (createCallSite (objectCreationExpr , "<init>" ,
488+ objectCreationExpr .getScope ().isPresent () ? objectCreationExpr .getScope ().get ().toString () : "" ,
515489 instantiatedType , arguments , false , true ));
516490 }
517491
@@ -524,17 +498,20 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
524498 *
525499 * @param callExpr
526500 * @param calleeName
527- * @param declaringType
501+ * @param receiverExpr
502+ * @param receiverType
528503 * @param arguments
529504 * @param isStaticCall
530505 * @param isConstructorCall
531506 * @return
532507 */
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 ) {
535511 CallSite callSite = new CallSite ();
536512 callSite .setMethodName (calleeName );
537- callSite .setDeclaringType (declaringType );
513+ callSite .setReceiverExpr (receiverExpr );
514+ callSite .setReceiverType (receiverType );
538515 callSite .setArgumentTypes (arguments );
539516 callSite .setStaticCall (isStaticCall );
540517 callSite .setConstructorCall (isConstructorCall );
0 commit comments