diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java index c055c56275be..864d7854f4e5 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java @@ -963,6 +963,26 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { expectedType = ((PsiAssignmentExpression)parent).getLExpression().getType(); } } + else if (parent instanceof PsiIfStatement) { + if (methodCall.equals(PsiUtil.skipParenthesizedExprDown(((PsiIfStatement)parent).getCondition()))) { + expectedType = PsiType.BOOLEAN.getBoxedType(parent); + } + } + else if (parent instanceof PsiWhileStatement) { + if (methodCall.equals(PsiUtil.skipParenthesizedExprDown(((PsiWhileStatement)parent).getCondition()))) { + expectedType = PsiType.BOOLEAN.getBoxedType(parent); + } + } + else if (parent instanceof PsiForStatement) { + if (methodCall.equals(PsiUtil.skipParenthesizedExprDown(((PsiForStatement)parent).getCondition()))) { + expectedType = PsiType.BOOLEAN.getBoxedType(parent); + } + } + else if (parent instanceof PsiDoWhileStatement) { + if (methodCall.equals(PsiUtil.skipParenthesizedExprDown(((PsiDoWhileStatement)parent).getCondition()))) { + expectedType = PsiType.BOOLEAN.getBoxedType(parent); + } + } else if (parent instanceof PsiReturnStatement) { final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class); if (lambdaExpression != null) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/BooleanInferenceFromIfCondition.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/BooleanInferenceFromIfCondition.java new file mode 100644 index 000000000000..44fbeef42671 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/BooleanInferenceFromIfCondition.java @@ -0,0 +1,12 @@ +public class Main { + public T getAttribute() {return null;} + public T getAttribute(T def) {return null;} + + { + if (getAttribute()) {} + + while (getAttribute()) {} + do {} while (getAttribute()); + for(int i = 0; getAttribute(); i++); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java index b5a544a47410..a7ead1667167 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -208,6 +208,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); } + public void testBooleanInferenceFromIfCondition() throws Exception { + doTest5(false); + } + public void testJavaUtilCollections_NoVerify() throws Exception { PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); assertNotNull(collectionsClass);