diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/RedundantMethodOverrideInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/RedundantMethodOverrideInspection.java index 0ff4b39bb4b1..a02e8993f53b 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/RedundantMethodOverrideInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/RedundantMethodOverrideInspection.java @@ -112,10 +112,9 @@ public class RedundantMethodOverrideInspection extends BaseInspection { return; // method overridden and made final - not redundant } final PsiCodeBlock superBody = superMethod.getBody(); - if (!EquivalenceChecker.codeBlocksAreEquivalent(body, superBody) && !isSuperCallWithSameArguments(body, method, superMethod)) { - return; + if (EquivalenceChecker.codeBlocksAreEquivalent(body, superBody) || isSuperCallWithSameArguments(body, method, superMethod)) { + registerMethodError(method); } - registerMethodError(method); } private static boolean isSuperCallWithSameArguments(PsiCodeBlock body, PsiMethod method, PsiMethod superMethod) { @@ -146,15 +145,16 @@ public class RedundantMethodOverrideInspection extends BaseInspection { if (!(expression instanceof PsiMethodCallExpression)) { return false; } + final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression; + if (!MethodCallUtils.isSuperMethodCall(methodCallExpression, method)) return false; + if (superMethod.hasModifierProperty(PsiModifier.PROTECTED)) { final PsiJavaFile superFile = (PsiJavaFile)superMethod.getContainingFile(); final PsiJavaFile file = (PsiJavaFile)method.getContainingFile(); // implementing a protected method in another package makes it available to that package. - return superFile.getPackageName().equals(file.getPackageName()); + if (!superFile.getPackageName().equals(file.getPackageName())) return false; } - final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression; - if (!MethodCallUtils.isSuperMethodCall(methodCallExpression, method)) return false; return areSameArguments(methodCallExpression, method); } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/redundant_method_override/RedundantMethodOverride.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/redundant_method_override/RedundantMethodOverride.java index 35ea4d6f3a1d..ada7188f92b9 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/redundant_method_override/RedundantMethodOverride.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/redundant_method_override/RedundantMethodOverride.java @@ -76,4 +76,19 @@ class MyList extends ArrayList { protected void removeRange(int fromIndex, int toIndex) { super.removeRange(fromIndex, toIndex); } +} +//////////////// +class Sup { + void overload1(int i) {} + void overload1(int i, boolean b) {} + + protected void foox() { + overload1(0); + } +} +class Sub extends Sup { + @Override + protected void foox() { // not redundant + overload1(0, true); + } } \ No newline at end of file