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