Skip to content

Commit

Permalink
AnnotationPosition: don't fail on record compact constructors.
Browse files Browse the repository at this point in the history
Fixes external #3494

PiperOrigin-RevId: 482595425
  • Loading branch information
graememorgan authored and Error Prone Team committed Oct 21, 2022
1 parent 0087e31 commit 3b4b102
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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
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);
}
}
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

0 comments on commit 3b4b102

Please sign in to comment.