Skip to content

Commit

Permalink
Merge pull request #38 from sinha108/main
Browse files Browse the repository at this point in the history
Added exception handling around method/constructor call resolution
  • Loading branch information
rangeetpan authored Jul 11, 2024
2 parents 16eabdf + 3fa4424 commit c13ae69
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/main/java/com/ibm/northstar/SymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.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 Down Expand Up @@ -491,14 +489,21 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
} else {
returnType = resolveExpression(methodCallExpr);
}
ResolvedMethodDeclaration resolvedMethodDeclaration = methodCallExpr.resolve();

// resolve callee and get signature
String calleeSignature = "";
try {
calleeSignature = methodCallExpr.resolve().getSignature();
} catch (RuntimeException exception) {
Log.debug("Could not resolve method call: " + methodCallExpr + ": " + exception.getMessage());
}

// resolve arguments of the method call to types
List<String> arguments = methodCallExpr.getArguments().stream()
.map(SymbolTable::resolveExpression).collect(Collectors.toList());
// add a new call site object
callSites.add(createCallSite(methodCallExpr, methodCallExpr.getNameAsString(), receiverName, declaringType,
arguments, returnType, resolvedMethodDeclaration.getSignature(), isStaticCall, false));
arguments, returnType, calleeSignature, isStaticCall, false));
}

for (ObjectCreationExpr objectCreationExpr : callableBody.get().findAll(ObjectCreationExpr.class)) {
Expand All @@ -509,13 +514,18 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
List<String> arguments = objectCreationExpr.getArguments().stream()
.map(SymbolTable::resolveExpression).collect(Collectors.toList());

ResolvedConstructorDeclaration resolvedConstructorDeclaration = objectCreationExpr.resolve();
// resolve callee and get signature
String calleeSignature = "";
try {
calleeSignature = objectCreationExpr.resolve().getSignature();
} catch (RuntimeException exception) {
Log.debug("Could not resolve constructor call: " + objectCreationExpr + ": " + exception.getMessage());
}

// add a new call site object
callSites.add(createCallSite(objectCreationExpr, "<init>",
objectCreationExpr.getScope().isPresent() ? objectCreationExpr.getScope().get().toString() : "",
instantiatedType, arguments, instantiatedType, resolvedConstructorDeclaration.getSignature(),
false, true));
instantiatedType, arguments, instantiatedType, calleeSignature,false, true));
}

return callSites;
Expand Down

0 comments on commit c13ae69

Please sign in to comment.