diff options
Diffstat (limited to 'java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java')
-rw-r--r-- | java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java index a1c908837ad0..bd207e58a0fe 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java @@ -71,7 +71,23 @@ 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) { + PsiTypeElement typeElement = myMethod.getReturnTypeElement(); + final boolean returningObject = typeElement == null || !(typeElement.getType() instanceof PsiClassType); + return ContainerUtil.findAll(result, new Condition<MethodContract>() { + @Override + public boolean value(MethodContract contract) { + if ((contract.returnValue == NULL_VALUE || contract.returnValue == NOT_NULL_VALUE) && returningObject) { + return false; + } + if ((contract.returnValue == TRUE_VALUE || contract.returnValue == FALSE_VALUE) && !returningObject) { + 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); @@ -132,6 +148,9 @@ class ContractInferenceInterpreter { } else { answer = withConstraint(answer, paramIndex, argConstraint); + if (answer == null) { + return null; + } } } } |