Skip to content

Commit 7510e5c

Browse files
authored
Merge pull request #28 from sinha108/main
Call site information update
2 parents 9dbae80 + e08b532 commit 7510e5c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import com.github.javaparser.ast.stmt.BlockStmt;
1313
import com.github.javaparser.ast.type.ReferenceType;
1414
import com.github.javaparser.ast.type.Type;
15-
import com.github.javaparser.resolution.MethodAmbiguityException;
16-
import com.github.javaparser.resolution.UnsolvedSymbolException;
1715
import com.github.javaparser.resolution.types.ResolvedType;
1816
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
1917
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
@@ -454,6 +452,7 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
454452
boolean isStaticCall = false;
455453
String declaringType = "";
456454
String receiverName = "";
455+
String returnType = "";
457456
if (methodCallExpr.getScope().isPresent()) {
458457
Expression scopeExpr = methodCallExpr.getScope().get();
459458
receiverName = scopeExpr.toString();
@@ -466,13 +465,14 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
466465
if (declaringTypeName.equals(scopeExpr.toString())) {
467466
isStaticCall = true;
468467
}
468+
returnType = resolveExpression(methodCallExpr);
469469
}
470470
// resolve arguments of the method call to types
471471
List<String> arguments = methodCallExpr.getArguments().stream()
472472
.map(arg -> resolveExpression(arg)).collect(Collectors.toList());
473473
// add a new call site object
474474
callSites.add(createCallSite(methodCallExpr, methodCallExpr.getNameAsString(), receiverName, declaringType,
475-
arguments, isStaticCall, false));
475+
arguments, returnType, isStaticCall, false));
476476
}
477477

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

492492
return callSites;
@@ -506,13 +506,14 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
506506
* @return
507507
*/
508508
private static CallSite createCallSite(Expression callExpr, String calleeName, String receiverExpr,
509-
String receiverType, List<String> arguments, boolean isStaticCall,
510-
boolean isConstructorCall) {
509+
String receiverType, List<String> arguments, String returnType,
510+
boolean isStaticCall, boolean isConstructorCall) {
511511
CallSite callSite = new CallSite();
512512
callSite.setMethodName(calleeName);
513513
callSite.setReceiverExpr(receiverExpr);
514514
callSite.setReceiverType(receiverType);
515515
callSite.setArgumentTypes(arguments);
516+
callSite.setReturnType(returnType);
516517
callSite.setStaticCall(isStaticCall);
517518
callSite.setConstructorCall(isConstructorCall);
518519
if (callExpr.getRange().isPresent()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class CallSite {
1010
private String receiverExpr;
1111
private String receiverType;
1212
private List<String> argumentTypes;
13+
private String returnType;
1314
private boolean isStaticCall;
1415
private boolean isConstructorCall;
1516
private int startLine;

0 commit comments

Comments
 (0)