Skip to content

Fix Java token order in special cases (new) #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,15 @@ public Object visitTry(TryTree node, Object p) {
addToken(JavaTokenType.J_TRY_BEGIN, start, 3);
else
addToken(JavaTokenType.J_TRY_WITH_RESOURCE, start, 3);
if (node.getFinallyBlock() != null)
scan(node.getResources(), p);
scan(node.getBlock(), p);
scan(node.getCatches(), p);
if (node.getFinallyBlock() != null) {
start = positions.getStartPosition(ast, node.getFinallyBlock());
addToken(JavaTokenType.J_FINALLY, start, 3);
return super.visitTry(node, p);
}
scan(node.getFinallyBlock(), p);
return null; // return value isn't used
}

@Override
Expand All @@ -261,13 +267,13 @@ public Object visitIf(IfTree node, Object p) {
long start = positions.getStartPosition(ast, node);
long end = positions.getEndPosition(ast, node) - 1;
addToken(JavaTokenType.J_IF_BEGIN, start, 2);
node.getCondition().accept(this, p);
node.getThenStatement().accept(this, p);
scan(node.getCondition(), p);
scan(node.getThenStatement(), p);
if (node.getElseStatement() != null) {
start = positions.getStartPosition(ast, node.getElseStatement());
addToken(JavaTokenType.J_ELSE, start, 4);
node.getElseStatement().accept(this, p);
}
scan(node.getElseStatement(), p);
addToken(JavaTokenType.J_IF_END, end, 1);
return null;
}
Expand Down Expand Up @@ -319,16 +325,23 @@ public Object visitTypeParameter(TypeParameterTree node, Object p) {
}

@Override
public Object visitNewArray(NewArrayTree node, Object arg1) {
public Object visitNewArray(NewArrayTree node, Object p) {
long start = positions.getStartPosition(ast, node);
long end = positions.getEndPosition(ast, node) - 1;
addToken(JavaTokenType.J_NEWARRAY, start, 3);
if (node.getInitializers() != null && !node.getInitializers().isEmpty()) {
scan(node.getType(), p);
scan(node.getDimensions(), p);
boolean hasInit = node.getInitializers() != null && !node.getInitializers().isEmpty();
if (hasInit) {
start = positions.getStartPosition(ast, node.getInitializers().get(0));
addToken(JavaTokenType.J_ARRAY_INIT_BEGIN, start, 1);
}
scan(node.getInitializers(), p);
// super method has annotation processing but we have it disabled anyways
if (hasInit) {
addToken(JavaTokenType.J_ARRAY_INIT_END, end, 1);
}
return super.visitNewArray(node, arg1);
return null; // return value isn't used
}

@Override
Expand Down