Skip to content
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

Use indexOfNextNonWhitespace() rather than getStartPosition() #4653

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -1679,7 +1679,7 @@ public J visitWildcard(WildcardTree node, Space fmt) {
return null;
}
try {
String prefix = source.substring(cursor, Math.max(cursor, getActualStartPosition((JCTree) t)));
String prefix = source.substring(cursor, indexOfNextNonWhitespace(cursor, source));
cursor += prefix.length();
// Java 21 and 23 have a different return type from getCommentTree; with reflection we can support both
Method getCommentTreeMethod = DocCommentTable.class.getMethod("getCommentTree", JCTree.class);
Expand All @@ -1695,14 +1695,6 @@ public J visitWildcard(WildcardTree node, Space fmt) {
}
}

private static int getActualStartPosition(JCTree t) {
// not sure if this is a bug in Lombok, but the variable's start position is after the `val` annotation
if (t instanceof JCVariableDecl && isLombokVal((JCVariableDecl) t)) {
return ((JCVariableDecl) t).mods.annotations.get(0).getStartPosition();
}
return t.getStartPosition();
}

private void reportJavaParsingException(Throwable ex) {
// this SHOULD never happen, but is here simply as a diagnostic measure in the event of unexpected exceptions
StringBuilder message = new StringBuilder("Failed to convert for the following cursor stack:");
Expand Down
Loading