mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
+5
@@ -71,4 +71,9 @@ public class CompletionParameterTypeInferencePolicy extends ProcessCandidatePara
|
||||
public boolean inferLowerBoundForFreshVariables() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestForBoxingExplicitly() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -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 =
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ class Foo<T> {
|
||||
}
|
||||
|
||||
static {
|
||||
new Foo<Integer>().to(Bar.<Integer>method(<caret>))
|
||||
new Foo<Integer>().to(Bar.method(<caret>))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user