empty methods hierarchy: warn about deepest methods, top empty could be of use (IDEA-146409)

This commit is contained in:
Anna Kozlova
2015-10-27 10:04:09 +01:00
parent 9144909495
commit dfb190bfe0
4 changed files with 31 additions and 2 deletions
@@ -83,8 +83,8 @@ public class EmptyMethodInspection extends GlobalJavaBatchInspectionTool {
String message = null;
boolean needToDeleteHierarchy = false;
RefMethod refSuper = findSuperWithBody(refMethod);
if (refMethod.isOnlyCallsSuper() && !refMethod.isFinal()) {
RefMethod refSuper = findSuperWithBody(refMethod);
final RefJavaUtil refUtil = RefJavaUtil.getInstance();
if (refSuper != null && Comparing.strEqual(refMethod.getAccessModifier(), refSuper.getAccessModifier())){
if (Comparing.strEqual(refSuper.getAccessModifier(), PsiModifier.PROTECTED) //protected modificator gives access to method in another package
@@ -112,7 +112,7 @@ public class EmptyMethodInspection extends GlobalJavaBatchInspectionTool {
message = InspectionsBundle.message("inspection.empty.method.problem.descriptor1");
}
else if (areAllImplementationsEmpty(refMethod)) {
else if (areAllImplementationsEmpty(refMethod) && refSuper == null) {
if (refMethod.hasBody()) {
if (refMethod.getDerivedMethods().isEmpty()) {
if (refMethod.getSuperMethods().isEmpty()) {
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Derived.java</file>
<line>15</line>
<description>Empty method overrides empty method</description>
</problem>
</problems>
@@ -0,0 +1,17 @@
package p2;
class A {
public void foo(){
System.out.println("");
}
}
class B extends A {
@Override
public void foo() {}
}
class C extends B {
@Override
public void foo() {}
}
@@ -49,4 +49,8 @@ public class EmptyMethodTest extends InspectionTestCase {
public void testSuperWithoutSync() throws Exception {
doTest();
}
public void testEmptyMethodsHierarchy() throws Exception {
doTest();
}
}