44import com .github .javaparser .ParseResult ;
55import com .github .javaparser .ParserConfiguration ;
66import com .github .javaparser .Problem ;
7+ import com .github .javaparser .ast .AccessSpecifier ;
78import com .github .javaparser .ast .CompilationUnit ;
89import com .github .javaparser .ast .NodeList ;
910import com .github .javaparser .ast .body .*;
1213import com .github .javaparser .ast .stmt .BlockStmt ;
1314import com .github .javaparser .ast .type .ReferenceType ;
1415import com .github .javaparser .ast .type .Type ;
16+ import com .github .javaparser .resolution .declarations .ResolvedMethodDeclaration ;
1517import com .github .javaparser .resolution .types .ResolvedType ;
1618import com .github .javaparser .symbolsolver .JavaSymbolSolver ;
1719import com .github .javaparser .symbolsolver .resolution .typesolvers .CombinedTypeSolver ;
@@ -498,12 +500,21 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
498500 Log .debug ("Could not resolve method call: " + methodCallExpr + ": " + exception .getMessage ());
499501 }
500502
503+ // Resolve access qualifier
504+ AccessSpecifier accessSpecifier = AccessSpecifier .NONE ;
505+ try {
506+ ResolvedMethodDeclaration resolvedMethodDeclaration = methodCallExpr .resolve ();
507+ accessSpecifier = resolvedMethodDeclaration .accessSpecifier ();
508+ }
509+ catch (RuntimeException exception ) {
510+ Log .debug ("Could not resolve access specifier for method call: " + methodCallExpr + ": " + exception .getMessage ());
511+ }
501512 // resolve arguments of the method call to types
502513 List <String > arguments = methodCallExpr .getArguments ().stream ()
503514 .map (SymbolTable ::resolveExpression ).collect (Collectors .toList ());
504515 // add a new call site object
505516 callSites .add (createCallSite (methodCallExpr , methodCallExpr .getNameAsString (), receiverName , declaringType ,
506- arguments , returnType , calleeSignature , isStaticCall , false ));
517+ arguments , returnType , calleeSignature , isStaticCall , false , accessSpecifier ));
507518 }
508519
509520 for (ObjectCreationExpr objectCreationExpr : callableBody .get ().findAll (ObjectCreationExpr .class )) {
@@ -525,7 +536,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
525536 // add a new call site object
526537 callSites .add (createCallSite (objectCreationExpr , "<init>" ,
527538 objectCreationExpr .getScope ().isPresent () ? objectCreationExpr .getScope ().get ().toString () : "" ,
528- instantiatedType , arguments , instantiatedType , calleeSignature ,false , true ));
539+ instantiatedType , arguments , instantiatedType , calleeSignature ,false , true , AccessSpecifier . NONE ));
529540 }
530541
531542 return callSites ;
@@ -546,7 +557,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
546557 */
547558 private static CallSite createCallSite (Expression callExpr , String calleeName , String receiverExpr ,
548559 String receiverType , List <String > arguments , String returnType ,
549- String calleeSignature , boolean isStaticCall , boolean isConstructorCall ) {
560+ String calleeSignature , boolean isStaticCall , boolean isConstructorCall , AccessSpecifier accessSpecifier ) {
550561 CallSite callSite = new CallSite ();
551562 callSite .setMethodName (calleeName );
552563 callSite .setReceiverExpr (receiverExpr );
@@ -556,6 +567,10 @@ private static CallSite createCallSite(Expression callExpr, String calleeName, S
556567 callSite .setCalleeSignature (calleeSignature );
557568 callSite .setStaticCall (isStaticCall );
558569 callSite .setConstructorCall (isConstructorCall );
570+ callSite .setPrivate (accessSpecifier .equals (AccessSpecifier .PRIVATE ));
571+ callSite .setPublic (accessSpecifier .equals (AccessSpecifier .PUBLIC ));
572+ callSite .setProtected (accessSpecifier .equals (AccessSpecifier .PROTECTED ));
573+ callSite .setUnspecified (accessSpecifier .equals (AccessSpecifier .NONE ));
559574 if (callExpr .getRange ().isPresent ()) {
560575 callSite .setStartLine (callExpr .getRange ().get ().begin .line );
561576 callSite .setStartColumn (callExpr .getRange ().get ().begin .column );
0 commit comments