From 735ce3d0a6eea83ab0b2e20fe074e499ca558fe7 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 30 Jun 2016 14:49:13 +0200 Subject: [PATCH] IG: remove no longer useful inspection --- .../src/META-INF/InspectionGadgets.xml | 3 - .../siyeh/InspectionGadgetsBundle.properties | 2 - .../ig/bugs/CovariantCompareToInspection.java | 105 ------------------ .../CovariantCompareTo.html | 10 -- .../covariantCompareTo/simple/Simple.java | 11 -- .../covariantCompareTo/simple/expected.xml | 2 - .../CovariantCompareToInspectionTest.java | 29 ----- 7 files changed, 162 deletions(-) delete mode 100644 plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CovariantCompareToInspection.java delete mode 100644 plugins/InspectionGadgets/src/inspectionDescriptions/CovariantCompareTo.html delete mode 100644 plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariantCompareTo/simple/Simple.java delete mode 100644 plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariantCompareTo/simple/expected.xml delete mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CovariantCompareToInspectionTest.java diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml index 0bfbe519655e..7e8728134f00 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml @@ -196,9 +196,6 @@ key="non.final.field.compareto.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.probable.bugs" enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.bugs.CompareToUsesNonFinalVariableInspection"/> - diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index 0fef824fa4f9..9198d15ea0f1 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -62,8 +62,6 @@ collection.added.to.self.display.name=Collection added to self collection.added.to.self.problem.descriptor=''{0}()'' called on collection #ref with itself as argument #loc non.final.field.compareto.display.name=Non-final field referenced in 'compareTo()' non.final.field.compareto.problem.descriptor=Non-final field #ref accessed in 'compareTo()' #loc -covariant.compareto.display.name=Covariant 'compareTo()' -covariant.compareto.problem.descriptor=#ref() should take 'Object' as its argument #loc covariant.equals.display.name=Covariant 'equals()' covariant.equals.problem.descriptor=#ref() should take 'Object' as its argument #loc empty.class.initializer.display.name=Empty class initializer diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CovariantCompareToInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CovariantCompareToInspection.java deleted file mode 100644 index 9de0ecf84302..000000000000 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CovariantCompareToInspection.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers - * - * 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.siyeh.ig.bugs; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.TypeConversionUtil; -import com.siyeh.HardcodedMethodConstants; -import com.siyeh.InspectionGadgetsBundle; -import com.siyeh.ig.BaseInspection; -import com.siyeh.ig.BaseInspectionVisitor; -import com.siyeh.ig.psiutils.MethodUtils; -import com.siyeh.ig.psiutils.TypeUtils; -import org.jetbrains.annotations.NotNull; - -public class CovariantCompareToInspection extends BaseInspection { - - @Override - @NotNull - public String getDisplayName() { - return InspectionGadgetsBundle.message("covariant.compareto.display.name"); - } - - @Override - @NotNull - public String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message("covariant.compareto.problem.descriptor"); - } - - @Override - public BaseInspectionVisitor buildVisitor() { - return new CovariantCompareToVisitor(); - } - - private static class CovariantCompareToVisitor extends BaseInspectionVisitor { - - @Override - public void visitMethod(@NotNull PsiMethod method) { - final String name = method.getName(); - if (!HardcodedMethodConstants.COMPARE_TO.equals(name)) { - return; - } - if (!method.hasModifierProperty(PsiModifier.PUBLIC)) { - return; - } - final PsiParameterList parameterList = method.getParameterList(); - if (parameterList.getParametersCount() != 1) { - return; - } - final PsiParameter[] parameters = parameterList.getParameters(); - final PsiType paramType = parameters[0].getType(); - if (TypeUtils.isJavaLangObject(paramType)) { - return; - } - final PsiClass aClass = method.getContainingClass(); - if (aClass == null) { - return; - } - final PsiMethod[] methods = aClass.findMethodsByName(HardcodedMethodConstants.COMPARE_TO, false); - final Project project = method.getProject(); - final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); - final GlobalSearchScope scope = method.getResolveScope(); - final PsiClass comparableClass = psiFacade.findClass(CommonClassNames.JAVA_LANG_COMPARABLE, scope); - PsiType substitutedTypeParam = null; - if (comparableClass != null && comparableClass.getTypeParameters().length == 1) { - final PsiSubstitutor superSubstitutor = TypeConversionUtil.getClassSubstitutor(comparableClass, aClass, PsiSubstitutor.EMPTY); - //null iff aClass is not inheritor of comparableClass - if (superSubstitutor != null) { - substitutedTypeParam = superSubstitutor.substitute(comparableClass.getTypeParameters()[0]); - } - } - for (PsiMethod compareToMethod : methods) { - if (isNonVariantCompareTo(compareToMethod, substitutedTypeParam)) { - return; - } - } - registerMethodError(method); - } - - private static boolean isNonVariantCompareTo(PsiMethod method, PsiType substitutedTypeParam) { - final PsiClassType objectType = TypeUtils.getObjectType(method); - if (MethodUtils.methodMatches(method, null, PsiType.INT, HardcodedMethodConstants.COMPARE_TO, objectType)) { - return true; - } - if (substitutedTypeParam == null) { - return false; - } - return MethodUtils.methodMatches(method, null, PsiType.INT, HardcodedMethodConstants.COMPARE_TO, substitutedTypeParam); - } - } -} \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/CovariantCompareTo.html b/plugins/InspectionGadgets/src/inspectionDescriptions/CovariantCompareTo.html deleted file mode 100644 index 7ab9a5bcbb08..000000000000 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/CovariantCompareTo.html +++ /dev/null @@ -1,10 +0,0 @@ - - -Reports a class having a compareTo() -method taking an argument other than java.lang.Object, if the class does not have a compareTo() method -which does take java.lang.Object as its argument. Normally, this is a mistake. - -

- - - \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariantCompareTo/simple/Simple.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariantCompareTo/simple/Simple.java deleted file mode 100644 index 52fed23d835d..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariantCompareTo/simple/Simple.java +++ /dev/null @@ -1,11 +0,0 @@ -import java.lang.Comparable; - -class Foo implements Comparable { - public int compareTo(Foo o) { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } - - public int compareTo(String o) { - return 0; //To change body of implemented methods use File | Settings | File Templates. - } -} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariantCompareTo/simple/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariantCompareTo/simple/expected.xml deleted file mode 100644 index 4704d91e891d..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/covariantCompareTo/simple/expected.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CovariantCompareToInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CovariantCompareToInspectionTest.java deleted file mode 100644 index 2109c8b1fcf3..000000000000 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/CovariantCompareToInspectionTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * 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.siyeh.ig.bugs; - -import com.siyeh.ig.IGInspectionTestCase; - -public class CovariantCompareToInspectionTest extends IGInspectionTestCase { - - public void testSimple() throws Exception { - doTest(); - } - - private void doTest() throws Exception { - doTest("com/siyeh/igtest/bugs/covariantCompareTo/" + getTestName(true), new CovariantCompareToInspection()); - } -}