Skip to content

Call site and maven library download path updates #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/main/java/com/ibm/northstar/SymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -490,13 +491,14 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
} else {
returnType = resolveExpression(methodCallExpr);
}
ResolvedMethodDeclaration resolvedMethodDeclaration = methodCallExpr.resolve();

// resolve arguments of the method call to types
List<String> 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)) {
Expand All @@ -505,12 +507,15 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {

// resolve arguments of the constructor call to types
List<String> 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, "<init>",
objectCreationExpr.getScope().isPresent() ? objectCreationExpr.getScope().get().toString() : "",
instantiatedType, arguments, instantiatedType, false, true));
instantiatedType, arguments, instantiatedType, resolvedConstructorDeclaration.getSignature(),
false, true));
}

return callSites;
Expand All @@ -531,13 +536,14 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
*/
private static CallSite createCallSite(Expression callExpr, String calleeName, String receiverExpr,
String receiverType, List<String> 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()) {
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 @@ -11,6 +11,7 @@ public class CallSite {
private String receiverType;
private List<String> argumentTypes;
private String returnType;
private String calleeSignature;
private boolean isStaticCall;
private boolean isConstructorCall;
private int startLine;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ibm/northstar/utils/BuildProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static List<Path> 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);
Expand Down