completion for older java versions: allow boxing even to specify explicit type arguments later when needed

fixing SmartTypeCompletionTest#testIfConditionExpectedType, consequence of changing expected type for condition from boxed to primitive
This commit is contained in:
Anna.Kozlova
2018-12-19 14:53:41 +01:00
parent 4af60ad9c5
commit a72e208a09
4 changed files with 21 additions and 1 deletions
@@ -71,4 +71,9 @@ public class CompletionParameterTypeInferencePolicy extends ProcessCandidatePara
public boolean inferLowerBoundForFreshVariables() {
return true;
}
@Override
public boolean requestForBoxingExplicitly() {
return true;
}
}
@@ -51,4 +51,15 @@ public abstract class ParameterTypeInferencePolicy {
public boolean inferLowerBoundForFreshVariables() {
return false;
}
/**
* Workaround for inference < 1.8.
*
* Boxed type is used for inference as it may be specified as type argument explicitly later for completion
* {@link com.intellij.codeInsight.completion.JavaMethodCallElement#setInferenceSubstitutorFromExpectedType(com.intellij.psi.PsiElement, com.intellij.psi.PsiType)},
* but should not be used for normal inference due to javac bug
*/
public boolean requestForBoxingExplicitly() {
return false;
}
}
@@ -685,6 +685,10 @@ public class PsiOldInferenceHelper implements PsiInferenceHelper {
expectedType = methodCall instanceof PsiCallExpression ? policy.getDefaultExpectedType((PsiCallExpression)methodCall) : null;
}
if (policy.requestForBoxingExplicitly() && TypeConversionUtil.isPrimitiveAndNotNull(expectedType)) {
expectedType = ((PsiPrimitiveType)expectedType).getBoxedType(typeParameter);
}
returnType = ((PsiMethod)typeParameter.getOwner()).getReturnType();
constraint =
@@ -6,7 +6,7 @@ class Foo<T> {
}
static {
new Foo<Integer>().to(Bar.<Integer>method(<caret>))
new Foo<Integer>().to(Bar.method(<caret>))
}
}