From 5976a919989923c4898287bf8da159a644c7fbb4 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Sun, 23 Feb 2014 10:58:25 +0400 Subject: [PATCH] Do not inject TopDownAnalysisContext into TopDownAnalyzer --- .../jet/cli/jvm/repl/ReplInterpreter.java | 8 +- .../di/InjectorForTopDownAnalyzerForJvm.java | 5 +- .../jet/di/InjectorForBodyResolve.java | 4 +- .../di/InjectorForTopDownAnalyzerBasic.java | 5 +- .../lang/resolve/TopDownAnalysisContext.java | 11 +- .../jet/lang/resolve/TopDownAnalyzer.java | 101 +++++++++--------- .../di/InjectorForTopDownAnalyzerForJs.java | 5 +- 7 files changed, 67 insertions(+), 72 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java index 81312baf01f..537c915e8c7 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java @@ -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.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) { diff --git a/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJvm.java b/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJvm.java index 2dfaa9324c7..426e3781210 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJvm.java @@ -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); diff --git a/compiler/frontend/src/org/jetbrains/jet/di/InjectorForBodyResolve.java b/compiler/frontend/src/org/jetbrains/jet/di/InjectorForBodyResolve.java index a9858e4ea1f..af4da7dc1b0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/di/InjectorForBodyResolve.java +++ b/compiler/frontend/src/org/jetbrains/jet/di/InjectorForBodyResolve.java @@ -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 diff --git a/compiler/frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerBasic.java b/compiler/frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerBasic.java index 6a9177a8063..d1d685d0611 100644 --- a/compiler/frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerBasic.java +++ b/compiler/frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerBasic.java @@ -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); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java index 812c408dc7a..2358632d54d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java @@ -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"); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java index ead064b3196..a678d68d7fe 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java @@ -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 declarations) { -// context.enableDebugOutput(); - context.debug("Enter"); + @NotNull TopDownAnalysisContext c, + @NotNull JetScope outerScope, + @NotNull PackageLikeBuilder owner, + @NotNull Collection 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 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.singletonList(object)); + @Override + public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) { + return ClassObjectStatus.NOT_ALLOWED; + } + }, + Collections.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(); } diff --git a/js/js.translator/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJs.java b/js/js.translator/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJs.java index bad7a1cc2f4..fd0101f34e5 100644 --- a/js/js.translator/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJs.java +++ b/js/js.translator/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJs.java @@ -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);