mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
nullable problems: do not suggest to annotate as @Nullable when parameter is referenced (IDEA-93083)
This commit is contained in:
+19
-7
@@ -174,13 +174,25 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
|
||||
new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove)));
|
||||
}
|
||||
else if (annotated.isDeclaredNullable && manager.isNotNull(parameter, false)) {
|
||||
final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier();
|
||||
assert nameIdentifier2 != null : parameter;
|
||||
holder.registerProblem(nameIdentifier2, InspectionsBundle.message(
|
||||
"inspection.nullable.problems.annotated.field.constructor.parameter.conflict", StringUtil.getShortName(anno),
|
||||
notNullSimpleName),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove)));
|
||||
boolean usedAsQualifier = !ReferencesSearch.search(parameter).forEach(new Processor<PsiReference>() {
|
||||
@Override
|
||||
public boolean process(PsiReference reference) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (element instanceof PsiReferenceExpression && element.getParent() instanceof PsiReferenceExpression) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (!usedAsQualifier) {
|
||||
final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier();
|
||||
assert nameIdentifier2 != null : parameter;
|
||||
holder.registerProblem(nameIdentifier2, InspectionsBundle.message(
|
||||
"inspection.nullable.problems.annotated.field.constructor.parameter.conflict", StringUtil.getShortName(anno),
|
||||
notNullSimpleName),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
new AddAnnotationFix(anno, parameter, ArrayUtil.toStringArray(annoToRemove)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>8</line>
|
||||
<description>Constructor parameter for @Nullable field is annotated @NotNull</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
class Test {
|
||||
@Nullable private final String baseFile;
|
||||
@Nullable private final String baseFile1;
|
||||
|
||||
|
||||
public Test(@NotNull String baseFile) {
|
||||
this.baseFile = baseFile;
|
||||
this.baseFile1 = null;
|
||||
}
|
||||
|
||||
public Test(@NotNull String baseFile1, boolean a) {
|
||||
this.baseFile1 = baseFile1;
|
||||
if (baseFile1.contains("foo")) {
|
||||
this.baseFile = null;
|
||||
} else {
|
||||
this.baseFile = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ public class NullableStuffInspectionTest extends InspectionTestCase {
|
||||
|
||||
public void testProblems() throws Exception{ doTest(); }
|
||||
public void testProblems2() throws Exception{ doTest(); }
|
||||
public void testNullableFieldNotnullParam() throws Exception{ doTest(); }
|
||||
public void testJdk14() throws Exception{ doTest14(); }
|
||||
|
||||
public void testGetterSetterProblems() throws Exception{ doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user