|
3 | 3 | import com.github.javaparser.ParseResult; |
4 | 4 | import com.github.javaparser.Problem; |
5 | 5 | import com.github.javaparser.ast.CompilationUnit; |
| 6 | +import com.github.javaparser.ast.NodeList; |
6 | 7 | import com.github.javaparser.ast.body.*; |
7 | 8 | import com.github.javaparser.ast.expr.Expression; |
8 | 9 | import com.github.javaparser.ast.expr.FieldAccessExpr; |
9 | 10 | import com.github.javaparser.ast.expr.MethodCallExpr; |
10 | 11 | import com.github.javaparser.ast.expr.NameExpr; |
11 | 12 | import com.github.javaparser.ast.nodeTypes.NodeWithName; |
12 | 13 | import com.github.javaparser.ast.stmt.BlockStmt; |
| 14 | +import com.github.javaparser.ast.type.ReferenceType; |
13 | 15 | import com.github.javaparser.ast.type.Type; |
14 | 16 | import com.github.javaparser.resolution.UnsolvedSymbolException; |
15 | 17 | import com.github.javaparser.resolution.types.ResolvedType; |
@@ -222,7 +224,6 @@ private static EnumConstant processEnumConstantDeclaration(EnumConstantDeclarati |
222 | 224 | return enumConstant; |
223 | 225 | } |
224 | 226 |
|
225 | | - |
226 | 227 | /** |
227 | 228 | * Process parameter declarations on callables. |
228 | 229 | * |
@@ -260,6 +261,13 @@ private static Pair<String, Callable> processCallableDeclaration(CallableDeclara |
260 | 261 | // add method or constructor modifiers |
261 | 262 | callableNode.setModifiers((List<String>) callableDecl.getModifiers().stream().map(mod -> mod.toString().strip()).collect(Collectors.toList())); |
262 | 263 |
|
| 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 | + |
263 | 271 | // add the complete declaration string, including modifiers, throws, and |
264 | 272 | // parameter names |
265 | 273 | callableNode.setDeclaration(callableDecl.getDeclarationAsString(true, true, true).strip()); |
@@ -427,8 +435,8 @@ private static String resolveExpression(Expression expression) { |
427 | 435 | if (resolvedType.isReferenceType() || resolvedType.isUnionType()) { |
428 | 436 | return resolvedType.describe(); |
429 | 437 | } |
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()); |
432 | 440 | } |
433 | 441 | return ""; |
434 | 442 | } |
|
0 commit comments