Refactor: Introduce JetElement#analyzeAndGetResult() utility
This commit is contained in:
@@ -36,6 +36,11 @@ public fun JetElement.analyze(): BindingContext {
|
||||
return getLazyResolveSession().analyze(this)
|
||||
}
|
||||
|
||||
public fun JetElement.analyzeAndGetResult(): AnalysisResult {
|
||||
val resolutionFacade = getLazyResolveSession()
|
||||
return AnalysisResult.success(resolutionFacade.analyze(this), resolutionFacade.findModuleDescriptor(this))
|
||||
}
|
||||
|
||||
public fun JetElement.findModuleDescriptor(): ModuleDescriptor {
|
||||
return getLazyResolveSession().findModuleDescriptor(this)
|
||||
}
|
||||
|
||||
@@ -303,11 +303,11 @@ public class JetPositionManager implements PositionManager {
|
||||
|
||||
private static JetTypeMapper createTypeMapperForLibraryFile(@Nullable PsiElement notPositionedElement, @NotNull JetFile file) {
|
||||
JetElement element = getElementToCreateTypeMapperForLibraryFile(notPositionedElement);
|
||||
ResolutionFacade resolveSession = ResolvePackage.getLazyResolveSession(element);
|
||||
AnalysisResult analysisResult = ResolvePackage.analyzeAndGetResult(element);
|
||||
|
||||
GenerationState state = new GenerationState(file.getProject(), ClassBuilderFactories.THROW_EXCEPTION,
|
||||
resolveSession.findModuleDescriptor(element),
|
||||
resolveSession.analyze(element),
|
||||
analysisResult.getModuleDescriptor(),
|
||||
analysisResult.getBindingContext(),
|
||||
Collections.singletonList(file)
|
||||
);
|
||||
state.beforeCompile();
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalysisResult;
|
||||
import org.jetbrains.jet.di.InjectorForMacros;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
@@ -39,7 +40,6 @@ import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingComponents;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolutionFacade;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.jet.plugin.util.extensionsUtils.ExtensionsUtilsPackage;
|
||||
|
||||
@@ -64,16 +64,16 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
JetExpression contextExpression = findContextExpression(psiFile, context.getStartOffset());
|
||||
if (contextExpression == null) return null;
|
||||
|
||||
ResolutionFacade resolveSession = ResolvePackage.getLazyResolveSession((JetFile) psiFile);
|
||||
AnalysisResult analysisResult = ResolvePackage.analyzeAndGetResult(contextExpression);
|
||||
|
||||
BindingContext bindingContext = resolveSession.analyze(contextExpression);
|
||||
BindingContext bindingContext = analysisResult.getBindingContext();
|
||||
JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, contextExpression);
|
||||
if (scope == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ExpressionTypingComponents components =
|
||||
new InjectorForMacros(project, resolveSession.findModuleDescriptor(contextExpression)).getExpressionTypingComponents();
|
||||
new InjectorForMacros(project, analysisResult.getModuleDescriptor()).getExpressionTypingComponents();
|
||||
|
||||
DataFlowInfo dataFlowInfo = getDataFlowInfo(bindingContext, contextExpression);
|
||||
|
||||
|
||||
+4
-6
@@ -34,8 +34,8 @@ import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalysisResult;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerPackage;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -49,7 +49,6 @@ import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolutionFacade;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils;
|
||||
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences;
|
||||
@@ -124,9 +123,8 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
||||
}
|
||||
}
|
||||
|
||||
ResolutionFacade resolveSession = ResolvePackage.getLazyResolveSession(expression);
|
||||
final BindingContext bindingContext = resolveSession.analyze(expression);
|
||||
ModuleDescriptor moduleDescriptorForElement = resolveSession.findModuleDescriptor(expression);
|
||||
AnalysisResult analysisResult = ResolvePackage.analyzeAndGetResult(expression);
|
||||
final BindingContext bindingContext = analysisResult.getBindingContext();
|
||||
final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); //can be null or error type
|
||||
JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expression);
|
||||
if (scope != null) {
|
||||
@@ -134,7 +132,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
||||
|
||||
ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext());
|
||||
JetType typeNoExpectedType = AnalyzerPackage.computeTypeInfoInContext(
|
||||
expression, scope, bindingTrace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, moduleDescriptorForElement
|
||||
expression, scope, bindingTrace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, analysisResult.getModuleDescriptor()
|
||||
).getType();
|
||||
if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.DEFAULT.equalTypes(expressionType,
|
||||
typeNoExpectedType)) {
|
||||
|
||||
Reference in New Issue
Block a user