4
4
import com .github .javaparser .ParseResult ;
5
5
import com .github .javaparser .ParserConfiguration ;
6
6
import com .github .javaparser .Problem ;
7
+ import com .github .javaparser .ast .AccessSpecifier ;
7
8
import com .github .javaparser .ast .CompilationUnit ;
8
9
import com .github .javaparser .ast .NodeList ;
9
10
import com .github .javaparser .ast .body .*;
12
13
import com .github .javaparser .ast .stmt .BlockStmt ;
13
14
import com .github .javaparser .ast .type .ReferenceType ;
14
15
import com .github .javaparser .ast .type .Type ;
16
+ import com .github .javaparser .resolution .declarations .ResolvedMethodDeclaration ;
15
17
import com .github .javaparser .resolution .types .ResolvedType ;
16
18
import com .github .javaparser .symbolsolver .JavaSymbolSolver ;
17
19
import com .github .javaparser .symbolsolver .resolution .typesolvers .CombinedTypeSolver ;
@@ -498,12 +500,21 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
498
500
Log .debug ("Could not resolve method call: " + methodCallExpr + ": " + exception .getMessage ());
499
501
}
500
502
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
+ }
501
512
// resolve arguments of the method call to types
502
513
List <String > arguments = methodCallExpr .getArguments ().stream ()
503
514
.map (SymbolTable ::resolveExpression ).collect (Collectors .toList ());
504
515
// add a new call site object
505
516
callSites .add (createCallSite (methodCallExpr , methodCallExpr .getNameAsString (), receiverName , declaringType ,
506
- arguments , returnType , calleeSignature , isStaticCall , false ));
517
+ arguments , returnType , calleeSignature , isStaticCall , false , accessSpecifier ));
507
518
}
508
519
509
520
for (ObjectCreationExpr objectCreationExpr : callableBody .get ().findAll (ObjectCreationExpr .class )) {
@@ -525,7 +536,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
525
536
// add a new call site object
526
537
callSites .add (createCallSite (objectCreationExpr , "<init>" ,
527
538
objectCreationExpr .getScope ().isPresent () ? objectCreationExpr .getScope ().get ().toString () : "" ,
528
- instantiatedType , arguments , instantiatedType , calleeSignature ,false , true ));
539
+ instantiatedType , arguments , instantiatedType , calleeSignature ,false , true , AccessSpecifier . NONE ));
529
540
}
530
541
531
542
return callSites ;
@@ -546,7 +557,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
546
557
*/
547
558
private static CallSite createCallSite (Expression callExpr , String calleeName , String receiverExpr ,
548
559
String receiverType , List <String > arguments , String returnType ,
549
- String calleeSignature , boolean isStaticCall , boolean isConstructorCall ) {
560
+ String calleeSignature , boolean isStaticCall , boolean isConstructorCall , AccessSpecifier accessSpecifier ) {
550
561
CallSite callSite = new CallSite ();
551
562
callSite .setMethodName (calleeName );
552
563
callSite .setReceiverExpr (receiverExpr );
@@ -556,6 +567,10 @@ private static CallSite createCallSite(Expression callExpr, String calleeName, S
556
567
callSite .setCalleeSignature (calleeSignature );
557
568
callSite .setStaticCall (isStaticCall );
558
569
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 ));
559
574
if (callExpr .getRange ().isPresent ()) {
560
575
callSite .setStartLine (callExpr .getRange ().get ().begin .line );
561
576
callSite .setStartColumn (callExpr .getRange ().get ().begin .column );
0 commit comments