Skip to content

Commit 4f0849b

Browse files
authored
Merge pull request #34 from sinha108/main
Call site and maven library download path updates
2 parents 580cb4c + b9fafc9 commit 4f0849b

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
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.declarations.ResolvedConstructorDeclaration;
16+
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
1517
import com.github.javaparser.resolution.types.ResolvedType;
1618
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
1719
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
@@ -27,8 +29,7 @@
2729
import org.apache.commons.lang3.tuple.Pair;
2830

2931
import java.io.IOException;
30-
import java.nio.file.Path;
31-
import java.nio.file.Paths;
32+
import java.nio.file.*;
3233
import java.util.*;
3334
import java.util.stream.Collectors;
3435
import java.util.stream.IntStream;
@@ -490,13 +491,14 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
490491
} else {
491492
returnType = resolveExpression(methodCallExpr);
492493
}
494+
ResolvedMethodDeclaration resolvedMethodDeclaration = methodCallExpr.resolve();
493495

494496
// resolve arguments of the method call to types
495497
List<String> arguments = methodCallExpr.getArguments().stream()
496-
.map(arg -> resolveExpression(arg)).collect(Collectors.toList());
498+
.map(SymbolTable::resolveExpression).collect(Collectors.toList());
497499
// add a new call site object
498500
callSites.add(createCallSite(methodCallExpr, methodCallExpr.getNameAsString(), receiverName, declaringType,
499-
arguments, returnType, isStaticCall, false));
501+
arguments, returnType, resolvedMethodDeclaration.getSignature(), isStaticCall, false));
500502
}
501503

502504
for (ObjectCreationExpr objectCreationExpr : callableBody.get().findAll(ObjectCreationExpr.class)) {
@@ -505,12 +507,15 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
505507

506508
// resolve arguments of the constructor call to types
507509
List<String> arguments = objectCreationExpr.getArguments().stream()
508-
.map(arg -> resolveExpression(arg)).collect(Collectors.toList());
510+
.map(SymbolTable::resolveExpression).collect(Collectors.toList());
511+
512+
ResolvedConstructorDeclaration resolvedConstructorDeclaration = objectCreationExpr.resolve();
509513

510514
// add a new call site object
511515
callSites.add(createCallSite(objectCreationExpr, "<init>",
512516
objectCreationExpr.getScope().isPresent() ? objectCreationExpr.getScope().get().toString() : "",
513-
instantiatedType, arguments, instantiatedType, false, true));
517+
instantiatedType, arguments, instantiatedType, resolvedConstructorDeclaration.getSignature(),
518+
false, true));
514519
}
515520

516521
return callSites;
@@ -531,13 +536,14 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
531536
*/
532537
private static CallSite createCallSite(Expression callExpr, String calleeName, String receiverExpr,
533538
String receiverType, List<String> arguments, String returnType,
534-
boolean isStaticCall, boolean isConstructorCall) {
539+
String calleeSignature, boolean isStaticCall, boolean isConstructorCall) {
535540
CallSite callSite = new CallSite();
536541
callSite.setMethodName(calleeName);
537542
callSite.setReceiverExpr(receiverExpr);
538543
callSite.setReceiverType(receiverType);
539544
callSite.setArgumentTypes(arguments);
540545
callSite.setReturnType(returnType);
546+
callSite.setCalleeSignature(calleeSignature);
541547
callSite.setStaticCall(isStaticCall);
542548
callSite.setConstructorCall(isConstructorCall);
543549
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
@@ -11,6 +11,7 @@ public class CallSite {
1111
private String receiverType;
1212
private List<String> argumentTypes;
1313
private String returnType;
14+
private String calleeSignature;
1415
private boolean isStaticCall;
1516
private boolean isConstructorCall;
1617
private int startLine;

src/main/java/com/ibm/northstar/utils/BuildProject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static List<Path> buildProjectAndStreamClassFiles(String projectPath, Str
129129
*/
130130
public static boolean downloadLibraryDependencies(String projectPath) {
131131
// created download dir if it does not exist
132-
libDownloadPath = Paths.get(projectPath, LIB_DEPS_DOWNLOAD_DIR);
132+
libDownloadPath = Paths.get(projectPath, LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
133133
if (!Files.exists(libDownloadPath)) {
134134
try {
135135
Files.createDirectory(libDownloadPath);

0 commit comments

Comments
 (0)