mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
nullity inference from source dfa: handle autoboxing in return values
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user