Utilities for analyzing expressions in given context introduced

This commit is contained in:
Andrey Breslav
2014-04-25 19:02:34 +04:00
parent a708b915db
commit 23205c17c0
4 changed files with 87 additions and 16 deletions
@@ -26,8 +26,8 @@ import com.intellij.psi.util.*;
import kotlin.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzerPackage;
import org.jetbrains.jet.di.InjectorForBodyResolve;
import org.jetbrains.jet.di.InjectorForMacros;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.psi.*;
@@ -229,13 +229,13 @@ public class ResolveElementCache {
JetScope scopeForContextElement = contextForElement.get(BindingContext.RESOLUTION_SCOPE, contextExpression);
if (scopeForContextElement != null) {
DataFlowInfo dataFlowInfoForContextElement = contextForElement.get(BindingContext.EXPRESSION_DATA_FLOW_INFO, contextExpression);
InjectorForMacros injectorForMacros = new InjectorForMacros(codeFragment.getProject(), resolveSession.getModuleDescriptor());
injectorForMacros.getExpressionTypingServices().getType(
AnalyzerPackage.computeTypeInContext(
codeFragment.getExpression(),
scopeForContextElement,
codeFragmentExpression,
TypeUtils.NO_EXPECTED_TYPE,
trace,
dataFlowInfoForContextElement == null ? DataFlowInfo.EMPTY : dataFlowInfoForContextElement,
trace
TypeUtils.NO_EXPECTED_TYPE,
resolveSession.getModuleDescriptor()
);
}
}
@@ -34,9 +34,9 @@ import com.intellij.refactoring.introduce.inplace.OccurrencesChooser;
import kotlin.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.di.InjectorForMacros;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.analyzer.AnalyzerPackage;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
@@ -55,7 +55,10 @@ import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils;
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
import org.jetbrains.jet.plugin.refactoring.*;
import org.jetbrains.jet.plugin.refactoring.JetNameSuggester;
import org.jetbrains.jet.plugin.refactoring.JetNameValidatorImpl;
import org.jetbrains.jet.plugin.refactoring.JetRefactoringBundle;
import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil;
import org.jetbrains.jet.plugin.refactoring.introduce.KotlinIntroduceHandlerBase;
import org.jetbrains.jet.renderer.DescriptorRenderer;
@@ -133,10 +136,9 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
}
ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext());
InjectorForMacros injector = new InjectorForMacros(project, resolveSession.getModuleDescriptor());
JetType typeNoExpectedType = injector.getExpressionTypingServices().getType(scope, expression,
TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo,
bindingTrace);
JetType typeNoExpectedType = AnalyzerPackage.computeTypeInfoInContext(
expression, scope, bindingTrace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, resolveSession.getModuleDescriptor()
).getType();
if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.INSTANCE.equalTypes(expressionType,
typeNoExpectedType)) {
noTypeInference = true;