IDEA-165372 (Incorrect suggestion to remove "super" qualifier)

This commit is contained in:
Bas Leijdekkers
2016-12-23 12:29:11 +01:00
parent b727e0d7c8
commit 501b7d99ce
2 changed files with 33 additions and 2 deletions
@@ -26,6 +26,7 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.MethodUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -129,7 +130,7 @@ public class UnnecessarySuperQualifierInspection extends BaseInspection implemen
private static boolean hasUnnecessarySuperQualifier(PsiMethodCallExpression methodCallExpression) {
final PsiMethod superMethod = methodCallExpression.resolveMethod();
if (superMethod == null) {
if (superMethod == null || MethodUtils.isOverridden(superMethod)) {
return false;
}
// check that super.m() and m() resolve to the same method
@@ -20,7 +20,7 @@ public class UnnecessarySuperQualifier {
private static class Up extends Base<String> {
void foo() {
<warning descr="Qualifier 'super' is unnecessary in this context">super</warning>.test("asfd");
super.test("asfd");
System.out.println(<warning descr="Qualifier 'super' is unnecessary in this context">super</warning>.field);
}
}
@@ -80,4 +80,34 @@ public class UnnecessarySuperQualifier {
return String.valueOf(<warning descr="Qualifier 'super' is unnecessary in this context">super</warning>.f);
}
}
}
class BugSuper {
public void close() {
System.out.println("BugSuper.close()");
}
public static void main(String[] arg) {
try {
BugSuper bug = new Next2();
bug.close();
} catch(Throwable t) {
System.out.println("ERROR: " + t);
t.printStackTrace();
}
}
}
class Next1 extends BugSuper {
public void closeall() {
System.out.println("Next1.closeall()");
// IDEA Intellij is suggesting: Remove unnecessary "super" qualifier.
// Try to remove yourself :-)
super.close();
}
}
class Next2 extends Next1 {
public void close() {
System.out.println("Next2.close()");
closeall();
}
}