Refactor: TopDownAnalysisParameters doesn't implement GlobalContext

This commit is contained in:
Pavel V. Talanov
2015-05-15 13:42:29 +03:00
parent f18b9caa8d
commit f9b6c25498
12 changed files with 42 additions and 104 deletions
@@ -113,8 +113,6 @@ public class ReplInterpreter {
GlobalContextImpl context = ContextPackage.GlobalContext();
TopDownAnalysisParameters topDownAnalysisParameters = TopDownAnalysisParameters.create(
context.getStorageManager(),
context.getExceptionTracker(),
false,
true
);
@@ -131,7 +129,7 @@ public class ReplInterpreter {
InjectorForReplWithJava injector = new InjectorForReplWithJava(
project,
topDownAnalysisParameters,
context,
trace,
module,
scriptDeclarationFactory,
@@ -355,7 +353,7 @@ public class ReplInterpreter {
@Nullable
private ScriptDescriptor doAnalyze(@NotNull JetFile psiFile, @NotNull MessageCollector messageCollector) {
scriptDeclarationFactory.setDelegateFactory(
new FileBasedDeclarationProviderFactory(topDownAnalysisContext.getStorageManager(), Collections.singletonList(psiFile)));
new FileBasedDeclarationProviderFactory(resolveSession.getStorageManager(), Collections.singletonList(psiFile)));
TopDownAnalysisContext context = topDownAnalyzer.analyzeDeclarations(
topDownAnalysisContext.getTopDownAnalysisParameters(),
@@ -72,12 +72,13 @@ public enum TopDownAnalyzerFacadeForJVM {
@NotNull
public static AnalysisResult analyzeFilesWithJavaIntegrationNoIncremental(
@NotNull Project project,
@NotNull GlobalContext globalContext,
@NotNull Collection<JetFile> files,
@NotNull BindingTrace trace,
@NotNull TopDownAnalysisParameters topDownAnalysisParameters,
@NotNull ModuleDescriptorImpl module
) {
return analyzeFilesWithJavaIntegration(project, files, trace, topDownAnalysisParameters, module, null, null);
return analyzeFilesWithJavaIntegration(project, globalContext, files, trace, topDownAnalysisParameters, module, null, null);
}
@NotNull
@@ -91,20 +92,19 @@ public enum TopDownAnalyzerFacadeForJVM {
@Nullable IncrementalCacheProvider incrementalCacheProvider
) {
TopDownAnalysisParameters topDownAnalysisParameters = TopDownAnalysisParameters.create(
globalContext.getStorageManager(),
globalContext.getExceptionTracker(),
false,
false
);
return analyzeFilesWithJavaIntegration(
project, files, trace, topDownAnalysisParameters, module,
project, globalContext, files, trace, topDownAnalysisParameters, module,
moduleIds, incrementalCacheProvider);
}
@NotNull
private static AnalysisResult analyzeFilesWithJavaIntegration(
Project project,
@NotNull GlobalContext globalContext,
Collection<JetFile> files,
BindingTrace trace,
TopDownAnalysisParameters topDownAnalysisParameters,
@@ -115,11 +115,11 @@ public enum TopDownAnalyzerFacadeForJVM {
List<JetFile> allFiles = JvmAnalyzerFacade.getAllFilesToAnalyze(project, null, files);
FileBasedDeclarationProviderFactory providerFactory =
new FileBasedDeclarationProviderFactory(topDownAnalysisParameters.getStorageManager(), allFiles);
new FileBasedDeclarationProviderFactory(globalContext.getStorageManager(), allFiles);
InjectorForTopDownAnalyzerForJvm injector = new InjectorForTopDownAnalyzerForJvm(
project,
topDownAnalysisParameters,
globalContext,
trace,
module,
providerFactory,
@@ -135,7 +135,7 @@ public enum TopDownAnalyzerFacadeForJVM {
additionalProviders.add(
new IncrementalPackageFragmentProvider(
files, module, topDownAnalysisParameters.getStorageManager(),
files, module, globalContext.getStorageManager(),
injector.getDeserializationComponentsForJava().getComponents(),
incrementalCache, moduleId
)
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope;
import java.util.Collection;
import java.util.Map;
public interface BodiesResolveContext extends GlobalContext {
public interface BodiesResolveContext {
@ReadOnly
Collection<JetFile> getFiles();
@@ -101,18 +101,6 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
return secondaryConstructors;
}
@NotNull
@Override
public StorageManager getStorageManager() {
return topDownAnalysisParameters.getStorageManager();
}
@NotNull
@Override
public ExceptionTracker getExceptionTracker() {
return topDownAnalysisParameters.getExceptionTracker();
}
@Override
public Collection<JetFile> getFiles() {
return files;
@@ -27,59 +27,35 @@ import org.jetbrains.kotlin.storage.StorageManager;
/**
* Various junk that cannot be placed into context (yet).
*/
public class TopDownAnalysisParameters extends TypeLazinessToken implements GlobalContext {
public class TopDownAnalysisParameters extends TypeLazinessToken {
@NotNull
public static TopDownAnalysisParameters create(
@NotNull StorageManager storageManager,
@NotNull ExceptionTracker exceptionTracker,
boolean analyzingBootstrapLibrary,
boolean declaredLocally
) {
return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzingBootstrapLibrary,
declaredLocally, true);
return new TopDownAnalysisParameters(analyzingBootstrapLibrary, declaredLocally, true);
}
@NotNull
public static TopDownAnalysisParameters createForLocalDeclarations(
@NotNull StorageManager storageManager,
@NotNull ExceptionTracker exceptionTracker
) {
return new TopDownAnalysisParameters(storageManager, exceptionTracker, false, true, false);
public static TopDownAnalysisParameters createForLocalDeclarations() {
return new TopDownAnalysisParameters(false, true, false);
}
@NotNull private final StorageManager storageManager;
@NotNull private final ExceptionTracker exceptionTracker;
private final boolean analyzingBootstrapLibrary;
private final boolean declaredLocally;
private final boolean lazyTopDownAnalysis;
private TopDownAnalysisParameters(
@NotNull StorageManager storageManager,
@NotNull ExceptionTracker exceptionTracker,
boolean analyzingBootstrapLibrary,
boolean declaredLocally,
boolean lazyTopDownAnalysis
) {
this.storageManager = storageManager;
this.exceptionTracker = exceptionTracker;
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
this.declaredLocally = declaredLocally;
this.lazyTopDownAnalysis = lazyTopDownAnalysis;
}
@Override
@NotNull
public StorageManager getStorageManager() {
return storageManager;
}
@Override
@NotNull
public ExceptionTracker getExceptionTracker() {
return exceptionTracker;
}
public boolean isAnalyzingBootstrapLibrary() {
return analyzingBootstrapLibrary;
}
@@ -62,7 +62,7 @@ public class LocalClassifierAnalyzer(
additionalCheckerProvider: AdditionalCheckerProvider,
dynamicTypesSettings: DynamicTypesSettings
) {
val topDownAnalysisParameters = TopDownAnalysisParameters.create(globalContext.storageManager, globalContext.exceptionTracker, false, true)
val topDownAnalysisParameters = TopDownAnalysisParameters.create(false, true)
val moduleDescriptor = DescriptorUtils.getContainingModule(containingDeclaration)
val injector = InjectorForLazyLocalClassifierAnalyzer(
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
import org.jetbrains.kotlin.config.CompilerConfiguration;
import org.jetbrains.kotlin.context.ContextPackage;
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
@@ -37,8 +38,6 @@ import org.jetbrains.kotlin.resolve.TopDownAnalysisParameters;
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor;
import org.jetbrains.kotlin.storage.ExceptionTracker;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
@@ -152,14 +151,13 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
ModuleDescriptorImpl module = TopDownAnalyzerFacadeForJVM.createSealedJavaModule();
TopDownAnalysisParameters parameters = TopDownAnalysisParameters.create(
new LockBasedStorageManager(),
new ExceptionTracker(), // dummy
false,
false
);
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental(
environment.getProject(),
ContextPackage.GlobalContext(),
environment.getSourceFiles(),
trace,
parameters,
@@ -56,14 +56,8 @@ public class LazyResolveTestUtil {
public static ModuleDescriptor resolve(@NotNull Project project, @NotNull BindingTrace trace, @NotNull List<JetFile> sourceFiles) {
ModuleDescriptorImpl module = TopDownAnalyzerFacadeForJVM.createSealedJavaModule();
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
TopDownAnalysisParameters params = TopDownAnalysisParameters.create(
globalContext.getStorageManager(),
globalContext.getExceptionTracker(),
false, false
);
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental(project, sourceFiles, trace, params, module);
TopDownAnalysisParameters params = TopDownAnalysisParameters.create(false, false);
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental(project, ContextPackage.GlobalContext(), sourceFiles, trace, params, module);
return module;
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.serialization
import com.google.common.base.Predicates
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
@@ -27,7 +26,6 @@ import org.jetbrains.kotlin.di.InjectorForTopDownAnalyzerForJvm
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.structure.reflect.classId
import org.jetbrains.kotlin.resolve.TopDownAnalysisParameters
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
import org.jetbrains.kotlin.test.*
@@ -57,13 +55,10 @@ public abstract class AbstractLocalClassProtoTest : TestCaseWithTmpdir() {
)
val module = TopDownAnalyzerFacadeForJVM.createSealedJavaModule()
val globalContext = GlobalContext()
val params = TopDownAnalysisParameters.create(
globalContext.storageManager, globalContext.exceptionTracker, false, false
)
val providerFactory = FileBasedDeclarationProviderFactory(globalContext.storageManager, emptyList())
val injector = InjectorForTopDownAnalyzerForJvm(
environment.project, params, CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), module,
environment.project, globalContext, CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), module,
providerFactory, GlobalSearchScope.allScope(environment.project)
)
module.initialize(injector.getJavaDescriptorResolver().packageFragmentProvider)
@@ -19,11 +19,11 @@ package org.jetbrains.kotlin.resolve.lazy
import com.google.common.base.Function
import com.google.common.base.Functions
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.analyzer.*
import org.jetbrains.kotlin.analyzer.computeTypeInContext
import org.jetbrains.kotlin.cfg.JetFlowInformationProvider
import org.jetbrains.kotlin.context.GlobalContextImpl
import org.jetbrains.kotlin.context.SimpleGlobalContext
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.di.InjectorForBodyResolve
import org.jetbrains.kotlin.name.FqName
@@ -32,18 +32,14 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.storage.ExceptionTracker
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.TypeUtils
import java.util.Collections
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
public abstract class ElementResolver protected(
@@ -298,7 +294,7 @@ public abstract class ElementResolver protected(
ForceResolveUtil.forceResolveAllContents(descriptor.getTypeConstructor().getSupertypes())
val bodyResolver = createBodyResolver(resolveSession, trace, file, StatementFilter.NONE)
bodyResolver.resolveDelegationSpecifierList(createEmptyContext(resolveSession),
bodyResolver.resolveDelegationSpecifierList(createEmptyContext(),
classOrObject,
descriptor,
descriptor.getUnsubstitutedPrimaryConstructor(),
@@ -309,7 +305,7 @@ public abstract class ElementResolver protected(
private fun propertyAdditionalResolve(resolveSession: ResolveSession, jetProperty: JetProperty, trace: BindingTrace, file: JetFile, statementFilter: StatementFilter) {
val propertyResolutionScope = resolveSession.getScopeProvider().getResolutionScopeForDeclaration(jetProperty)
val bodyResolveContext = BodyResolveContextForLazy(createParameters(resolveSession), object : Function<JetDeclaration, JetScope> {
val bodyResolveContext = BodyResolveContextForLazy(TopDownAnalysisParameters.createForLocalDeclarations(), object : Function<JetDeclaration, JetScope> {
override fun apply(declaration: JetDeclaration?): JetScope? {
assert(declaration!!.getParent() == jetProperty) { "Must be called only for property accessors, but called for " + declaration }
return resolveSession.getScopeProvider().getResolutionScopeForDeclaration(declaration)
@@ -342,7 +338,7 @@ public abstract class ElementResolver protected(
ForceResolveUtil.forceResolveAllContents(functionDescriptor)
val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter)
bodyResolver.resolveFunctionBody(createEmptyContext(resolveSession), trace, namedFunction, functionDescriptor, scope)
bodyResolver.resolveFunctionBody(createEmptyContext(), trace, namedFunction, functionDescriptor, scope)
}
private fun secondaryConstructorAdditionalResolve(resolveSession: ResolveSession, constructor: JetSecondaryConstructor, trace: BindingTrace, file: JetFile, statementFilter: StatementFilter) {
@@ -351,7 +347,7 @@ public abstract class ElementResolver protected(
ForceResolveUtil.forceResolveAllContents(constructorDescriptor)
val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter)
bodyResolver.resolveSecondaryConstructorBody(createEmptyContext(resolveSession), trace, constructor, constructorDescriptor, scope)
bodyResolver.resolveSecondaryConstructorBody(createEmptyContext(), trace, constructor, constructorDescriptor, scope)
}
private fun constructorAdditionalResolve(resolveSession: ResolveSession, klass: JetClass, trace: BindingTrace, file: JetFile, statementFilter: StatementFilter) {
@@ -362,7 +358,7 @@ public abstract class ElementResolver protected(
?: error("Can't get primary constructor for descriptor '$classDescriptor' in from class '${klass.getElementTextWithContext()}'")
val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter)
bodyResolver.resolveConstructorParameterDefaultValuesAndAnnotations(createEmptyContext(resolveSession), trace, klass, constructorDescriptor, scope)
bodyResolver.resolveConstructorParameterDefaultValuesAndAnnotations(createEmptyContext(), trace, klass, constructorDescriptor, scope)
}
private fun initializerAdditionalResolve(resolveSession: ResolveSession, classInitializer: JetClassInitializer, trace: BindingTrace, file: JetFile, statementFilter: StatementFilter) {
@@ -370,21 +366,20 @@ public abstract class ElementResolver protected(
val classOrObjectDescriptor = resolveSession.resolveToDescriptor(classOrObject) as LazyClassDescriptor
val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter)
bodyResolver.resolveAnonymousInitializer(createEmptyContext(resolveSession), classInitializer, classOrObjectDescriptor)
bodyResolver.resolveAnonymousInitializer(createEmptyContext(), classInitializer, classOrObjectDescriptor)
}
private fun createBodyResolver(resolveSession: ResolveSession, trace: BindingTrace, file: JetFile, statementFilter: StatementFilter): BodyResolver {
val bodyResolve = InjectorForBodyResolve(file.getProject(), createParameters(resolveSession), trace,
resolveSession.getModuleDescriptor(), getAdditionalCheckerProvider(file), statementFilter)
val globalContext = SimpleGlobalContext(resolveSession.getStorageManager(), resolveSession.getExceptionTracker())
val bodyResolve = InjectorForBodyResolve(
file.getProject(), globalContext,
trace, resolveSession.getModuleDescriptor(), getAdditionalCheckerProvider(file), statementFilter
)
return bodyResolve.getBodyResolver()
}
private fun createParameters(resolveSession: ResolveSession): TopDownAnalysisParameters {
return TopDownAnalysisParameters.createForLocalDeclarations(resolveSession.getStorageManager(), resolveSession.getExceptionTracker())
}
private fun createEmptyContext(resolveSession: ResolveSession): BodyResolveContextForLazy {
return BodyResolveContextForLazy(createParameters(resolveSession), Functions.constant<JetScope>(null))
private fun createEmptyContext(): BodyResolveContextForLazy {
return BodyResolveContextForLazy(TopDownAnalysisParameters.createForLocalDeclarations(), Functions.constant<JetScope>(null))
}
private fun getExpressionResolutionScope(resolveSession: ResolveSession, expression: JetExpression): JetScope {
@@ -460,12 +455,6 @@ public abstract class ElementResolver protected(
private val declaringScopes: Function<in JetDeclaration, JetScope>
) : BodiesResolveContext {
override val storageManager: StorageManager
get() = topDownAnalysisParameters.getStorageManager()
override val exceptionTracker: ExceptionTracker
get() = topDownAnalysisParameters.getExceptionTracker()
override fun getFiles(): Collection<JetFile> = setOf()
override fun getDeclaredClasses(): Map<JetClassOrObject, ClassDescriptorWithResolutionScopes> = mapOf()
@@ -233,7 +233,7 @@ private object KotlinResolveDataProvider {
).getLazyTopDownAnalyzerForTopLevel()!!
lazyTopDownAnalyzer.analyzeDeclarations(
TopDownAnalysisParameters.create(resolveSession.getStorageManager(), resolveSession.getExceptionTracker(), false, false),
TopDownAnalysisParameters.create(false, false),
listOf(analyzableElement)
)
return AnalysisResult.success(
@@ -79,13 +79,13 @@ public final class TopDownAnalyzerFacadeForJS {
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
TopDownAnalysisParameters topDownAnalysisParameters = TopDownAnalysisParameters.create(
globalContext.getStorageManager(), globalContext.getExceptionTracker(), false, false);
false, false);
Collection<JetFile> allFiles = Config.withJsLibAdded(files, config);
InjectorForTopDownAnalyzerForJs injector = new InjectorForTopDownAnalyzerForJs(
project, topDownAnalysisParameters, trace, module,
new FileBasedDeclarationProviderFactory(topDownAnalysisParameters.getStorageManager(), allFiles));
project, globalContext, trace, module,
new FileBasedDeclarationProviderFactory(globalContext.getStorageManager(), allFiles));
try {
injector.getLazyTopDownAnalyzerForTopLevel().analyzeFiles(topDownAnalysisParameters, files,
Collections.<PackageFragmentProvider>emptyList());