mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-134733 Inspection: @NotNull/@Nullable inspection does not report annotation name in the warning for overridden method
This commit is contained in:
+7
@@ -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), "???"));
|
||||
}
|
||||
|
||||
+24
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user