mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
require that notnull fields be initialized (IDEA-114889)
This commit is contained in:
+11
-1
@@ -154,7 +154,17 @@ public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionToo
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiExpression rhs : DfaPsiUtil.findAllConstructorInitializers(field)) {
|
||||
List<PsiExpression> initializers = DfaPsiUtil.findAllConstructorInitializers(field);
|
||||
if (annotated.isDeclaredNotNull && initializers.isEmpty()) {
|
||||
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(field, manager.getNotNulls());
|
||||
if (annotation != null) {
|
||||
holder.registerProblem(annotation.isPhysical() ? annotation : field.getNameIdentifier(),
|
||||
"Not-null fields must be initialized",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiExpression rhs : initializers) {
|
||||
if (rhs instanceof PsiReferenceExpression) {
|
||||
PsiElement target = ((PsiReferenceExpression)rhs).resolve();
|
||||
if (target instanceof PsiParameter) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class B {
|
||||
@NotNull
|
||||
B b;
|
||||
B b = new B();
|
||||
|
||||
public B <warning descr="Getter for @NotNull field might be annotated @NotNull itself">getB</warning>() {
|
||||
return b;
|
||||
@@ -39,7 +39,7 @@ class C {
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@NotNull C c1;
|
||||
@NotNull C c1 = new C(null);
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public C getC1() {
|
||||
if (c1 != null) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
class Test {
|
||||
<warning descr="Not-null fields must be initialized">@NotNull</warning> Object member;
|
||||
|
||||
private void accessMember() {
|
||||
member = new Object();
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
|
||||
public void testNullableFieldNotnullParam() throws Exception{ doTest(); }
|
||||
public void testNotNullFieldNullableParam() throws Exception{ doTest(); }
|
||||
public void testNotNullCustomException() throws Exception{ doTest(); }
|
||||
public void testNotNullFieldNotInitialized() throws Exception{ doTest(); }
|
||||
|
||||
public void testGetterSetterProblems() throws Exception{ doTest(); }
|
||||
public void testOverriddenMethods() throws Exception{
|
||||
|
||||
Reference in New Issue
Block a user