diff --git a/src/main/java/com/ibm/northstar/SymbolTable.java b/src/main/java/com/ibm/northstar/SymbolTable.java index 1f6dcc55..bfac5849 100644 --- a/src/main/java/com/ibm/northstar/SymbolTable.java +++ b/src/main/java/com/ibm/northstar/SymbolTable.java @@ -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; @@ -454,6 +452,7 @@ private static List getCallSites(Optional callableBody) { boolean isStaticCall = false; String declaringType = ""; String receiverName = ""; + String returnType = ""; if (methodCallExpr.getScope().isPresent()) { Expression scopeExpr = methodCallExpr.getScope().get(); receiverName = scopeExpr.toString(); @@ -466,13 +465,14 @@ private static List getCallSites(Optional callableBody) { if (declaringTypeName.equals(scopeExpr.toString())) { isStaticCall = true; } + returnType = resolveExpression(methodCallExpr); } // resolve arguments of the method call to types List 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)) { @@ -486,7 +486,7 @@ private static List getCallSites(Optional callableBody) { // add a new call site object callSites.add(createCallSite(objectCreationExpr, "", objectCreationExpr.getScope().isPresent() ? objectCreationExpr.getScope().get().toString() : "", - instantiatedType, arguments, false, true)); + instantiatedType, arguments, instantiatedType, false, true)); } return callSites; @@ -506,13 +506,14 @@ private static List getCallSites(Optional callableBody) { * @return */ private static CallSite createCallSite(Expression callExpr, String calleeName, String receiverExpr, - String receiverType, List arguments, boolean isStaticCall, - boolean isConstructorCall) { + String receiverType, List 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()) { diff --git a/src/main/java/com/ibm/northstar/entities/CallSite.java b/src/main/java/com/ibm/northstar/entities/CallSite.java index 53d82f7d..13fef7d3 100644 --- a/src/main/java/com/ibm/northstar/entities/CallSite.java +++ b/src/main/java/com/ibm/northstar/entities/CallSite.java @@ -10,6 +10,7 @@ public class CallSite { private String receiverExpr; private String receiverType; private List argumentTypes; + private String returnType; private boolean isStaticCall; private boolean isConstructorCall; private int startLine;