source contract inference: handle unboxing during delegation (CR-IC-5787)

This commit is contained in:
peter
2014-07-23 18:37:36 +02:00
parent 209d66a92d
commit c88f288bda
2 changed files with 31 additions and 1 deletions
@@ -71,7 +71,21 @@ class ContractInferenceInterpreter {
if (statements.length == 1) {
if (statements[0] instanceof PsiReturnStatement) {
List<MethodContract> result = handleDelegation(((PsiReturnStatement)statements[0]).getReturnValue(), false);
if (result != null) return result;
if (result != null) {
return ContainerUtil.findAll(result, new Condition<MethodContract>() {
@Override
public boolean value(MethodContract contract) {
if (contract.returnValue == NULL_VALUE || contract.returnValue == NOT_NULL_VALUE) {
PsiTypeElement typeElement = myMethod.getReturnTypeElement();
if (typeElement == null || !(typeElement.getType() instanceof PsiClassType)) {
return false;
}
}
return true;
}
});
}
}
else if (statements[0] instanceof PsiExpressionStatement && ((PsiExpressionStatement)statements[0]).getExpression() instanceof PsiMethodCallExpression) {
List<MethodContract> result = handleDelegation(((PsiExpressionStatement)statements[0]).getExpression(), false);
@@ -228,6 +228,22 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase {
assert c == []
}
public void "test boolean auto-unboxing"() {
def c = inferContracts("""
static boolean test02(String s) {
return test01(s);
}
static Boolean test01(String s) {
if (s == null)
return new Boolean(false);
else
return null;
}
""")
assert c == []
}
public void "test non-returning delegation"() {
def c = inferContracts("""
static void test2(Object o) {