mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
protected method calling other overload is not redundant
This commit is contained in:
+6
-6
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user