Skip to content

Commit

Permalink
Merge pull request #28 from sinha108/main
Browse files Browse the repository at this point in the history
Call site information update
  • Loading branch information
rahlk authored Jun 19, 2024
2 parents 9dbae80 + e08b532 commit 7510e5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/ibm/northstar/SymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.type.ReferenceType;
import com.github.javaparser.ast.type.Type;
import com.github.javaparser.resolution.MethodAmbiguityException;
import com.github.javaparser.resolution.UnsolvedSymbolException;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
Expand Down Expand Up @@ -454,6 +452,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
boolean isStaticCall = false;
String declaringType = "";
String receiverName = "";
String returnType = "";
if (methodCallExpr.getScope().isPresent()) {
Expression scopeExpr = methodCallExpr.getScope().get();
receiverName = scopeExpr.toString();
Expand All @@ -466,13 +465,14 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
if (declaringTypeName.equals(scopeExpr.toString())) {
isStaticCall = true;
}
returnType = resolveExpression(methodCallExpr);
}
// resolve arguments of the method call to types
List<String> arguments = methodCallExpr.getArguments().stream()
.map(arg -> resolveExpression(arg)).collect(Collectors.toList());
// add a new call site object
callSites.add(createCallSite(methodCallExpr, methodCallExpr.getNameAsString(), receiverName, declaringType,
arguments, isStaticCall, false));
arguments, returnType, isStaticCall, false));
}

for (ObjectCreationExpr objectCreationExpr : callableBody.get().findAll(ObjectCreationExpr.class)) {
Expand All @@ -486,7 +486,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
// add a new call site object
callSites.add(createCallSite(objectCreationExpr, "<init>",
objectCreationExpr.getScope().isPresent() ? objectCreationExpr.getScope().get().toString() : "",
instantiatedType, arguments, false, true));
instantiatedType, arguments, instantiatedType, false, true));
}

return callSites;
Expand All @@ -506,13 +506,14 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
* @return
*/
private static CallSite createCallSite(Expression callExpr, String calleeName, String receiverExpr,
String receiverType, List<String> arguments, boolean isStaticCall,
boolean isConstructorCall) {
String receiverType, List<String> arguments, String returnType,
boolean isStaticCall, boolean isConstructorCall) {
CallSite callSite = new CallSite();
callSite.setMethodName(calleeName);
callSite.setReceiverExpr(receiverExpr);
callSite.setReceiverType(receiverType);
callSite.setArgumentTypes(arguments);
callSite.setReturnType(returnType);
callSite.setStaticCall(isStaticCall);
callSite.setConstructorCall(isConstructorCall);
if (callExpr.getRange().isPresent()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/ibm/northstar/entities/CallSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CallSite {
private String receiverExpr;
private String receiverType;
private List<String> argumentTypes;
private String returnType;
private boolean isStaticCall;
private boolean isConstructorCall;
private int startLine;
Expand Down

0 comments on commit 7510e5c

Please sign in to comment.