nullity inference from source dfa: handle autoboxing in return values

This commit is contained in:
peter
2014-12-03 17:35:12 +01:00
parent 155208faea
commit c2ef559c17
2 changed files with 13 additions and 16 deletions

View File

@@ -253,10 +253,6 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
if (value instanceof DfaVariableValue) {
setVariableState(var, getVariableState((DfaVariableValue)value));
}
else if (value instanceof DfaBoxedValue) {
setVariableState(var, getVariableState(var).withNullable(false));
applyCondition(compareToNull(var, true));
}
}
if (getVariableState(var).isNotNull()) {
@@ -477,6 +473,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
@Override
public boolean isNotNull(DfaValue dfaVar) {
if (dfaVar instanceof DfaConstValue) return ((DfaConstValue)dfaVar).getValue() != null;
if (dfaVar instanceof DfaBoxedValue) return true;
if (dfaVar instanceof DfaTypeValue) return ((DfaTypeValue)dfaVar).isNotNull();
if (dfaVar instanceof DfaVariableValue) {
if (getVariableState((DfaVariableValue)dfaVar).isNotNull()) return true;

View File

@@ -50,6 +50,18 @@ abstract class NullityInferenceFromSourceTestCase extends LightCodeInsightFixtur
assert inferNullity(parse('String foo() { return bar(); }; String bar() { if (equals(2)) return null; return "a"; }; ')) == UNKNOWN
}
void "test return boxed boolean constant"() {
assert inferNullity(parse('Object foo() { return true; }')) == NOT_NULL
}
void "test return boxed boolean value"() {
assert inferNullity(parse('Object foo(Object o) { return o == null; }')) == NOT_NULL
}
void "test return boxed integer"() {
assert inferNullity(parse('Object foo() { return 1; }')) == NOT_NULL
}
protected abstract Nullness inferNullity(PsiMethod method)
private PsiMethod parse(String method) {
@@ -60,18 +72,6 @@ abstract class NullityInferenceFromSourceTestCase extends LightCodeInsightFixtur
Nullness inferNullity(PsiMethod method) {
return NullableNotNullManager.isNotNull(method) ? NOT_NULL : NullableNotNullManager.isNullable(method) ? NULLABLE : UNKNOWN
}
void "test return boxed boolean constant"() {
assert inferNullity(parse('Object foo() { return true; }')) == NOT_NULL
}
void "test return boxed boolean value"() {
assert inferNullity(parse('Object foo(Object o) { return o == null; }')) == NOT_NULL
}
void "test return boxed integer"() {
assert inferNullity(parse('Object foo() { return 1; }')) == NOT_NULL
}
}
static class DfaInferenceTest extends NullityInferenceFromSourceTestCase {