infer Boolean in if(runReadAction(new Computab<caret>)){}

This commit is contained in:
peter
2011-08-16 19:54:55 +02:00
parent c2373aff91
commit 440204554c
4 changed files with 50 additions and 2 deletions
@@ -15,6 +15,8 @@
*/
package com.intellij.psi.impl.source.resolve;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.ExpectedTypesProvider;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.RecursionGuard;
@@ -639,6 +641,13 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
final GlobalSearchScope scope = parent.getResolveScope();
PsiType returnType = null;
if (constraint == null) {
if (forCompletion && expectedType == null) {
ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(methodCall, true);
if (expectedTypes.length > 0) {
expectedType = expectedTypes[0].getType();
}
}
if (expectedType == null) {
expectedType = forCompletion ?
PsiType.NULL :
@@ -647,11 +656,15 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
returnType = ((PsiMethod)typeParameter.getOwner()).getReturnType();
constraint = getSubstitutionForTypeParameterConstraint(typeParameter, returnType, expectedType, false, PsiUtil.getLanguageLevel(parent));
constraint =
getSubstitutionForTypeParameterConstraint(typeParameter, returnType, expectedType, false, PsiUtil.getLanguageLevel(parent));
if (constraint != null) {
PsiType guess = constraint.getFirst();
if (guess != null && !guess.equals(PsiType.NULL) && constraint.getSecond() == ConstraintType.SUPERTYPE && guess instanceof PsiIntersectionType) {
if (guess != null &&
!guess.equals(PsiType.NULL) &&
constraint.getSecond() == ConstraintType.SUPERTYPE &&
guess instanceof PsiIntersectionType) {
for (PsiType conjuct : ((PsiIntersectionType)guess).getConjuncts()) {
if (!conjuct.isAssignableFrom(expectedType)) {
return FAILED_INFERENCE;
@@ -0,0 +1,19 @@
interface Computable<T> {
T compute();
}
public class Zoo2 {
<T> T run(Computable<T> computable) {
}
{
if (run(new Computable<Boolean>() {
@Override
public Boolean compute() {
<selection>return null; //To change body of implemented methods use File | Settings | File Templates.</selection>
}
}))
}
}
@@ -0,0 +1,14 @@
interface Computable<T> {
T compute();
}
public class Zoo2 {
<T> T run(Computable<T> computable) {
}
{
if (run(new <caret>))
}
}
@@ -870,6 +870,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
public void testIfConditionExpectedType() throws Exception { doTest(); }
public void testUnboundTypeArgs() throws Exception { doTest(); }
public void testIDEADEV2668() throws Exception {