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:
anna
2010-11-11 14:17:58 +03:00
parent 76c393a145
commit c191be3cc3
4 changed files with 43 additions and 0 deletions
@@ -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);