mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-147534 Inspection "@NotNull/@Nullable problems" - "Require @NotNull fileds to be initialized explicitly", does not trigger when using @NonnullByDefault
This commit is contained in:
+12
-15
@@ -105,12 +105,12 @@ public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionToo
|
||||
|
||||
checkAccessors(field, annotated, project, manager, anno, annoToRemove, holder);
|
||||
|
||||
if (REQUIRE_NOTNULL_FIELDS_INITIALIZED) {
|
||||
checkNotNullFieldsInitialized(field, annotated, manager, holder);
|
||||
}
|
||||
|
||||
checkConstructorParameters(field, annotated, manager, anno, annoToRemove, holder);
|
||||
}
|
||||
|
||||
if (REQUIRE_NOTNULL_FIELDS_INITIALIZED && !annotated.isDeclaredNullable) {
|
||||
checkNotNullFieldsInitialized(field, manager, holder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,17 +259,14 @@ public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionToo
|
||||
LOG.assertTrue(parameter.isPhysical(), setter.getText());
|
||||
}
|
||||
|
||||
private static void checkNotNullFieldsInitialized(PsiField field,
|
||||
Annotated annotated,
|
||||
NullableNotNullManager manager, @NotNull ProblemsHolder holder) {
|
||||
if (annotated.isDeclaredNotNull && !HighlightControlFlowUtil.isFieldInitializedAfterObjectConstruction(field)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
private static void checkNotNullFieldsInitialized(PsiField field, NullableNotNullManager manager, @NotNull ProblemsHolder holder) {
|
||||
PsiAnnotation annotation = manager.getNotNullAnnotation(field, false);
|
||||
if (annotation == null || HighlightControlFlowUtil.isFieldInitializedAfterObjectConstruction(field)) return;
|
||||
|
||||
boolean byDefault = manager.isContainerAnnotation(annotation);
|
||||
PsiJavaCodeReferenceElement name = annotation.getNameReferenceElement();
|
||||
holder.registerProblem(annotation.isPhysical() && !byDefault ? annotation : field.getNameIdentifier(),
|
||||
(byDefault && name != null ? "@" + name.getReferenceName() : "Not-null") + " fields must be initialized");
|
||||
}
|
||||
|
||||
private void checkConstructorParameters(PsiField field,
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import javax.annotation.*;
|
||||
|
||||
@NonnullByDefault
|
||||
class Test {
|
||||
Object <warning descr="@NonnullByDefault fields must be initialized">member</warning>;
|
||||
|
||||
private void accessMember() {
|
||||
member = new Object();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@javax.annotation.meta.TypeQualifierDefault(java.lang.annotation.ElementType.FIELD)
|
||||
@interface NonnullByDefault {}
|
||||
@@ -59,6 +59,11 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotNullByDefaultFieldNotInitialized() {
|
||||
DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotNullAnnotationChecksInChildClassMethods() { doTest(); }
|
||||
|
||||
public void testGetterSetterProblems() throws Exception{ doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user