Skip to content

Commit

Permalink
Fixing throws clause and other jls version-specific logic
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed Mar 11, 2024
1 parent dfeeb5d commit d220865
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ private MethodDeclaration convertMethodDecl(JCMethodDecl javac, ASTNode parent)
commonSettings(res, javac);
if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
res.modifiers().addAll(convert(javac.getModifiers()));
} else {
res.internalSetModifiers(getJLS2ModifiersFlags(javac.mods));
}
boolean isConstructor = Objects.equals(javac.getName(), Names.instance(this.context).init);
res.setConstructor(isConstructor);
Expand All @@ -441,10 +443,23 @@ private MethodDeclaration convertMethodDecl(JCMethodDecl javac, ASTNode parent)
res.internalSetReturnType(convertToType(javac.getReturnType()));
}
}

javac.getParameters().stream().map(this::convertVariableDeclaration).forEach(res.parameters()::add);
if (javac.getBody() != null) {
res.setBody(convertBlock(javac.getBody()));
}

List throwing = javac.getThrows();
for( Iterator i = throwing.iterator(); i.hasNext(); ) {
if( this.ast.apiLevel < AST.JLS8_INTERNAL) {
JCIdent id = (JCIdent)i.next();
Name r = convert(id.getName());
res.thrownExceptions().add(r);
} else {
JCIdent id = (JCIdent)i.next();
res.thrownExceptionTypes().add(convertToType(id));
}
}
return res;
}

Expand Down Expand Up @@ -1120,7 +1135,10 @@ private TryStatement convertTryStatement(JCTry javac) {
if (javac.finalizer != null) {
res.setFinally(convertBlock(javac.getFinallyBlock()));
}
javac.getResources().stream().map(this::convertTryResource).forEach(res.resources()::add);

if( this.ast.apiLevel >= AST.JLS4_INTERNAL) {
javac.getResources().stream().map(this::convertTryResource).forEach(res.resources()::add);
}
javac.getCatches().stream().map(this::convertCatcher).forEach(res.catchClauses()::add);
return res;
}
Expand Down

0 comments on commit d220865

Please sign in to comment.