[java] make InferenceSession#propagateVariables accept InferenceSession to propagate from

This commit is contained in:
Daniil Ovchinnikov
2018-11-07 16:13:09 +03:00
parent 8e5e169345
commit d3b39580fa
4 changed files with 9 additions and 23 deletions
@@ -1922,9 +1922,9 @@ public class InferenceSession {
return myContext;
}
public void propagateVariables(Collection<InferenceVariable> variables, PsiSubstitutor restoreNamesSubstitution) {
myInferenceVariables.addAll(variables);
myRestoreNameSubstitution = myRestoreNameSubstitution.putAll(restoreNamesSubstitution);
public final void propagateVariables(@NotNull InferenceSession from) {
myInferenceVariables.addAll(from.getInferenceVariables());
myRestoreNameSubstitution = myRestoreNameSubstitution.putAll(from.getRestoreNameSubstitution());
}
public PsiType substituteWithInferenceVariables(@Nullable PsiType type) {
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.psi.impl.source.resolve.graphInference;
import com.intellij.openapi.diagnostic.Logger;
@@ -55,7 +41,7 @@ public class InferenceSessionContainer {
ExpressionCompatibilityConstraint.reduceExpressionCompatibilityConstraint(session, returnExpression, returnType, false);
if (inferenceSession != null && inferenceSession != session) {
registerNestedSession(inferenceSession);
session.propagateVariables(inferenceSession.getInferenceVariables(), inferenceSession.getRestoreNameSubstitution());
session.propagateVariables(inferenceSession);
}
}
}
@@ -89,7 +89,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
}
if (callSession != session) {
session.getInferenceSessionContainer().registerNestedSession(callSession);
session.propagateVariables(callSession.getInferenceVariables(), callSession.getRestoreNameSubstitution());
session.propagateVariables(callSession);
for (Pair<InferenceVariable[], PsiClassType> pair : callSession.myIncorporationPhase.getCaptures()) {
session.myIncorporationPhase.addCapture(pair.first, pair.second);
}
@@ -149,7 +149,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
if (typeParams != null) {
PsiSubstitutor siteSubstitutor = InferenceSession.chooseSiteSubstitutor(candidateProperties, resolveResult, method);
final InferenceSession callSession = new InferenceSession(typeParams, siteSubstitutor, expression.getManager(), expression);
callSession.propagateVariables(session.getInferenceVariables(), session.getRestoreNameSubstitution());
callSession.propagateVariables(session);
if (method != null) {
final PsiExpression[] args = argumentList.getExpressions();
final PsiParameter[] parameters = method.getParameterList().getParameters();
@@ -20,7 +20,7 @@ class ReferenceExpressionConstraint(private val callRef: GrReferenceExpression,
val typeParameters = it.method.typeParameters
val nestedSession = GroovyInferenceSession(typeParameters, it.siteSubstitutor, callRef, emptyList(), session.skipClosureBlock)
session.myNestedSessions[callRef] = nestedSession
nestedSession.propagateVariables(session.inferenceVariables, session.restoreNameSubstitution)
nestedSession.propagateVariables(session)
nestedSession.addConstraint(MethodCallConstraint(callRef, it))
nestedSession.repeatInferencePhases()
@@ -31,7 +31,7 @@ class ReferenceExpressionConstraint(private val callRef: GrReferenceExpression,
nestedSession.repeatInferencePhases()
}
session.propagateVariables(nestedSession.inferenceVariables, nestedSession.restoreNameSubstitution)
session.propagateVariables(nestedSession)
for (pair in nestedSession.myIncorporationPhase.captures) {
session.myIncorporationPhase.addCapture(pair.first, pair.second)
}