diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java index f1add226773..6d3b37fb5c4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java @@ -23,7 +23,8 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl; import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM; +import org.jetbrains.kotlin.resolve.TargetPlatformKt; +import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform; import org.jetbrains.kotlin.storage.LockBasedStorageManager; import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils; @@ -39,10 +40,10 @@ public class JvmRuntimeTypes { private final List mutablePropertyReferences; public JvmRuntimeTypes() { - ModuleDescriptorImpl module = new ModuleDescriptorImpl( + ModuleDescriptorImpl module = TargetPlatformKt.createModule( + JvmPlatform.INSTANCE$, Name.special(""), - LockBasedStorageManager.NO_LOCKS, - TopDownAnalyzerFacadeForJVM.JVM_MODULE_PARAMETERS + LockBasedStorageManager.NO_LOCKS ); PackageFragmentDescriptor kotlinJvmInternal = new MutablePackageFragmentDescriptor(module, new FqName("kotlin.jvm.internal")); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmAnalyzerFacade.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmAnalyzerFacade.kt index 01bdfb9420b..51f8cc0b10e 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmAnalyzerFacade.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmAnalyzerFacade.kt @@ -32,6 +32,8 @@ import org.jetbrains.kotlin.load.java.structure.JavaClass import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer import org.jetbrains.kotlin.resolve.TargetEnvironment +import org.jetbrains.kotlin.resolve.TargetPlatform +import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService import java.util.ArrayList @@ -80,9 +82,6 @@ public object JvmAnalyzerFacade : AnalyzerFacade() { return ResolverForModule(CompositePackageFragmentProvider(providersForModule), container) } - override val moduleParameters: ModuleParameters - get() = TopDownAnalyzerFacadeForJVM.JVM_MODULE_PARAMETERS - @JvmStatic public fun getAllFilesToAnalyze(project: Project, moduleInfo: ModuleInfo?, baseFiles: Collection): List { val allFiles = ArrayList(baseFiles) @@ -92,4 +91,6 @@ public object JvmAnalyzerFacade : AnalyzerFacade() { return allFiles } + override val targetPlatform: TargetPlatform + get() = JvmPlatform } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.java index 480270126cc..6a5303d5385 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.java @@ -21,10 +21,11 @@ import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.analyzer.AnalysisResult; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.context.ModuleContext; import org.jetbrains.kotlin.context.MutableModuleContext; -import org.jetbrains.kotlin.descriptors.*; +import org.jetbrains.kotlin.descriptors.ModuleDescriptor; +import org.jetbrains.kotlin.descriptors.PackageFragmentProvider; +import org.jetbrains.kotlin.descriptors.PackagePartProvider; import org.jetbrains.kotlin.frontend.java.di.ContainerForTopDownAnalyzerForJvm; import org.jetbrains.kotlin.frontend.java.di.DiPackage; import org.jetbrains.kotlin.incremental.components.LookupTracker; @@ -36,15 +37,13 @@ import org.jetbrains.kotlin.modules.Module; import org.jetbrains.kotlin.modules.ModulesPackage; import org.jetbrains.kotlin.modules.TargetId; import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.platform.JavaToKotlinClassMap; -import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap; import org.jetbrains.kotlin.psi.JetFile; -import org.jetbrains.kotlin.resolve.*; +import org.jetbrains.kotlin.resolve.BindingContext; +import org.jetbrains.kotlin.resolve.BindingTrace; +import org.jetbrains.kotlin.resolve.TopDownAnalysisMode; import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisCompletedHandlerExtension; import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform; import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory; -import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter; -import org.jetbrains.kotlin.resolve.scopes.JetScope; import java.util.ArrayList; import java.util.Collection; @@ -56,42 +55,6 @@ public enum TopDownAnalyzerFacadeForJVM { INSTANCE; - public static final List DEFAULT_IMPORTS = buildDefaultImports(); - - private static void addAllClassifiersToImportPathList(List list, JetScope scope) { - for (DeclarationDescriptor descriptor : scope.getDescriptors(DescriptorKindFilter.CLASSIFIERS, JetScope.ALL_NAME_FILTER)) { - list.add(new ImportPath(DescriptorUtils.getFqNameSafe(descriptor), false)); - } - } - - private static List buildDefaultImports() { - List list = new ArrayList(); - list.add(new ImportPath("java.lang.*")); - list.add(new ImportPath("kotlin.*")); - list.add(new ImportPath("kotlin.annotation.*")); - list.add(new ImportPath("kotlin.jvm.*")); - list.add(new ImportPath("kotlin.io.*")); - - addAllClassifiersToImportPathList(list, JvmPlatform.INSTANCE$.getBuiltIns().getBuiltInsPackageScope()); - addAllClassifiersToImportPathList(list, JvmPlatform.INSTANCE$.getBuiltIns().getAnnotationPackageScope()); - - return list; - } - - public static ModuleParameters JVM_MODULE_PARAMETERS = new ModuleParameters() { - @NotNull - @Override - public List getDefaultImports() { - return DEFAULT_IMPORTS; - } - - @NotNull - @Override - public PlatformToKotlinClassMap getPlatformToKotlinClassMap() { - return JavaToKotlinClassMap.INSTANCE; - } - }; - @NotNull public static AnalysisResult analyzeFilesWithJavaIntegrationNoIncremental( @NotNull ModuleContext moduleContext, @@ -192,7 +155,7 @@ public enum TopDownAnalyzerFacadeForJVM { @NotNull public static MutableModuleContext createContextWithSealedModule(@NotNull Project project, @NotNull String moduleName) { MutableModuleContext context = ContextForNewModule( - project, Name.special("<" + moduleName + ">"), JVM_MODULE_PARAMETERS + project, Name.special("<" + moduleName + ">"), JvmPlatform.INSTANCE$ ); context.setDependencies(context.getModule(), JvmPlatform.INSTANCE$.getBuiltIns().getBuiltInsModule()); return context; diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatform.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatform.kt index 706f298ec1e..ffda3b91ff3 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatform.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatform.kt @@ -16,10 +16,42 @@ package org.jetbrains.kotlin.resolve.jvm.platform +import org.jetbrains.kotlin.descriptors.ModuleParameters +import org.jetbrains.kotlin.platform.JavaToKotlinClassMap +import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap +import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.ImportPath import org.jetbrains.kotlin.resolve.PlatformConfigurator import org.jetbrains.kotlin.resolve.TargetPlatform -import org.jetbrains.kotlin.types.DynamicTypesSettings +import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter +import org.jetbrains.kotlin.resolve.scopes.JetScope +import java.util.* public object JvmPlatform : TargetPlatform("JVM") { + override val defaultModuleParameters = object : ModuleParameters { + override val platformToKotlinClassMap: PlatformToKotlinClassMap + get() = JavaToKotlinClassMap.INSTANCE + override val defaultImports: List + get() = DEFAULT_IMPORTS_FOR_JVM + } + override val platformConfigurator: PlatformConfigurator = JvmPlatformConfigurator -} \ No newline at end of file +} + +private val DEFAULT_IMPORTS_FOR_JVM = ArrayList().apply { + add(ImportPath("java.lang.*")) + add(ImportPath("kotlin.*")) + add(ImportPath("kotlin.annotation.*")) + add(ImportPath("kotlin.jvm.*")) + add(ImportPath("kotlin.io.*")) + + fun addAllClassifiersFromScope(scope: JetScope) { + for (descriptor in scope.getDescriptors(DescriptorKindFilter.CLASSIFIERS, JetScope.ALL_NAME_FILTER)) { + add(ImportPath(DescriptorUtils.getFqNameSafe(descriptor), false)) + } + } + + val builtIns = JvmPlatform.builtIns + addAllClassifiersFromScope(builtIns.builtInsPackageScope) + addAllClassifiersFromScope(builtIns.annotationPackageScope) +} diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt index 929f592c0e8..fb6ce9ae564 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.resolve.jvm.platform import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.builtins.KotlinBuiltIns.isArray import org.jetbrains.kotlin.cfg.WhenChecker import org.jetbrains.kotlin.container.StorageComponentContainer import org.jetbrains.kotlin.container.useImpl diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt index 4565d6a5b37..37d6f5ab4b5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt @@ -17,24 +17,23 @@ package org.jetbrains.kotlin.analyzer import com.intellij.psi.search.GlobalSearchScope -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.container.ComponentProvider import org.jetbrains.kotlin.context.ModuleContext import org.jetbrains.kotlin.context.ProjectContext import org.jetbrains.kotlin.context.withModule import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.ModuleParameters import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentProvider +import org.jetbrains.kotlin.descriptors.PackagePartProvider import org.jetbrains.kotlin.descriptors.impl.LazyModuleDependencies import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl -import org.jetbrains.kotlin.descriptors.PackagePartProvider import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.resolve.TargetEnvironment -import java.util.ArrayList -import java.util.HashMap +import org.jetbrains.kotlin.resolve.TargetPlatform +import org.jetbrains.kotlin.resolve.createModule +import java.util.* public class ResolverForModule( public val packageFragmentProvider: PackageFragmentProvider, @@ -137,7 +136,7 @@ public abstract class AnalyzerFacade { val descriptorByModule = HashMap() modules.forEach { module -> - descriptorByModule[module] = ModuleDescriptorImpl(module.name, storageManager, moduleParameters) + descriptorByModule[module] = targetPlatform.createModule(module.name, storageManager) } return ResolverForProjectImpl(descriptorByModule, delegateResolver) } @@ -150,7 +149,7 @@ public abstract class AnalyzerFacade { resolverForProject.descriptorForModule(dependencyInfo as M) } - val builtinsModule = KotlinBuiltIns.getInstance().getBuiltInsModule() + val builtinsModule = targetPlatform.builtIns.builtInsModule module.dependencyOnBuiltins().adjustDependencies(builtinsModule, dependenciesDescriptors) return dependenciesDescriptors } @@ -211,7 +210,7 @@ public abstract class AnalyzerFacade { packagePartProvider: PackagePartProvider ): ResolverForModule - public abstract val moduleParameters: ModuleParameters + public abstract val targetPlatform: TargetPlatform } //NOTE: relies on delegate to be lazily computed and cached diff --git a/compiler/frontend/src/org/jetbrains/kotlin/context/context.kt b/compiler/frontend/src/org/jetbrains/kotlin/context/context.kt index be0aa6c3261..7c542901d32 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/context/context.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/context/context.kt @@ -24,6 +24,8 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap +import org.jetbrains.kotlin.resolve.TargetPlatform +import org.jetbrains.kotlin.resolve.createModule import org.jetbrains.kotlin.storage.ExceptionTracker import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.StorageManager @@ -105,13 +107,25 @@ public fun ProjectContext.withModule(module: ModuleDescriptor): ModuleContext = public fun ContextForNewModule( project: Project, moduleName: Name, - parameters: ModuleParameters + parameters: ModuleParameters, + builtIns: KotlinBuiltIns = KotlinBuiltIns.getInstance() ): MutableModuleContext { val projectContext = ProjectContext(project) - val module = ModuleDescriptorImpl(moduleName, projectContext.storageManager, parameters) + val module = ModuleDescriptorImpl(moduleName, projectContext.storageManager, parameters, builtIns) return MutableModuleContextImpl(module, projectContext) } +public fun ContextForNewModule( + project: Project, + moduleName: Name, + targetPlatform: TargetPlatform +): MutableModuleContext { + val projectContext = ProjectContext(project) + val module = targetPlatform.createModule(moduleName, projectContext.storageManager) + return MutableModuleContextImpl(module, projectContext) +} + + @Deprecated("Used temporarily while we are in transition from to lazy resolve") public open class TypeLazinessToken { @Deprecated("Used temporarily while we are in transition from to lazy resolve") diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt index 5678bbc6a55..3818f1ba9f0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt @@ -19,10 +19,14 @@ package org.jetbrains.kotlin.resolve import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.container.StorageComponentContainer import org.jetbrains.kotlin.container.useInstance +import org.jetbrains.kotlin.descriptors.ModuleParameters +import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.checkers.* import org.jetbrains.kotlin.resolve.validation.DeprecatedSymbolValidator import org.jetbrains.kotlin.resolve.validation.OperatorValidator import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator +import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.DynamicTypesSettings public abstract class TargetPlatform( @@ -34,8 +38,10 @@ public abstract class TargetPlatform( public abstract val platformConfigurator: PlatformConfigurator public val builtIns: KotlinBuiltIns = KotlinBuiltIns.getInstance() + abstract val defaultModuleParameters: ModuleParameters public object Default : TargetPlatform("Default") { + override val defaultModuleParameters = ModuleParameters.Empty override val platformConfigurator = PlatformConfigurator(DynamicTypesSettings(), listOf(), listOf(), listOf(), listOf(), listOf()) } } @@ -71,3 +77,9 @@ public open class PlatformConfigurator( } } } + +fun TargetPlatform.createModule( + name: Name, + storageManager: StorageManager +) = ModuleDescriptorImpl(name, storageManager, defaultModuleParameters, builtIns) + diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractJetDiagnosticsTest.java b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractJetDiagnosticsTest.java index a7b8716d489..7014edad028 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractJetDiagnosticsTest.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractJetDiagnosticsTest.java @@ -41,10 +41,7 @@ import org.jetbrains.kotlin.psi.Call; import org.jetbrains.kotlin.psi.JetElement; import org.jetbrains.kotlin.psi.JetExpression; import org.jetbrains.kotlin.psi.JetFile; -import org.jetbrains.kotlin.resolve.AnalyzingUtils; -import org.jetbrains.kotlin.resolve.BindingContext; -import org.jetbrains.kotlin.resolve.BindingTrace; -import org.jetbrains.kotlin.resolve.TargetPlatform; +import org.jetbrains.kotlin.resolve.*; import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics; @@ -360,9 +357,7 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest { @NotNull protected ModuleDescriptorImpl createModule(@NotNull String moduleName, @NotNull StorageManager storageManager) { - return new ModuleDescriptorImpl(Name.special(moduleName), - storageManager, - TopDownAnalyzerFacadeForJVM.JVM_MODULE_PARAMETERS); + return TargetPlatformKt.createModule(JvmPlatform.INSTANCE$, Name.special(moduleName), storageManager); } @NotNull diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractJetDiagnosticsTestWithJsStdLib.java b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractJetDiagnosticsTestWithJsStdLib.java index c9c549ae350..ce83d59b78d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractJetDiagnosticsTestWithJsStdLib.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractJetDiagnosticsTestWithJsStdLib.java @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.JetFile; import org.jetbrains.kotlin.resolve.BindingTrace; import org.jetbrains.kotlin.resolve.TargetPlatform; +import org.jetbrains.kotlin.resolve.TargetPlatformKt; import org.jetbrains.kotlin.storage.StorageManager; import java.util.ArrayList; @@ -75,7 +76,7 @@ public abstract class AbstractJetDiagnosticsTestWithJsStdLib extends AbstractJet @NotNull @Override protected ModuleDescriptorImpl createModule(@NotNull String moduleName, @NotNull StorageManager storageManager) { - return new ModuleDescriptorImpl(Name.special(moduleName), storageManager, TopDownAnalyzerFacadeForJS.JS_MODULE_PARAMETERS); + return TargetPlatformKt.createModule(JsPlatform.INSTANCE$, Name.special(moduleName), storageManager); } @NotNull diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/builtins/LoadBuiltinsTest.java b/compiler/tests/org/jetbrains/kotlin/serialization/builtins/LoadBuiltinsTest.java index 77cc6edd3e7..c0fc61ff450 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/builtins/LoadBuiltinsTest.java +++ b/compiler/tests/org/jetbrains/kotlin/serialization/builtins/LoadBuiltinsTest.java @@ -21,6 +21,7 @@ import com.intellij.util.containers.ContainerUtil; import kotlin.Unit; import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime; @@ -102,7 +103,7 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment { private static PackageFragmentDescriptor createBuiltInsPackageFragment() { LockBasedStorageManager storageManager = new LockBasedStorageManager(); ModuleDescriptorImpl builtInsModule = new ModuleDescriptorImpl( - Name.special(""), storageManager, ModuleParameters.Empty.INSTANCE$ + Name.special(""), storageManager, ModuleParameters.Empty.INSTANCE$, KotlinBuiltIns.getInstance() ); PackageFragmentProvider packageFragmentProvider = createBuiltInPackageFragmentProvider( diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerTest.kt b/compiler/tests/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerTest.kt index 21f37a88100..40e93573f69 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/serialization/js/KotlinJavascriptSerializerTest.kt @@ -79,7 +79,7 @@ public class KotlinJavascriptSerializerTest : TestCaseWithTmpdir() { } private fun deserialize(metaFile: File): ModuleDescriptorImpl { - val module = JetTestUtils.createEmptyModule("<$MODULE_NAME>") + val module = JetTestUtils.createEmptyModule("<$MODULE_NAME>", JsPlatform) val metadata = KotlinJavascriptMetadataUtils.loadMetadata(metaFile) assert(metadata.size() == 1) diff --git a/compiler/tests/org/jetbrains/kotlin/test/JetTestUtils.java b/compiler/tests/org/jetbrains/kotlin/test/JetTestUtils.java index ed26932d183..fe8f99cc8ae 100644 --- a/compiler/tests/org/jetbrains/kotlin/test/JetTestUtils.java +++ b/compiler/tests/org/jetbrains/kotlin/test/JetTestUtils.java @@ -65,7 +65,9 @@ import org.jetbrains.kotlin.psi.JetExpression; import org.jetbrains.kotlin.psi.JetFile; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.BindingTrace; +import org.jetbrains.kotlin.resolve.TargetPlatform; import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics; +import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform; import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil; import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil; import org.jetbrains.kotlin.storage.LockBasedStorageManager; @@ -941,8 +943,13 @@ public class JetTestUtils { @NotNull public static ModuleDescriptorImpl createEmptyModule(@NotNull String name) { + return createEmptyModule(name, JvmPlatform.INSTANCE$); + } + + @NotNull + public static ModuleDescriptorImpl createEmptyModule(@NotNull String name, @NotNull TargetPlatform platform) { return new ModuleDescriptorImpl( - Name.special(name), LockBasedStorageManager.NO_LOCKS, ModuleParameters.Empty.INSTANCE$ + Name.special(name), LockBasedStorageManager.NO_LOCKS, platform.getDefaultModuleParameters(), platform.getBuiltIns() ); } diff --git a/core/descriptors.runtime/src/org/jetbrains/kotlin/load/kotlin/reflect/RuntimeModuleData.kt b/core/descriptors.runtime/src/org/jetbrains/kotlin/load/kotlin/reflect/RuntimeModuleData.kt index 7f0c5484f49..77e8c0d2c25 100644 --- a/core/descriptors.runtime/src/org/jetbrains/kotlin/load/kotlin/reflect/RuntimeModuleData.kt +++ b/core/descriptors.runtime/src/org/jetbrains/kotlin/load/kotlin/reflect/RuntimeModuleData.kt @@ -44,9 +44,10 @@ public class RuntimeModuleData private constructor(public val deserialization: D companion object { public fun create(classLoader: ClassLoader): RuntimeModuleData { + val builtIns = KotlinBuiltIns.getInstance() val storageManager = LockBasedStorageManager() val module = ModuleDescriptorImpl(Name.special(""), storageManager, - ModuleParameters(listOf(), JavaToKotlinClassMap.INSTANCE)) + ModuleParameters(listOf(), JavaToKotlinClassMap.INSTANCE), builtIns) val reflectKotlinClassFinder = ReflectKotlinClassFinder(classLoader) val deserializedDescriptorResolver = DeserializedDescriptorResolver(RuntimeErrorReporter) @@ -71,7 +72,7 @@ public class RuntimeModuleData private constructor(public val deserialization: D singleModuleClassResolver.resolver = javaDescriptorResolver deserializedDescriptorResolver.setComponents(deserializationComponentsForJava) - module.setDependencies(module, KotlinBuiltIns.getInstance().getBuiltInsModule()) + module.setDependencies(module, builtIns.builtInsModule) module.initialize(javaDescriptorResolver.packageFragmentProvider) return RuntimeModuleData(deserializationComponentsForJava.components, runtimePackageFacadeProvider) diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ModuleDescriptorImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ModuleDescriptorImpl.kt index 280e80a497c..844fbdff265 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ModuleDescriptorImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/ModuleDescriptorImpl.kt @@ -40,12 +40,6 @@ public class ModuleDescriptorImpl( } } - public constructor( - moduleName: Name, - storageManager: StorageManager, - moduleParameters: ModuleParameters - ) : this(moduleName, storageManager, moduleParameters, KotlinBuiltIns.getInstance()) - private var dependencies: ModuleDependencies? = null private var packageFragmentProviderForModuleContent: PackageFragmentProvider? = null diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JsAnalyzerFacade.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JsAnalyzerFacade.kt index 7ce57877b7c..da973b9d01d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JsAnalyzerFacade.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JsAnalyzerFacade.kt @@ -22,16 +22,15 @@ import com.intellij.util.PathUtil import org.jetbrains.kotlin.analyzer.* import org.jetbrains.kotlin.container.get import org.jetbrains.kotlin.context.ModuleContext -import org.jetbrains.kotlin.descriptors.ModuleParameters +import org.jetbrains.kotlin.descriptors.PackagePartProvider import org.jetbrains.kotlin.descriptors.impl.CompositePackageFragmentProvider import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.frontend.di.createContainerForLazyResolve import org.jetbrains.kotlin.idea.framework.KotlinJavaScriptLibraryDetectionUtil -import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS import org.jetbrains.kotlin.js.resolve.JsPlatform -import org.jetbrains.kotlin.descriptors.PackagePartProvider import org.jetbrains.kotlin.resolve.BindingTraceContext import org.jetbrains.kotlin.resolve.TargetEnvironment +import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil @@ -73,6 +72,6 @@ public object JsAnalyzerFacade : AnalyzerFacade() { return ResolverForModule(packageFragmentProvider, container) } - override val moduleParameters: ModuleParameters - get() = TopDownAnalyzerFacadeForJS.JS_MODULE_PARAMETERS + override val targetPlatform: TargetPlatform + get() = JsPlatform } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java index 6d5eb5f72a7..699bc3c154d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java @@ -39,6 +39,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import org.jetbrains.kotlin.asJava.LightClassUtil; +import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.codegen.binding.PsiCodegenPredictor; import org.jetbrains.kotlin.context.ContextPackage; import org.jetbrains.kotlin.context.MutableModuleContext; @@ -60,7 +61,7 @@ import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.resolve.BindingTraceContext; import org.jetbrains.kotlin.resolve.TargetPlatform; import org.jetbrains.kotlin.resolve.jvm.JvmClassName; -import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM; +import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform; import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer; import org.jetbrains.kotlin.resolve.lazy.ResolveSession; import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory; @@ -242,9 +243,10 @@ public class JetSourceNavigationHelper { MutableModuleContext newModuleContext = ContextPackage.ContextForNewModule( project, Name.special(""), ModuleParameters( - TopDownAnalyzerFacadeForJVM.DEFAULT_IMPORTS, + JvmPlatform.defaultModuleParameters.getDefaultImports(), PlatformToKotlinClassMap.EMPTY - ) + ), + KotlinBuiltIns.getInstance() ); newModuleContext.setDependencies(newModuleContext.getModule(), platform.getBuiltIns().getBuiltInsModule()); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt index 697e0d84c4e..457e8ad1b2e 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/textBuilder/DeserializerForDecompilerBase.kt @@ -66,7 +66,7 @@ public abstract class DeserializerForDecompilerBase( protected fun createDummyPackageFragment(fqName: FqName): MutablePackageFragmentDescriptor = MutablePackageFragmentDescriptor(moduleDescriptor, fqName) - private fun createDummyModule(name: String) = ModuleDescriptorImpl(Name.special("<$name>"), storageManager, ModuleParameters.Empty) + private fun createDummyModule(name: String) = ModuleDescriptorImpl(Name.special("<$name>"), storageManager, ModuleParameters.Empty, targetPlatform.builtIns) init { moduleDescriptor.initialize(packageFragmentProvider) diff --git a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt index cedb99fc4d8..b6eb71252e5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/ImportInsertHelperImpl.kt @@ -27,18 +27,16 @@ import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings import org.jetbrains.kotlin.idea.core.targetDescriptors import org.jetbrains.kotlin.idea.imports.getImportableTargets import org.jetbrains.kotlin.idea.imports.importableFqName -import org.jetbrains.kotlin.idea.project.ProjectStructureUtil +import org.jetbrains.kotlin.idea.project.platform import org.jetbrains.kotlin.idea.refactoring.fqName.isImported import org.jetbrains.kotlin.idea.util.ImportInsertHelper import org.jetbrains.kotlin.idea.util.ImportInsertHelper.ImportDescriptorResult import org.jetbrains.kotlin.incremental.components.NoLookupLocation -import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.ImportPath import org.jetbrains.kotlin.resolve.descriptorUtil.getImportableDescriptor -import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.JetScope @@ -79,10 +77,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert } override fun isImportedWithDefault(importPath: ImportPath, contextFile: JetFile): Boolean { - val defaultImports = if (ProjectStructureUtil.isJsKotlinModule(contextFile)) - TopDownAnalyzerFacadeForJS.DEFAULT_IMPORTS - else - TopDownAnalyzerFacadeForJVM.DEFAULT_IMPORTS + val defaultImports = contextFile.platform.defaultModuleParameters.defaultImports return importPath.isImported(defaultImports) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/KotlinJavaScriptDecompiledTextConsistencyTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/KotlinJavaScriptDecompiledTextConsistencyTest.kt index 107aea505c7..8c9c83dd9cb 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/KotlinJavaScriptDecompiledTextConsistencyTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/KotlinJavaScriptDecompiledTextConsistencyTest.kt @@ -57,7 +57,7 @@ public class KotlinJavaScriptDecompiledTextConsistencyTest : TextConsistencyBase override fun getModuleDescriptor(): ModuleDescriptor { val stdlibJar = PathUtil.getKotlinPathsForDistDirectory().jsStdLibJarPath.absolutePath - val module = JetTestUtils.createEmptyModule("") + val module = JetTestUtils.createEmptyModule("", JsPlatform) val metadata = KotlinJavascriptMetadataUtils.loadMetadata(stdlibJar) assert(metadata.size() == 1) diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/TopDownAnalyzerFacadeForJS.java b/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/TopDownAnalyzerFacadeForJS.java index e573dab947d..2ad108a7e67 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/TopDownAnalyzerFacadeForJS.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/analyze/TopDownAnalyzerFacadeForJS.java @@ -40,27 +40,6 @@ import java.util.Collections; import java.util.List; public final class TopDownAnalyzerFacadeForJS { - public static final List DEFAULT_IMPORTS = ImmutableList.of( - new ImportPath("java.lang.*"), - new ImportPath("kotlin.*"), - new ImportPath("kotlin.annotation.*"), - new ImportPath("kotlin.js.*") - ); - - public static ModuleParameters JS_MODULE_PARAMETERS = new ModuleParameters() { - @NotNull - @Override - public List getDefaultImports() { - return DEFAULT_IMPORTS; - } - - @NotNull - @Override - public PlatformToKotlinClassMap getPlatformToKotlinClassMap() { - return PlatformToKotlinClassMap.EMPTY; - } - }; - private TopDownAnalyzerFacadeForJS() { } @@ -72,7 +51,7 @@ public final class TopDownAnalyzerFacadeForJS { BindingTrace trace = new BindingTraceContext(); MutableModuleContext newModuleContext = ContextPackage.ContextForNewModule( - config.getProject(), Name.special("<" + config.getModuleId() + ">"), JS_MODULE_PARAMETERS + config.getProject(), Name.special("<" + config.getModuleId() + ">"), JsPlatform.INSTANCE$ ); newModuleContext.setDependencies(computeDependencies(newModuleContext.getModule(), config)); return analyzeFilesWithGivenTrace(files, trace, newModuleContext, config); diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/config/Config.java b/js/js.frontend/src/org/jetbrains/kotlin/js/config/Config.java index 857b778df87..029785bddaa 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/config/Config.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/config/Config.java @@ -26,10 +26,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.PackageFragmentProvider; import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl; -import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS; import org.jetbrains.kotlin.js.resolve.JsPlatform; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.JetFile; +import org.jetbrains.kotlin.resolve.TargetPlatformKt; import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil; import org.jetbrains.kotlin.storage.LockBasedStorageManager; import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata; @@ -152,9 +152,8 @@ public abstract class Config { "expected abi version " + KotlinJavascriptMetadataUtils.ABI_VERSION + ", but metadata.abiVersion = " + metadata.getAbiVersion(); - ModuleDescriptorImpl moduleDescriptor = new ModuleDescriptorImpl( - Name.special("<" + metadata.getModuleName() + ">"), storageManager, - TopDownAnalyzerFacadeForJS.JS_MODULE_PARAMETERS + ModuleDescriptorImpl moduleDescriptor = TargetPlatformKt.createModule( + JsPlatform.INSTANCE$, Name.special("<" + metadata.getModuleName() + ">"), storageManager ); PackageFragmentProvider provider = diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatform.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatform.kt index 78a3914c93c..93ecb3b0ea1 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatform.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatform.kt @@ -16,10 +16,26 @@ package org.jetbrains.kotlin.js.resolve +import com.google.common.collect.ImmutableList +import org.jetbrains.kotlin.descriptors.ModuleParameters +import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap +import org.jetbrains.kotlin.resolve.ImportPath import org.jetbrains.kotlin.resolve.PlatformConfigurator import org.jetbrains.kotlin.resolve.TargetPlatform -import org.jetbrains.kotlin.types.DynamicTypesAllowed public object JsPlatform : TargetPlatform("JS") { + override val defaultModuleParameters = object : ModuleParameters { + override val defaultImports: List = ImmutableList.of( + ImportPath("java.lang.*"), + ImportPath("kotlin.*"), + ImportPath("kotlin.annotation.*"), + ImportPath("kotlin.js.*") + ) + + override val platformToKotlinClassMap: PlatformToKotlinClassMap + get() = PlatformToKotlinClassMap.EMPTY + } + + override val platformConfigurator: PlatformConfigurator = JsPlatformConfigurator } \ No newline at end of file