Skip to content

Commit

Permalink
UnusedNestedClass: don't complain about classes whose name begins wit…
Browse files Browse the repository at this point in the history
…h "Unused".

PiperOrigin-RevId: 518021137
  • Loading branch information
graememorgan authored and Error Prone Team committed Mar 20, 2023
1 parent 3816046 commit 7f9ce8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -16,6 +16,7 @@

package com.google.errorprone.bugpatterns;

import static com.google.common.base.Ascii.toLowerCase;
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
import static com.google.errorprone.matchers.Description.NO_MATCH;
import static com.google.errorprone.util.ASTHelpers.canBeRemoved;
Expand Down Expand Up @@ -91,7 +92,9 @@ public Void visitClass(ClassTree classTree, Void unused) {
}

private boolean ignoreUnusedClass(ClassTree classTree, VisitorState state) {
return isSuppressed(classTree, state) || shouldKeep(classTree);
return isSuppressed(classTree, state)
|| shouldKeep(classTree)
|| toLowerCase(classTree.getSimpleName().toString()).startsWith("unused");
}
}

Expand Down
Expand Up @@ -43,6 +43,17 @@ public void positive() {
.doTest();
}

@Test
public void exemptedByUnusedPrefix() {
compilationHelper
.addSourceLines(
"Test.java", //
"class A {",
" private class UnusedClass {}",
"}")
.doTest();
}

@Test
public void nonPrivateNestedClass_noWarning() {
compilationHelper
Expand Down

0 comments on commit 7f9ce8b

Please sign in to comment.