summaryrefslogtreecommitdiff
path: root/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2014-08-19 12:53:10 -0700
committerTor Norbye <tnorbye@google.com>2014-08-19 12:53:10 -0700
commit02cf98d65c798d368fcec43ed64a001d513bdd4f (patch)
treee39e210ab20917b7e5ffdce14a42f5747506eed0 /java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java
parent2e5965e996aad62ab1338b09d54caaf99ff3dd6a (diff)
downloadidea-02cf98d65c798d368fcec43ed64a001d513bdd4f.tar.gz
Snapshot idea/138.1503 from git://git.jetbrains.org/idea/community.git
Change-Id: Ie01af1d8710ec0ff51d90301bda1a18b0b5c0faf
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.java21
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;
+ }
}
}
}