IDEA-212402 Inspection Use Objects.requireNonNull detected, but the fix not work for ParametersAreNonnullByDefault

GitOrigin-RevId: f3d7caf333fdf02abdb4da5fa7aa873a9d33e0bd
This commit is contained in:
Tagir Valeev
2019-05-14 07:03:15 +03:00
committed by intellij-monorepo-bot
parent 13779f3aae
commit 77eeff1698
4 changed files with 32 additions and 10 deletions
@@ -54,8 +54,9 @@ public class ObjectsRequireNonNullIntention extends Intention {
return;
}
final PsiVariable variable = (PsiVariable)target;
final List<String> notNulls = NullableNotNullManager.getInstance(element.getProject()).getNotNulls();
final PsiAnnotation annotation = AnnotationUtil.findAnnotation(variable, notNulls);
NullableNotNullManager manager = NullableNotNullManager.getInstance(element.getProject());
final NullabilityAnnotationInfo info = manager.findEffectiveNullabilityInfo(variable);
final PsiAnnotation annotation = info == null ? null : info.getAnnotation();
final CommentTracker commentTracker = new CommentTracker();
if (annotation == null) {
final PsiStatement referenceStatement = PsiTreeUtil.getParentOfType(referenceExpression, PsiStatement.class);
@@ -0,0 +1,8 @@
@javax.annotation.ParametersAreNonnullByDefault
public class Test {
private final String message;
public Test(String message) {
this.message = m<caret>essage;
}
}
@@ -0,0 +1,10 @@
import java.util.Objects;
@javax.annotation.ParametersAreNonnullByDefault
public class Test {
private final String message;
public Test(String message) {
this.message = Objects.requireNonNull(message);
}
}
@@ -15,31 +15,34 @@
*/
package com.siyeh.ipp.asserttoif;
import com.intellij.java.codeInspection.DataFlowInspectionTest;
import com.intellij.testFramework.LightProjectDescriptor;
import com.siyeh.IntentionPowerPackBundle;
import com.siyeh.ipp.IPPTestCase;
import org.jetbrains.annotations.NotNull;
/**
* @see com.siyeh.ipp.asserttoif.ObjectsRequireNonNullIntention
* @author Bas Leijdekkers
*/
public class ObjectsRequireNonNullIntentionTest extends IPPTestCase {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_8;
}
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.addClass("package java.util;\n" +
"public class Objects {\n" +
" public static <T> T requireNonNull(T obj) {\n" +
" if (obj == null)\n" +
" throw new NullPointerException();\n" +
" return obj;\n" +
" }\n" +
"}");
DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture);
DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture);
}
public void testOne() { doTest(); }
public void testTwo() { doTest(); }
public void testThree() { doTest(); }
public void testContainer() { doTest(); }
@Override
protected String getRelativePath() {