Skip to content

Commit

Permalink
partial fix to testBug497719_0001 - modifiers missing on try with res…
Browse files Browse the repository at this point in the history
…ources

Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed May 21, 2024
1 parent 0ff8575 commit c2ea72d
Showing 1 changed file with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) {
return res;
}
if (javac instanceof JCTry tryStatement) {
return convertTryStatement(tryStatement);
return convertTryStatement(tryStatement, parent);
}
if (javac instanceof JCSynchronized jcSynchronized) {
SynchronizedStatement res = this.ast.newSynchronizedStatement();
Expand Down Expand Up @@ -2003,7 +2003,7 @@ private Block convertBlock(JCBlock javac) {
return res;
}

private TryStatement convertTryStatement(JCTry javac) {
private TryStatement convertTryStatement(JCTry javac, ASTNode parent) {
TryStatement res = this.ast.newTryStatement();
commonSettings(res, javac);
res.setBody(convertBlock(javac.getBlock()));
Expand All @@ -2012,15 +2012,19 @@ private TryStatement convertTryStatement(JCTry javac) {
}

if( this.ast.apiLevel >= AST.JLS4_INTERNAL) {
javac.getResources().stream().map(this::convertTryResource)
.filter(Objects::nonNull)
.forEach(res.resources()::add);
Iterator<JCTree> it = javac.getResources().iterator();
while(it.hasNext()) {
ASTNode working = convertTryResource(it.next(), parent);
if( working != null ) {
res.resources().add(working);
}
}
}
javac.getCatches().stream().map(this::convertCatcher).forEach(res.catchClauses()::add);
return res;
}

private ASTNode /*VariableDeclarationExpression or Name*/ convertTryResource(JCTree javac) {
private ASTNode /*VariableDeclarationExpression or Name*/ convertTryResource(JCTree javac, ASTNode parent) {
if (javac instanceof JCFieldAccess || javac instanceof JCIdent) {
return toName(javac);
}
Expand Down Expand Up @@ -2050,8 +2054,16 @@ private TryStatement convertTryStatement(JCTry javac) {
fragment = this.ast.newVariableDeclarationFragment();
}
VariableDeclarationExpression res = this.ast.newVariableDeclarationExpression(fragment);
res.setType(convertToType(decl.getType()));
commonSettings(res, javac);
res.setType(convertToType(decl.getType()));
if( this.ast.apiLevel > AST.JLS2_INTERNAL) {
res.modifiers().addAll(convert(decl.getModifiers(), res));
} else {
JCModifiers mods = decl.getModifiers();
int[] total = new int[] {0};
mods.getFlags().forEach(x -> {total[0] += modifierToFlagVal(x);});
res.internalSetModifiers(total[0]);
}
return res;
}
if (javac instanceof JCErroneous error && error.getErrorTrees().isEmpty()) {
Expand Down Expand Up @@ -2472,10 +2484,12 @@ private Modifier convert(javax.lang.model.element.Modifier javac, int startPos,
Modifier res = modifierToDom(javac);
if (startPos >= 0) {
// This needs work... It's not a great solution.
String sub = this.rawText.substring(startPos, endPos);
int indOf = sub.indexOf(res.getKeyword().toString());
if( indOf != -1 ) {
res.setSourceRange(startPos+indOf, res.getKeyword().toString().length());
if( endPos >= startPos && endPos >= 0 && endPos < this.rawText.length()) {
String sub = this.rawText.substring(startPos, endPos);
int indOf = sub.indexOf(res.getKeyword().toString());
if( indOf != -1 ) {
res.setSourceRange(startPos+indOf, res.getKeyword().toString().length());
}
}
}
return res;
Expand Down

0 comments on commit c2ea72d

Please sign in to comment.