Skip to content

Commit c13ae69

Browse files
authored
Merge pull request #38 from sinha108/main
Added exception handling around method/constructor call resolution
2 parents 16eabdf + 3fa4424 commit c13ae69

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
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;
1715
import com.github.javaparser.resolution.types.ResolvedType;
1816
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
1917
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
@@ -491,14 +489,21 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
491489
} else {
492490
returnType = resolveExpression(methodCallExpr);
493491
}
494-
ResolvedMethodDeclaration resolvedMethodDeclaration = methodCallExpr.resolve();
492+
493+
// resolve callee and get signature
494+
String calleeSignature = "";
495+
try {
496+
calleeSignature = methodCallExpr.resolve().getSignature();
497+
} catch (RuntimeException exception) {
498+
Log.debug("Could not resolve method call: " + methodCallExpr + ": " + exception.getMessage());
499+
}
495500

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

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

512-
ResolvedConstructorDeclaration resolvedConstructorDeclaration = objectCreationExpr.resolve();
517+
// resolve callee and get signature
518+
String calleeSignature = "";
519+
try {
520+
calleeSignature = objectCreationExpr.resolve().getSignature();
521+
} catch (RuntimeException exception) {
522+
Log.debug("Could not resolve constructor call: " + objectCreationExpr + ": " + exception.getMessage());
523+
}
513524

514525
// add a new call site object
515526
callSites.add(createCallSite(objectCreationExpr, "<init>",
516527
objectCreationExpr.getScope().isPresent() ? objectCreationExpr.getScope().get().toString() : "",
517-
instantiatedType, arguments, instantiatedType, resolvedConstructorDeclaration.getSignature(),
518-
false, true));
528+
instantiatedType, arguments, instantiatedType, calleeSignature,false, true));
519529
}
520530

521531
return callSites;

0 commit comments

Comments
 (0)