Skip to content

Commit

Permalink
Merge pull request #34 from sinha108/main
Browse files Browse the repository at this point in the history
Call site and maven library download path updates
  • Loading branch information
rangeetpan authored Jul 10, 2024
2 parents 580cb4c + b9fafc9 commit 4f0849b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
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

0 comments on commit 4f0849b

Please sign in to comment.