Skip to content

Commit

Permalink
Exclude default methods from MethodCanBeStatic.
Browse files Browse the repository at this point in the history
This is a bit over-zealous, but I can't imagine it often being a useful finding.

Fixes external google#3090

PiperOrigin-RevId: 457126278
  • Loading branch information
graememorgan authored and Error Prone Team committed Jun 25, 2022
1 parent 7598623 commit adbcd33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static com.google.errorprone.util.ASTHelpers.getStartPosition;
import static java.util.Collections.disjoint;
import static javax.lang.model.element.Modifier.ABSTRACT;
import static javax.lang.model.element.Modifier.DEFAULT;
import static javax.lang.model.element.Modifier.NATIVE;
import static javax.lang.model.element.Modifier.SYNCHRONIZED;

Expand Down Expand Up @@ -250,7 +251,7 @@ private static boolean isExcluded(MethodTree tree, VisitorState state) {
}

private static final ImmutableSet<Modifier> EXCLUDED_MODIFIERS =
immutableEnumSet(NATIVE, SYNCHRONIZED, ABSTRACT);
immutableEnumSet(NATIVE, SYNCHRONIZED, ABSTRACT, DEFAULT);

/** Information about a {@link MethodSymbol} and whether it can be made static. */
private static final class MethodDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,12 @@ public void abstractMethod_notFlagged() {
"}")
.doTest();
}

@Test
public void defaultMethodExempted() {
testHelper
.addSourceLines(
"Test.java", "class Test {", " private interface Foo { default void foo() {} }", "}")
.doTest();
}
}

0 comments on commit adbcd33

Please sign in to comment.