diff --git a/tools/errorprone/src/main/java/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfaces.java b/tools/errorprone/src/main/java/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfaces.java deleted file mode 100644 index a5755a4c6d5..00000000000 --- a/tools/errorprone/src/main/java/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfaces.java +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.firebase.errorprone; - -import com.google.auto.service.AutoService; -import com.google.errorprone.BugPattern; -import com.google.errorprone.VisitorState; -import com.google.errorprone.bugpatterns.BugChecker; -import com.google.errorprone.matchers.Description; -import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.matchers.Matchers; -import com.sun.source.tree.ClassTree; -import com.sun.source.tree.MethodTree; -import com.sun.source.tree.Tree; -import java.util.Set; -import javax.lang.model.element.Modifier; - -/** Errorprone custom check that forbids use of static and default methods in interfaces. */ -@BugPattern( - name = "NoStaticOrDefaultMethodsInInterfaces", - summary = - "Avoid static/default methods in interfaces: We currently desugar SDKs with retrolambda " - + "which has limited support for those.", - severity = BugPattern.SeverityLevel.ERROR) -@AutoService(BugChecker.class) -public class NoStaticOrDefaultMethodsInInterfaces extends BugChecker - implements BugChecker.MethodTreeMatcher { - private static final Matcher WITHIN_INTERFACE = - Matchers.enclosingClass(new WithinInterface()); - - private static final Matcher HAS_STATIC_METHOD = new HasStaticOrDefaultMethod(); - - @Override - public Description matchMethod(MethodTree tree, VisitorState state) { - if (WITHIN_INTERFACE.matches(tree, state) && HAS_STATIC_METHOD.matches(tree, state)) { - return describeMatch(tree); - } - return Description.NO_MATCH; - } - - private static class WithinInterface implements Matcher { - - @Override - public boolean matches(ClassTree classTree, VisitorState state) { - return classTree.getKind() == Tree.Kind.INTERFACE; - } - } - - private static class HasStaticOrDefaultMethod implements Matcher { - - @Override - public boolean matches(MethodTree methodTree, VisitorState state) { - Set flags = methodTree.getModifiers().getFlags(); - return flags.contains(Modifier.STATIC) || flags.contains(Modifier.DEFAULT); - } - } -} diff --git a/tools/errorprone/src/test/java/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesTest.java b/tools/errorprone/src/test/java/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesTest.java deleted file mode 100644 index 1976c0f85e1..00000000000 --- a/tools/errorprone/src/test/java/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesTest.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.firebase.errorprone; - -import static org.junit.Assert.*; - -import com.google.errorprone.CompilationTestHelper; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class NoStaticOrDefaultMethodsInInterfacesTest { - private CompilationTestHelper compilationHelper; - - @Before - public void setup() { - compilationHelper = - CompilationTestHelper.newInstance(NoStaticOrDefaultMethodsInInterfaces.class, getClass()); - } - - @Test - public void testPositiveCases() { - compilationHelper - .addSourceFile("NoStaticOrDefaultMethodsInInterfacesPositiveCases.java") - .doTest(); - } - - @Test - public void testNegativeCases() { - compilationHelper - .addSourceFile("NoStaticOrDefaultMethodsInInterfacesNegativeCases.java") - .doTest(); - } -} diff --git a/tools/errorprone/src/test/resources/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesNegativeCases.java b/tools/errorprone/src/test/resources/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesNegativeCases.java deleted file mode 100644 index 193c2749b4d..00000000000 --- a/tools/errorprone/src/test/resources/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesNegativeCases.java +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.firebase.errorprone; - -public class NoStaticOrDefaultMethodsInInterfacesNegativeCases { - - public interface EmptyInterface {} - - public interface NonDefaultInterface { - void method1(); - } -} diff --git a/tools/errorprone/src/test/resources/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesPositiveCases.java b/tools/errorprone/src/test/resources/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesPositiveCases.java deleted file mode 100644 index 4a357903527..00000000000 --- a/tools/errorprone/src/test/resources/com/google/firebase/errorprone/NoStaticOrDefaultMethodsInInterfacesPositiveCases.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.firebase.errorprone; - -public class NoStaticOrDefaultMethodsInInterfacesPositiveCases { - - public interface InterfaceWithDefault { - // BUG: Diagnostic contains: Avoid static/default - default void method1() { - return; - } - } - - public interface InterfaceWithStatic { - // BUG: Diagnostic contains: Avoid static/default - static void method1() { - return; - } - } -}