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

AnnotationPosition: don't fail on record compact constructors. #3502

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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 @@ -159,6 +159,9 @@ private static List<ErrorProneToken> annotationTokens(
endPos = getStartPosition(methodTree.getReturnType());
} else if (!methodTree.getParameters().isEmpty()) {
endPos = getStartPosition(methodTree.getParameters().get(0));
if (endPos < annotationEnd) {
endPos = state.getEndPosition(methodTree);
}
} else if (methodTree.getBody() != null && !methodTree.getBody().getStatements().isEmpty()) {
endPos = getStartPosition(methodTree.getBody().getStatements().get(0));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,18 @@ public void varKeyword() {
.expectUnchanged()
.doTest(TEXT_MATCH);
}

@Test
public void recordAnnotation() {
assumeTrue(RuntimeVersion.isAtLeast16());
refactoringHelper
.addInputLines(
"Test.java",
"public record Test(String bar) {",
" @SuppressWarnings(\"unused\")",
" public Test {}",
"}")
.expectUnchanged()
.doTest(TEXT_MATCH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ void verifyMatch(JavaFileObject refactoredSource, JavaFileObject expectedSource)
private String maybeFormat(String input) {
try {
return new Formatter().formatSource(input);
} catch (FormatterException e) {
// TODO(b/254713810): Remove the AIOOBE catch below.
} catch (FormatterException | ArrayIndexOutOfBoundsException e) {
return input;
}
}
Expand Down