IDEA-134733 Inspection: @NotNull/@Nullable inspection does not report annotation name in the warning for overridden method

This commit is contained in:
peter
2015-01-02 12:59:13 +01:00
parent af97b204de
commit 1d463f3df4
3 changed files with 32 additions and 0 deletions
@@ -43,6 +43,7 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionTool {
// deprecated fields remain to minimize changes to users inspection profiles (which are often located in version control).
@@ -269,6 +270,12 @@ public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionToo
@NotNull
private static String getPresentableAnnoName(@NotNull PsiModifierListOwner owner) {
NullableNotNullManager manager = NullableNotNullManager.getInstance(owner.getProject());
Set<String> names = ContainerUtil.newHashSet(manager.getNullables());
names.addAll(manager.getNotNulls());
PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(owner, names);
if (annotation != null) return getPresentableAnnoName(annotation);
String anno = manager.getNotNull(owner);
return StringUtil.getShortName(anno != null ? anno : StringUtil.notNullize(manager.getNullable(owner), "???"));
}
@@ -0,0 +1,24 @@
import org.jetbrains.annotations.*;
public class NotNullAnnotationChecksInChildClassMethods {
private static class A {
@NotNull public String getNormalizedName() {
return "classA";
}
}
private static class B extends A {
@Override public String <warning descr="Not annotated method overrides method annotated with @NotNull">getNormalizedName</warning>() {
return "classB";
}
}
private static class C extends B {
@Override public String <warning descr="Not annotated method overrides method annotated with @NotNull">getNormalizedName</warning>() {
return "classC";
}
}
}
@@ -49,6 +49,7 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
public void testNotNullFieldNullableParam() throws Exception{ doTest(); }
public void testNotNullCustomException() throws Exception{ doTest(); }
public void testNotNullFieldNotInitialized() throws Exception{ doTest(); }
public void testNotNullAnnotationChecksInChildClassMethods() { doTest(); }
public void testGetterSetterProblems() throws Exception{ doTest(); }
public void testOverriddenMethods() throws Exception{