diff --git a/src/main/java/com/ibm/northstar/SymbolTable.java b/src/main/java/com/ibm/northstar/SymbolTable.java index c84f09be..45d39e2e 100644 --- a/src/main/java/com/ibm/northstar/SymbolTable.java +++ b/src/main/java/com/ibm/northstar/SymbolTable.java @@ -12,6 +12,8 @@ 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.declarations.ResolvedConstructorDeclaration; +import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; @@ -27,8 +29,7 @@ import org.apache.commons.lang3.tuple.Pair; import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -490,13 +491,14 @@ private static List getCallSites(Optional callableBody) { } else { returnType = resolveExpression(methodCallExpr); } + ResolvedMethodDeclaration resolvedMethodDeclaration = methodCallExpr.resolve(); // resolve arguments of the method call to types List arguments = methodCallExpr.getArguments().stream() - .map(arg -> resolveExpression(arg)).collect(Collectors.toList()); + .map(SymbolTable::resolveExpression).collect(Collectors.toList()); // add a new call site object callSites.add(createCallSite(methodCallExpr, methodCallExpr.getNameAsString(), receiverName, declaringType, - arguments, returnType, isStaticCall, false)); + arguments, returnType, resolvedMethodDeclaration.getSignature(), isStaticCall, false)); } for (ObjectCreationExpr objectCreationExpr : callableBody.get().findAll(ObjectCreationExpr.class)) { @@ -505,12 +507,15 @@ private static List getCallSites(Optional callableBody) { // resolve arguments of the constructor call to types List arguments = objectCreationExpr.getArguments().stream() - .map(arg -> resolveExpression(arg)).collect(Collectors.toList()); + .map(SymbolTable::resolveExpression).collect(Collectors.toList()); + + ResolvedConstructorDeclaration resolvedConstructorDeclaration = objectCreationExpr.resolve(); // add a new call site object callSites.add(createCallSite(objectCreationExpr, "", objectCreationExpr.getScope().isPresent() ? objectCreationExpr.getScope().get().toString() : "", - instantiatedType, arguments, instantiatedType, false, true)); + instantiatedType, arguments, instantiatedType, resolvedConstructorDeclaration.getSignature(), + false, true)); } return callSites; @@ -531,13 +536,14 @@ private static List getCallSites(Optional callableBody) { */ private static CallSite createCallSite(Expression callExpr, String calleeName, String receiverExpr, String receiverType, List arguments, String returnType, - boolean isStaticCall, boolean isConstructorCall) { + String calleeSignature, boolean isStaticCall, boolean isConstructorCall) { CallSite callSite = new CallSite(); callSite.setMethodName(calleeName); callSite.setReceiverExpr(receiverExpr); callSite.setReceiverType(receiverType); callSite.setArgumentTypes(arguments); callSite.setReturnType(returnType); + callSite.setCalleeSignature(calleeSignature); 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 13fef7d3..0c466d46 100644 --- a/src/main/java/com/ibm/northstar/entities/CallSite.java +++ b/src/main/java/com/ibm/northstar/entities/CallSite.java @@ -11,6 +11,7 @@ public class CallSite { private String receiverType; private List argumentTypes; private String returnType; + private String calleeSignature; private boolean isStaticCall; private boolean isConstructorCall; private int startLine; diff --git a/src/main/java/com/ibm/northstar/utils/BuildProject.java b/src/main/java/com/ibm/northstar/utils/BuildProject.java index fd233969..0b2a3458 100644 --- a/src/main/java/com/ibm/northstar/utils/BuildProject.java +++ b/src/main/java/com/ibm/northstar/utils/BuildProject.java @@ -129,7 +129,7 @@ public static List buildProjectAndStreamClassFiles(String projectPath, Str */ public static boolean downloadLibraryDependencies(String projectPath) { // created download dir if it does not exist - libDownloadPath = Paths.get(projectPath, LIB_DEPS_DOWNLOAD_DIR); + libDownloadPath = Paths.get(projectPath, LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath(); if (!Files.exists(libDownloadPath)) { try { Files.createDirectory(libDownloadPath);