mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
nullity: skip assert statements for local vars - should be possible to detect from usages; use in prams nullification (IDEA-60705)
This commit is contained in:
@@ -197,6 +197,10 @@ public class NullityInferrer {
|
||||
neverNull = expressionIsNeverNull(expression.getRExpression());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAssertStatement(PsiAssertStatement statement) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitConditionalExpression(@NotNull PsiConditionalExpression expression) {
|
||||
final PsiExpression condition = expression.getCondition();
|
||||
@@ -299,6 +303,10 @@ public class NullityInferrer {
|
||||
sometimesNull = expressionIsSometimesNull(expression.getRExpression());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAssertStatement(PsiAssertStatement statement) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitConditionalExpression(@NotNull PsiConditionalExpression expression) {
|
||||
final PsiExpression condition = expression.getCondition();
|
||||
@@ -534,6 +542,12 @@ public class NullityInferrer {
|
||||
opposite = lOperand;
|
||||
}
|
||||
if (opposite != null && opposite.getType() == PsiType.NULL) {
|
||||
if (parent.getParent() instanceof PsiAssertStatement) {
|
||||
if (((PsiBinaryExpression)parent).getOperationTokenType() == JavaTokenType.NE) {
|
||||
registerNotNullAnnotation(parameter);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
registerNullableAnnotation(parameter);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class Test {
|
||||
@NotNull
|
||||
public String noNull(@NotNull String text) {
|
||||
assert text != null;
|
||||
return "";
|
||||
}
|
||||
|
||||
private void foo() {
|
||||
@NotNull String str = "";
|
||||
assert str != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
public String noNull(String text) {
|
||||
assert text != null;
|
||||
return "";
|
||||
}
|
||||
|
||||
private void foo() {
|
||||
String str = "";
|
||||
assert str != null;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,10 @@ public class NullityInferrerTest extends CodeInsightTestCase {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testAssertParamNotNull() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
//-----------------------fields---------------------------------------------------
|
||||
public void testFieldsAssignment() throws Exception {
|
||||
doTest(false);
|
||||
|
||||
Reference in New Issue
Block a user