Skip to content

Commit 9f9cfea

Browse files
author
Saurabh Sinha
committed
Added field for thrown exceptions to callable info. Added check for illegal state exception
to type resolution for expressions. Signed-off-by: Saurabh Sinha <[email protected]>
1 parent 62fcfae commit 9f9cfea

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import com.github.javaparser.ParseResult;
44
import com.github.javaparser.Problem;
55
import com.github.javaparser.ast.CompilationUnit;
6+
import com.github.javaparser.ast.NodeList;
67
import com.github.javaparser.ast.body.*;
78
import com.github.javaparser.ast.expr.Expression;
89
import com.github.javaparser.ast.expr.FieldAccessExpr;
910
import com.github.javaparser.ast.expr.MethodCallExpr;
1011
import com.github.javaparser.ast.expr.NameExpr;
1112
import com.github.javaparser.ast.nodeTypes.NodeWithName;
1213
import com.github.javaparser.ast.stmt.BlockStmt;
14+
import com.github.javaparser.ast.type.ReferenceType;
1315
import com.github.javaparser.ast.type.Type;
1416
import com.github.javaparser.resolution.UnsolvedSymbolException;
1517
import com.github.javaparser.resolution.types.ResolvedType;
@@ -222,7 +224,6 @@ private static EnumConstant processEnumConstantDeclaration(EnumConstantDeclarati
222224
return enumConstant;
223225
}
224226

225-
226227
/**
227228
* Process parameter declarations on callables.
228229
*
@@ -260,6 +261,13 @@ private static Pair<String, Callable> processCallableDeclaration(CallableDeclara
260261
// add method or constructor modifiers
261262
callableNode.setModifiers((List<String>) callableDecl.getModifiers().stream().map(mod -> mod.toString().strip()).collect(Collectors.toList()));
262263

264+
// add exceptions declared in "throws" clause
265+
callableNode.setThrownExceptions(
266+
((NodeList<ReferenceType>)callableDecl.getThrownExceptions())
267+
.stream()
268+
.map(SymbolTable::resolveType)
269+
.collect(Collectors.toList()));
270+
263271
// add the complete declaration string, including modifiers, throws, and
264272
// parameter names
265273
callableNode.setDeclaration(callableDecl.getDeclarationAsString(true, true, true).strip());
@@ -427,8 +435,8 @@ private static String resolveExpression(Expression expression) {
427435
if (resolvedType.isReferenceType() || resolvedType.isUnionType()) {
428436
return resolvedType.describe();
429437
}
430-
} catch (UnsolvedSymbolException use) {
431-
Log.warn("Could not resolve expression: "+expression+"\n"+use.getMessage());
438+
} catch (UnsolvedSymbolException | IllegalStateException exception) {
439+
Log.warn("Could not resolve expression: "+expression+"\n"+exception.getMessage());
432440
}
433441
return "";
434442
}

src/main/java/com/ibm/northstar/entities/Callable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Callable {
99
private String comment;
1010
private List<String> annotations;
1111
private List<String> modifiers;
12+
private List<String> thrownExceptions;
1213
private String declaration;
1314
private List<ParameterInCallable> parameters;
1415
private String code;

0 commit comments

Comments
 (0)