mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-178922 A few more null annotation problems with arrays
This commit is contained in:
@@ -247,15 +247,14 @@ public abstract class NullableNotNullManager {
|
||||
PsiAnnotation memberAnno = checkBases && owner instanceof PsiMethod
|
||||
? AnnotationUtil.findAnnotationInHierarchy(owner, qNames)
|
||||
: AnnotationUtil.findAnnotation(owner, qNames);
|
||||
PsiType type = getOwnerType(owner);
|
||||
if (memberAnno != null) {
|
||||
if (owner instanceof PsiMethod) {
|
||||
return preferTypeAnnotation(memberAnno, ((PsiMethod)owner).getReturnType());
|
||||
}
|
||||
if (owner instanceof PsiVariable) {
|
||||
return preferTypeAnnotation(memberAnno, ((PsiVariable)owner).getType());
|
||||
}
|
||||
return preferTypeAnnotation(memberAnno, type);
|
||||
}
|
||||
if (type != null) {
|
||||
return ContainerUtil.find(type.getAnnotations(), a -> qNames.contains(a.getQualifiedName()));
|
||||
}
|
||||
return memberAnno;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PsiAnnotation preferTypeAnnotation(@NotNull PsiAnnotation memberAnno, @Nullable PsiType type) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import typeUse.*;
|
||||
|
||||
class Test {
|
||||
private byte <warning descr="Not-null fields must be initialized">@NotNull</warning> [] field;
|
||||
private byte @NotNull [] initField;
|
||||
|
||||
{
|
||||
initField = new byte[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import typeUse.*;
|
||||
|
||||
class Super {
|
||||
void m1(byte @NotNull [] p) {}
|
||||
void m2(byte @NotNull [] p) {}
|
||||
void m3(byte[] p) {}
|
||||
}
|
||||
|
||||
class Sub extends Super {
|
||||
void m1(byte @NotNull [] p) {}
|
||||
void m2(byte[] <warning descr="Not annotated parameter overrides @NotNull parameter">p</warning>) {}
|
||||
void m3(byte <warning descr="Parameter annotated @NotNull should not override non-annotated parameter">@NotNull</warning> [] p) {}
|
||||
|
||||
}
|
||||
+11
@@ -240,6 +240,17 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTypeUseNotNullField() {
|
||||
DataFlowInspection8Test.setupTypeUseAnnotations("typeUse", myFixture);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTypeUseNotNullOverriding() {
|
||||
myInspection.REPORT_NOTNULL_PARAMETERS_OVERRIDES_NOT_ANNOTATED = true;
|
||||
DataFlowInspection8Test.setupTypeUseAnnotations("typeUse", myFixture);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnnotateQuickFixOnMethodReference() {
|
||||
doTest();
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Annotate"));
|
||||
|
||||
Reference in New Issue
Block a user