Skip to content

Commit 2691303

Browse files
committed
Update callsites object to include public/private/protected/default flags.
Signed-off-by: Rahul Krishna <[email protected]>
1 parent f16860f commit 2691303

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/main/java/com/ibm/northstar/SymbolTable.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.javaparser.ParseResult;
55
import com.github.javaparser.ParserConfiguration;
66
import com.github.javaparser.Problem;
7+
import com.github.javaparser.ast.AccessSpecifier;
78
import com.github.javaparser.ast.CompilationUnit;
89
import com.github.javaparser.ast.NodeList;
910
import com.github.javaparser.ast.body.*;
@@ -12,6 +13,7 @@
1213
import com.github.javaparser.ast.stmt.BlockStmt;
1314
import com.github.javaparser.ast.type.ReferenceType;
1415
import com.github.javaparser.ast.type.Type;
16+
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
1517
import com.github.javaparser.resolution.types.ResolvedType;
1618
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
1719
import 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);

src/main/java/com/ibm/northstar/entities/CallSite.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public class CallSite {
1212
private List<String> argumentTypes;
1313
private String returnType;
1414
private String calleeSignature;
15+
// Access specifiers
16+
private boolean isPublic = false;
17+
private boolean isProtected = false;
18+
private boolean isPrivate = false;
19+
private boolean isUnspecified = false;
1520
private boolean isStaticCall;
1621
private boolean isConstructorCall;
1722
private int startLine;

0 commit comments

Comments
 (0)