mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new inference: substitute captured wildcards with new inference variables
This commit is contained in:
+24
-5
@@ -634,13 +634,17 @@ public class InferenceSession {
|
||||
PsiType targetType = getTargetTypeFromParent(context, false);
|
||||
if (targetType != null && !PsiType.VOID.equals(targetType)) {
|
||||
registerReturnTypeConstraints(
|
||||
PsiUtil.isRawSubstitutor(method, mySiteSubstitutor) ? returnType : mySiteSubstitutor.substitute(returnType), targetType);
|
||||
PsiUtil.isRawSubstitutor(method, mySiteSubstitutor) ? returnType : mySiteSubstitutor.substitute(returnType), targetType, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerReturnTypeConstraints(PsiType returnType, PsiType targetType) {
|
||||
registerReturnTypeConstraints(returnType, targetType, false);
|
||||
}
|
||||
|
||||
public void registerReturnTypeConstraints(PsiType returnType, PsiType targetType, boolean toplevel) {
|
||||
returnType = substituteWithInferenceVariables(returnType);
|
||||
final InferenceVariable inferenceVariable = shouldResolveAndInstantiate(returnType, targetType);
|
||||
if (inferenceVariable != null) {
|
||||
@@ -656,10 +660,25 @@ public class InferenceSession {
|
||||
final PsiClass psiClass = resolveResult.getElement();
|
||||
if (psiClass != null) {
|
||||
LOG.assertTrue(returnType instanceof PsiClassType);
|
||||
final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters();
|
||||
InferenceVariable[] copy = initBounds(null, typeParameters);
|
||||
final PsiType substitutedCapture = PsiImplUtil.normalizeWildcardTypeByPosition(returnType, (PsiExpression)myContext);
|
||||
myIncorporationPhase.addCapture(copy, (PsiClassType)substituteWithInferenceVariables(returnType));
|
||||
PsiClassType substitutedCapture = (PsiClassType)returnType;
|
||||
if (!toplevel) {
|
||||
substitutedCapture = (PsiClassType)PsiImplUtil.normalizeWildcardTypeByPosition(returnType, (PsiExpression)myContext);
|
||||
final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters();
|
||||
final InferenceVariable[] copy = initBounds(null, typeParameters);
|
||||
|
||||
final PsiType[] parameters = substitutedCapture.getParameters();
|
||||
final PsiType[] newParameters = new PsiType[parameters.length];
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myManager.getProject());
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
newParameters[i] = parameters[i];
|
||||
if (parameters[i] instanceof PsiCapturedWildcardType) {
|
||||
newParameters[i] = elementFactory.createType(copy[i]);
|
||||
}
|
||||
}
|
||||
substitutedCapture = elementFactory.createType(psiClass, newParameters);
|
||||
|
||||
myIncorporationPhase.addCapture(copy, substitutedCapture);
|
||||
}
|
||||
addConstraint(new TypeCompatibilityConstraint(targetType, substitutedCapture));
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user