Skip to content

Commit a706e8d

Browse files
java-team-github-botError Prone Team
authored and
Error Prone Team
committed
Add ability to suppress warning for the entire AutoValue class
PiperOrigin-RevId: 660029479
1 parent 86df5cf commit a706e8d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/AutoValueBoxedValues.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class AutoValueBoxedValues extends BugChecker implements ClassTreeMatcher
6262

6363
@Override
6464
public Description matchClass(ClassTree tree, VisitorState state) {
65-
if (!hasAnnotation(tree, AutoValue.class.getName(), state)) {
65+
if (!hasAnnotation(tree, AutoValue.class.getName(), state) || isSuppressed(tree, state)) {
6666
return NO_MATCH;
6767
}
6868

core/src/test/java/com/google/errorprone/bugpatterns/AutoValueBoxedValuesTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,34 @@ public void mixedTypes_refactoring() {
345345
.doTest();
346346
}
347347

348+
@Test
349+
public void unnecessaryBoxedTypes_suppressWarningsForClass() {
350+
compilationHelper
351+
.addSourceLines(
352+
"in/Test.java",
353+
mergeLines(
354+
lines(
355+
"import com.google.auto.value.AutoValue;",
356+
"@AutoValue",
357+
"@SuppressWarnings(\"AutoValueBoxedValues\")",
358+
"abstract class Test {",
359+
" public abstract Long longId();",
360+
" public abstract Integer intId();"),
361+
linesWithoutBuilder(
362+
" static Test create(Long longId, Integer intId) {",
363+
" return new AutoValue_Test(longId, intId);",
364+
" }"),
365+
linesWithBuilder(
366+
" @AutoValue.Builder",
367+
" abstract static class Builder {",
368+
" abstract Builder setLongId(Long value);",
369+
" abstract Builder setIntId(Integer value);",
370+
" abstract Test build();",
371+
" }"),
372+
lines("}")))
373+
.doTest();
374+
}
375+
348376
@Test
349377
public void unnecessaryBoxedTypes_suppressWarnings() {
350378
refactoringHelper

0 commit comments

Comments
 (0)