Do not inject TopDownAnalysisContext into TopDownAnalyzer
This commit is contained in:
@@ -91,6 +91,8 @@ public class ReplInterpreter {
|
||||
@NotNull
|
||||
private final InjectorForTopDownAnalyzerForJvm injector;
|
||||
@NotNull
|
||||
private final TopDownAnalysisContext topDownAnalysisContext;
|
||||
@NotNull
|
||||
private final JetCoreEnvironment jetCoreEnvironment;
|
||||
@NotNull
|
||||
private final BindingTraceContext trace;
|
||||
@@ -110,6 +112,7 @@ public class ReplInterpreter {
|
||||
true,
|
||||
Collections.<AnalyzerScriptParameter>emptyList());
|
||||
injector = new InjectorForTopDownAnalyzerForJvm(project, topDownAnalysisParameters, trace, module);
|
||||
topDownAnalysisContext = new TopDownAnalysisContext(topDownAnalysisParameters);
|
||||
module.addFragmentProvider(SOURCES, injector.getTopDownAnalyzer().getPackageFragmentProvider());
|
||||
module.addFragmentProvider(BUILT_INS, KotlinBuiltIns.getInstance().getBuiltInsModule().getPackageFragmentProvider());
|
||||
module.addFragmentProvider(BINARIES, injector.getJavaDescriptorResolver().getPackageFragmentProvider());
|
||||
@@ -227,7 +230,7 @@ public class ReplInterpreter {
|
||||
return LineResult.error(errorCollector.getString());
|
||||
}
|
||||
|
||||
injector.getTopDownAnalyzer().prepareForTheNextReplLine();
|
||||
injector.getTopDownAnalyzer().prepareForTheNextReplLine(topDownAnalysisContext);
|
||||
trace.clearDiagnostics();
|
||||
|
||||
psiFile.getScript().putUserData(ScriptHeaderResolver.PRIORITY_KEY, lineNumber);
|
||||
@@ -307,7 +310,8 @@ public class ReplInterpreter {
|
||||
|
||||
// dummy builder is used because "root" is module descriptor,
|
||||
// packages added to module explicitly in
|
||||
injector.getTopDownAnalyzer().doProcess(scope, new PackageLikeBuilderDummy(), Collections.singletonList(psiFile));
|
||||
injector.getTopDownAnalyzer().doProcess(topDownAnalysisContext,
|
||||
scope, new PackageLikeBuilderDummy(), Collections.singletonList(psiFile));
|
||||
|
||||
boolean hasErrors = AnalyzerWithCompilerReport.reportDiagnostics(trace.getBindingContext(), messageCollector);
|
||||
if (hasErrors) {
|
||||
|
||||
+1
-4
@@ -133,7 +133,7 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
this.platformToKotlinClassMap = moduleDescriptor.getPlatformToKotlinClassMap();
|
||||
this.topDownAnalyzer = new TopDownAnalyzer();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext(topDownAnalysisParameters);
|
||||
this.mutablePackageFragmentProvider = new MutablePackageFragmentProvider(getModuleDescriptor());
|
||||
this.javaClassFinder = new JavaClassFinderImpl();
|
||||
this.virtualFileFinder = org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder.SERVICE.getInstance(project);
|
||||
@@ -176,7 +176,6 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.annotationDescriptorDeserializer = new AnnotationDescriptorDeserializer(storageManager);
|
||||
|
||||
this.topDownAnalyzer.setBodyResolver(bodyResolver);
|
||||
this.topDownAnalyzer.setContext(topDownAnalysisContext);
|
||||
this.topDownAnalyzer.setDeclarationResolver(declarationResolver);
|
||||
this.topDownAnalyzer.setModuleDescriptor(moduleDescriptor);
|
||||
this.topDownAnalyzer.setOverloadResolver(overloadResolver);
|
||||
@@ -186,8 +185,6 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.topDownAnalyzer.setTrace(bindingTrace);
|
||||
this.topDownAnalyzer.setTypeHierarchyResolver(typeHierarchyResolver);
|
||||
|
||||
this.topDownAnalysisContext.setTopDownAnalysisParameters(topDownAnalysisParameters);
|
||||
|
||||
javaClassFinder.setProject(project);
|
||||
|
||||
traceBasedExternalSignatureResolver.setExternalAnnotationResolver(psiBasedExternalAnnotationResolver);
|
||||
|
||||
@@ -116,7 +116,7 @@ public class InjectorForBodyResolve {
|
||||
this.declarationsChecker = new DeclarationsChecker();
|
||||
this.functionAnalyzerExtension = new FunctionAnalyzerExtension();
|
||||
this.scriptBodyResolver = new ScriptBodyResolver();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext(topDownAnalysisParameters);
|
||||
|
||||
this.bodyResolver.setAnnotationResolver(annotationResolver);
|
||||
this.bodyResolver.setCallResolver(callResolver);
|
||||
@@ -188,8 +188,6 @@ public class InjectorForBodyResolve {
|
||||
scriptBodyResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
scriptBodyResolver.setTrace(bindingTrace);
|
||||
|
||||
topDownAnalysisContext.setTopDownAnalysisParameters(topDownAnalysisParameters);
|
||||
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
||||
@@ -111,7 +111,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
this.platformToKotlinClassMap = moduleDescriptor.getPlatformToKotlinClassMap();
|
||||
this.topDownAnalyzer = new TopDownAnalyzer();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext(topDownAnalysisParameters);
|
||||
this.mutablePackageFragmentProvider = new MutablePackageFragmentProvider(getModuleDescriptor());
|
||||
this.dependencyClassByQualifiedNameResolverDummy = new DependencyClassByQualifiedNameResolverDummyImpl();
|
||||
this.bodyResolver = new BodyResolver();
|
||||
@@ -143,7 +143,6 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
this.typeHierarchyResolver = new TypeHierarchyResolver();
|
||||
|
||||
this.topDownAnalyzer.setBodyResolver(bodyResolver);
|
||||
this.topDownAnalyzer.setContext(topDownAnalysisContext);
|
||||
this.topDownAnalyzer.setDeclarationResolver(declarationResolver);
|
||||
this.topDownAnalyzer.setModuleDescriptor(moduleDescriptor);
|
||||
this.topDownAnalyzer.setOverloadResolver(overloadResolver);
|
||||
@@ -153,8 +152,6 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
this.topDownAnalyzer.setTrace(bindingTrace);
|
||||
this.topDownAnalyzer.setTypeHierarchyResolver(typeHierarchyResolver);
|
||||
|
||||
this.topDownAnalysisContext.setTopDownAnalysisParameters(topDownAnalysisParameters);
|
||||
|
||||
bodyResolver.setAnnotationResolver(annotationResolver);
|
||||
bodyResolver.setCallResolver(callResolver);
|
||||
bodyResolver.setControlFlowAnalyzer(controlFlowAnalyzer);
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.storage.ExceptionTracker;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -64,12 +63,9 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
|
||||
|
||||
private StringBuilder debugOutput;
|
||||
|
||||
|
||||
private TopDownAnalysisParameters topDownAnalysisParameters;
|
||||
|
||||
@Override
|
||||
@Inject
|
||||
public void setTopDownAnalysisParameters(TopDownAnalysisParameters topDownAnalysisParameters) {
|
||||
public TopDownAnalysisContext(@NotNull TopDownAnalysisParameters topDownAnalysisParameters) {
|
||||
this.topDownAnalysisParameters = topDownAnalysisParameters;
|
||||
}
|
||||
|
||||
@@ -77,6 +73,11 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
|
||||
return topDownAnalysisParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopDownAnalysisParameters(TopDownAnalysisParameters topDownAnalysisParameters) {
|
||||
this.topDownAnalysisParameters = topDownAnalysisParameters;
|
||||
}
|
||||
|
||||
public void debug(Object message) {
|
||||
if (debugOutput != null) {
|
||||
debugOutput.append(message).append("\n");
|
||||
|
||||
@@ -55,8 +55,6 @@ public class TopDownAnalyzer {
|
||||
@NotNull
|
||||
private TopDownAnalysisParameters topDownAnalysisParameters;
|
||||
@NotNull
|
||||
private TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private BindingTrace trace;
|
||||
@NotNull
|
||||
private ModuleDescriptor moduleDescriptor;
|
||||
@@ -95,11 +93,6 @@ public class TopDownAnalyzer {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setModuleDescriptor(@NotNull ModuleDescriptor moduleDescriptor) {
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
@@ -115,37 +108,37 @@ public class TopDownAnalyzer {
|
||||
this.bodyResolver = bodyResolver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void doProcess(
|
||||
JetScope outerScope,
|
||||
PackageLikeBuilder owner,
|
||||
Collection<? extends PsiElement> declarations) {
|
||||
// context.enableDebugOutput();
|
||||
context.debug("Enter");
|
||||
@NotNull TopDownAnalysisContext c,
|
||||
@NotNull JetScope outerScope,
|
||||
@NotNull PackageLikeBuilder owner,
|
||||
@NotNull Collection<? extends PsiElement> declarations
|
||||
) {
|
||||
// c.enableDebugOutput();
|
||||
c.debug("Enter");
|
||||
|
||||
typeHierarchyResolver.process(outerScope, owner, declarations);
|
||||
declarationResolver.process(outerScope);
|
||||
overrideResolver.process();
|
||||
|
||||
lockScopes();
|
||||
lockScopes(c);
|
||||
|
||||
overloadResolver.process();
|
||||
|
||||
if (!topDownAnalysisParameters.isAnalyzingBootstrapLibrary()) {
|
||||
bodyResolver.resolveBodies(context);
|
||||
bodyResolver.resolveBodies(c);
|
||||
}
|
||||
|
||||
context.debug("Exit");
|
||||
context.printDebugOutput(System.out);
|
||||
c.debug("Exit");
|
||||
c.printDebugOutput(System.out);
|
||||
}
|
||||
|
||||
private void lockScopes() {
|
||||
for (ClassDescriptorWithResolutionScopes mutableClassDescriptor : context.getClasses().values()) {
|
||||
private void lockScopes(@NotNull TopDownAnalysisContext c) {
|
||||
for (ClassDescriptorWithResolutionScopes mutableClassDescriptor : c.getClasses().values()) {
|
||||
((MutableClassDescriptor) mutableClassDescriptor).lockScopes();
|
||||
}
|
||||
Set<FqName> scriptFqNames = Sets.newHashSet();
|
||||
for (JetFile file : context.getFileScopes().keySet()) {
|
||||
for (JetFile file : c.getFileScopes().keySet()) {
|
||||
if (file.isScript()) {
|
||||
scriptFqNames.add(JetPsiUtil.getFQName(file));
|
||||
}
|
||||
@@ -183,38 +176,44 @@ public class TopDownAnalyzer {
|
||||
object.getProject(), topDownAnalysisParameters, new ObservableBindingTrace(context.trace),
|
||||
moduleDescriptor);
|
||||
|
||||
injector.getTopDownAnalysisContext().setOuterDataFlowInfo(context.dataFlowInfo);
|
||||
TopDownAnalysisContext c = new TopDownAnalysisContext(topDownAnalysisParameters);
|
||||
c.setOuterDataFlowInfo(context.dataFlowInfo);
|
||||
|
||||
injector.getTopDownAnalyzer().doProcess(context.scope, new PackageLikeBuilder() {
|
||||
injector.getTopDownAnalyzer().doProcess(
|
||||
c,
|
||||
context.scope,
|
||||
new PackageLikeBuilder() {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOwnerForChildren() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
if (scope != null) {
|
||||
scope.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
|
||||
if (scope != null) {
|
||||
scope.addClassifierDescriptor(classDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
@Override
|
||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
return ClassObjectStatus.NOT_ALLOWED;
|
||||
}
|
||||
}, Collections.<PsiElement>singletonList(object));
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
return ClassObjectStatus.NOT_ALLOWED;
|
||||
}
|
||||
},
|
||||
Collections.<PsiElement>singletonList(object)
|
||||
);
|
||||
}
|
||||
|
||||
public void analyzeFiles(
|
||||
@@ -227,13 +226,15 @@ public class TopDownAnalyzer {
|
||||
|
||||
// dummy builder is used because "root" is module descriptor,
|
||||
// packages added to module explicitly in
|
||||
doProcess(JetModuleUtil.getSubpackagesOfRootScope(moduleDescriptor), new PackageLikeBuilderDummy(), files);
|
||||
|
||||
doProcess(new TopDownAnalysisContext(topDownAnalysisParameters), JetModuleUtil.getSubpackagesOfRootScope(moduleDescriptor),
|
||||
new PackageLikeBuilderDummy(), files);
|
||||
}
|
||||
|
||||
|
||||
public void prepareForTheNextReplLine() {
|
||||
context.getScriptScopes().clear();
|
||||
context.getScripts().clear();
|
||||
public void prepareForTheNextReplLine(@NotNull TopDownAnalysisContext c) {
|
||||
c.getScriptScopes().clear();
|
||||
c.getScripts().clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public class InjectorForTopDownAnalyzerForJs {
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
this.platformToKotlinClassMap = moduleDescriptor.getPlatformToKotlinClassMap();
|
||||
this.topDownAnalyzer = new TopDownAnalyzer();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext();
|
||||
this.topDownAnalysisContext = new TopDownAnalysisContext(topDownAnalysisParameters);
|
||||
this.mutablePackageFragmentProvider = new MutablePackageFragmentProvider(getModuleDescriptor());
|
||||
this.dependencyClassByQualifiedNameResolverDummy = new DependencyClassByQualifiedNameResolverDummyImpl();
|
||||
this.bodyResolver = new BodyResolver();
|
||||
@@ -143,7 +143,6 @@ public class InjectorForTopDownAnalyzerForJs {
|
||||
this.typeHierarchyResolver = new TypeHierarchyResolver();
|
||||
|
||||
this.topDownAnalyzer.setBodyResolver(bodyResolver);
|
||||
this.topDownAnalyzer.setContext(topDownAnalysisContext);
|
||||
this.topDownAnalyzer.setDeclarationResolver(declarationResolver);
|
||||
this.topDownAnalyzer.setModuleDescriptor(moduleDescriptor);
|
||||
this.topDownAnalyzer.setOverloadResolver(overloadResolver);
|
||||
@@ -153,8 +152,6 @@ public class InjectorForTopDownAnalyzerForJs {
|
||||
this.topDownAnalyzer.setTrace(bindingTrace);
|
||||
this.topDownAnalyzer.setTypeHierarchyResolver(typeHierarchyResolver);
|
||||
|
||||
this.topDownAnalysisContext.setTopDownAnalysisParameters(topDownAnalysisParameters);
|
||||
|
||||
bodyResolver.setAnnotationResolver(annotationResolver);
|
||||
bodyResolver.setCallResolver(callResolver);
|
||||
bodyResolver.setControlFlowAnalyzer(controlFlowAnalyzer);
|
||||
|
||||
Reference in New Issue
Block a user