Skip to content

Commit

Permalink
Add ability to suppress warning for the entire AutoValue class
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 660029479
  • Loading branch information
java-team-github-bot authored and Error Prone Team committed Aug 6, 2024
1 parent 86df5cf commit a706e8d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class AutoValueBoxedValues extends BugChecker implements ClassTreeMatcher

@Override
public Description matchClass(ClassTree tree, VisitorState state) {
if (!hasAnnotation(tree, AutoValue.class.getName(), state)) {
if (!hasAnnotation(tree, AutoValue.class.getName(), state) || isSuppressed(tree, state)) {
return NO_MATCH;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,34 @@ public void mixedTypes_refactoring() {
.doTest();
}

@Test
public void unnecessaryBoxedTypes_suppressWarningsForClass() {
compilationHelper
.addSourceLines(
"in/Test.java",
mergeLines(
lines(
"import com.google.auto.value.AutoValue;",
"@AutoValue",
"@SuppressWarnings(\"AutoValueBoxedValues\")",
"abstract class Test {",
" public abstract Long longId();",
" public abstract Integer intId();"),
linesWithoutBuilder(
" static Test create(Long longId, Integer intId) {",
" return new AutoValue_Test(longId, intId);",
" }"),
linesWithBuilder(
" @AutoValue.Builder",
" abstract static class Builder {",
" abstract Builder setLongId(Long value);",
" abstract Builder setIntId(Integer value);",
" abstract Test build();",
" }"),
lines("}")))
.doTest();
}

@Test
public void unnecessaryBoxedTypes_suppressWarnings() {
refactoringHelper
Expand Down

0 comments on commit a706e8d

Please sign in to comment.