mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
source contract inference: handle unboxing during delegation (CR-IC-5787)
This commit is contained in:
+15
-1
@@ -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);
|
||||
|
||||
+16
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user