From b08482fbca5ed2fd03235c4f083ce85abd9c3e2e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 3 Dec 2015 12:55:00 +0100 Subject: [PATCH] new inference: capture by the spec --- .../graphInference/InferenceSession.java | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 395643413bc8..e54bc203ca79 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -632,18 +632,13 @@ public class InferenceSession { if (!PsiType.VOID.equals(returnType) && returnType != null) { PsiType targetType = getTargetTypeFromParent(context, false); if (targetType != null && !PsiType.VOID.equals(targetType)) { - registerReturnTypeConstraints( - PsiUtil.isRawSubstitutor(method, mySiteSubstitutor) ? returnType : mySiteSubstitutor.substitute(returnType), targetType, true); + registerReturnTypeConstraints(PsiUtil.isRawSubstitutor(method, mySiteSubstitutor) ? returnType : mySiteSubstitutor.substitute(returnType), targetType); } } } } 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) { @@ -659,25 +654,22 @@ public class InferenceSession { final PsiClass psiClass = resolveResult.getElement(); if (psiClass != null) { LOG.assertTrue(returnType instanceof PsiClassType); - PsiClassType substitutedCapture = (PsiClassType)returnType; - if (!toplevel) { - substitutedCapture = (PsiClassType)PsiUtil.captureToplevelWildcards(returnType, myContext); - final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters(); - final InferenceVariable[] copy = initBounds(null, typeParameters); + PsiClassType substitutedCapture = (PsiClassType)PsiUtil.captureToplevelWildcards(returnType, 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]); - } + 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); } + substitutedCapture = elementFactory.createType(psiClass, newParameters); + + myIncorporationPhase.addCapture(copy, substitutedCapture); addConstraint(new TypeCompatibilityConstraint(targetType, substitutedCapture)); } } else {