Extract module info & target platform to separate frontend.common
This commit is contained in:
committed by
Mikhail Glukhikh
parent
cd614b5bf8
commit
e3aed04d96
@@ -14,6 +14,7 @@ dependencies {
|
||||
compile(project(":compiler:container"))
|
||||
compile(project(":compiler:resolution"))
|
||||
compile(project(":compiler:psi"))
|
||||
compile(project(":compiler:frontend.common"))
|
||||
compile(project(":kotlin-script-runtime"))
|
||||
compile(commonDep("io.javaslang","javaslang"))
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
|
||||
@@ -278,37 +278,6 @@ interface PlatformAnalysisParameters {
|
||||
object Empty : PlatformAnalysisParameters
|
||||
}
|
||||
|
||||
interface ModuleInfo {
|
||||
val name: Name
|
||||
val displayedName: String get() = name.asString()
|
||||
fun dependencies(): List<ModuleInfo>
|
||||
val expectedBy: List<ModuleInfo> get() = emptyList()
|
||||
val platform: TargetPlatform? get() = null
|
||||
fun modulesWhoseInternalsAreVisible(): Collection<ModuleInfo> = listOf()
|
||||
val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>
|
||||
get() = mapOf(Capability to this)
|
||||
val stableName: Name?
|
||||
get() = null
|
||||
|
||||
// For common modules, we add built-ins at the beginning of the dependencies list, after the SDK.
|
||||
// This is needed because if a JVM module depends on the common module, we should use JVM built-ins for resolution of both modules.
|
||||
// The common module usually depends on kotlin-stdlib-common which may or may not have its own (common, non-JVM) built-ins,
|
||||
// but if they are present, they should come after JVM built-ins in the dependencies list, because JVM built-ins contain
|
||||
// additional members dependent on the JDK
|
||||
fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns =
|
||||
if (platform == TargetPlatform.Common)
|
||||
ModuleInfo.DependencyOnBuiltIns.AFTER_SDK
|
||||
else
|
||||
ModuleInfo.DependencyOnBuiltIns.LAST
|
||||
|
||||
//TODO: (module refactoring) provide dependency on builtins after runtime in IDEA
|
||||
enum class DependencyOnBuiltIns { NONE, AFTER_SDK, LAST }
|
||||
|
||||
companion object {
|
||||
val Capability = ModuleDescriptor.Capability<ModuleInfo>("ModuleInfo")
|
||||
}
|
||||
}
|
||||
|
||||
interface CombinedModuleInfo : ModuleInfo {
|
||||
val containedModules: List<ModuleInfo>
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class CommonAnalysisParameters(
|
||||
|
||||
/**
|
||||
* A facade that is used to analyze common (platform-independent) modules in multi-platform projects.
|
||||
* See [TargetPlatform.Common]
|
||||
* See [CommonPlatform]
|
||||
*/
|
||||
object CommonAnalyzerFacade : ResolverForModuleFactory() {
|
||||
private class SourceModuleInfo(
|
||||
@@ -176,5 +176,5 @@ object CommonAnalyzerFacade : ResolverForModuleFactory() {
|
||||
}
|
||||
|
||||
override val targetPlatform: TargetPlatform
|
||||
get() = TargetPlatform.Common
|
||||
get() = CommonPlatform
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analyzer.common
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.builtins.PlatformToKotlinClassMap
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.SamConversionTransformer
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.DynamicTypesSettings
|
||||
|
||||
object CommonPlatform : TargetPlatform("Default") {
|
||||
override fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>) {}
|
||||
|
||||
override val multiTargetPlatform: MultiTargetPlatform
|
||||
get() = MultiTargetPlatform.Common
|
||||
|
||||
override val platformConfigurator: PlatformConfigurator = CommonPlatformConfigurator
|
||||
|
||||
override fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns = ModuleInfo.DependencyOnBuiltIns.AFTER_SDK
|
||||
}
|
||||
|
||||
private object CommonPlatformConfigurator : PlatformConfiguratorBase(
|
||||
DynamicTypesSettings(), listOf(), listOf(), listOf(), listOf(), listOf(),
|
||||
IdentifierChecker.Default, OverloadFilter.Default, PlatformToKotlinClassMap.EMPTY, DelegationFilter.Default,
|
||||
OverridesBackwardCompatibilityHelper.Default,
|
||||
DeclarationReturnTypeSanitizer.Default
|
||||
) {
|
||||
override fun configureModuleComponents(container: StorageComponentContainer) {
|
||||
container.useInstance(SyntheticScopes.Empty)
|
||||
container.useInstance(SamConversionTransformer.Empty)
|
||||
container.useInstance(TypeSpecificityComparator.NONE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.frontend.di
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.common.CommonPlatform
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
||||
@@ -181,7 +182,7 @@ fun createLazyResolveSession(moduleContext: ModuleContext, files: Collection<KtF
|
||||
moduleContext,
|
||||
FileBasedDeclarationProviderFactory(moduleContext.storageManager, files),
|
||||
BindingTraceContext(),
|
||||
TargetPlatform.Common,
|
||||
CommonPlatform,
|
||||
TargetPlatformVersion.NoVersion,
|
||||
CompilerEnvironment,
|
||||
LanguageVersionSettingsImpl.DEFAULT
|
||||
|
||||
@@ -6,104 +6,15 @@
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.builtins.PlatformToKotlinClassMap
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.composeContainer
|
||||
import org.jetbrains.kotlin.container.useImpl
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.SamConversionTransformer
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
import org.jetbrains.kotlin.resolve.checkers.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.DynamicTypesSettings
|
||||
import java.util.*
|
||||
|
||||
abstract class TargetPlatform(val platformName: String) {
|
||||
private data class DefaultImportsKey(val includeKotlinComparisons: Boolean, val includeLowPriorityImports: Boolean)
|
||||
|
||||
private val defaultImports = LockBasedStorageManager().let { storageManager ->
|
||||
storageManager.createMemoizedFunction<DefaultImportsKey, List<ImportPath>> { (includeKotlinComparisons, includeLowPriorityImports) ->
|
||||
ArrayList<ImportPath>().apply {
|
||||
listOf(
|
||||
"kotlin.*",
|
||||
"kotlin.annotation.*",
|
||||
"kotlin.collections.*",
|
||||
"kotlin.ranges.*",
|
||||
"kotlin.sequences.*",
|
||||
"kotlin.text.*",
|
||||
"kotlin.io.*"
|
||||
).forEach { add(ImportPath.fromString(it)) }
|
||||
|
||||
if (includeKotlinComparisons) {
|
||||
add(ImportPath.fromString("kotlin.comparisons.*"))
|
||||
}
|
||||
|
||||
computePlatformSpecificDefaultImports(storageManager, this)
|
||||
|
||||
if (includeLowPriorityImports) {
|
||||
addAll(defaultLowPriorityImports)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString() = platformName
|
||||
|
||||
abstract val platformConfigurator: PlatformConfigurator
|
||||
|
||||
open val defaultLowPriorityImports: List<ImportPath> get() = emptyList()
|
||||
|
||||
fun getDefaultImports(languageVersionSettings: LanguageVersionSettings, includeLowPriorityImports: Boolean): List<ImportPath> =
|
||||
defaultImports(
|
||||
DefaultImportsKey(
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.DefaultImportOfPackageKotlinComparisons),
|
||||
includeLowPriorityImports
|
||||
)
|
||||
)
|
||||
|
||||
protected abstract fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>)
|
||||
|
||||
open val excludedImports: List<FqName> get() = emptyList()
|
||||
|
||||
abstract val multiTargetPlatform: MultiTargetPlatform
|
||||
|
||||
// This function is used in "cat.helm.clean:0.1.1-SNAPSHOT": https://plugins.jetbrains.com/plugin/index?xmlId=cat.helm.clean
|
||||
@Suppress("DeprecatedCallableAddReplaceWith")
|
||||
@Deprecated("Use getDefaultImports(LanguageVersionSettings, Boolean) instead.", level = DeprecationLevel.ERROR)
|
||||
fun getDefaultImports(includeKotlinComparisons: Boolean): List<ImportPath> {
|
||||
return getDefaultImports(
|
||||
if (includeKotlinComparisons) LanguageVersionSettingsImpl.DEFAULT
|
||||
else LanguageVersionSettingsImpl(LanguageVersion.KOTLIN_1_0, ApiVersion.KOTLIN_1_0),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
object Common : TargetPlatform("Default") {
|
||||
override fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>) {}
|
||||
|
||||
override val platformConfigurator =
|
||||
object : PlatformConfigurator(
|
||||
DynamicTypesSettings(), listOf(), listOf(), listOf(), listOf(), listOf(),
|
||||
IdentifierChecker.Default, OverloadFilter.Default, PlatformToKotlinClassMap.EMPTY, DelegationFilter.Default,
|
||||
OverridesBackwardCompatibilityHelper.Default,
|
||||
DeclarationReturnTypeSanitizer.Default
|
||||
) {
|
||||
override fun configureModuleComponents(container: StorageComponentContainer) {
|
||||
container.useInstance(SyntheticScopes.Empty)
|
||||
container.useInstance(SamConversionTransformer.Empty)
|
||||
container.useInstance(TypeSpecificityComparator.NONE)
|
||||
}
|
||||
}
|
||||
|
||||
override val multiTargetPlatform: MultiTargetPlatform
|
||||
get() = MultiTargetPlatform.Common
|
||||
}
|
||||
}
|
||||
|
||||
private val DEFAULT_DECLARATION_CHECKERS = listOf(
|
||||
DataClassDeclarationChecker(),
|
||||
@@ -143,7 +54,7 @@ private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf(
|
||||
private val DEFAULT_ANNOTATION_CHECKERS = listOf<AdditionalAnnotationChecker>()
|
||||
|
||||
|
||||
abstract class PlatformConfigurator(
|
||||
abstract class PlatformConfiguratorBase(
|
||||
private val dynamicTypesSettings: DynamicTypesSettings,
|
||||
additionalDeclarationCheckers: List<DeclarationChecker>,
|
||||
additionalCallCheckers: List<CallChecker>,
|
||||
@@ -156,7 +67,7 @@ abstract class PlatformConfigurator(
|
||||
private val delegationFilter: DelegationFilter,
|
||||
private val overridesBackwardCompatibilityHelper: OverridesBackwardCompatibilityHelper,
|
||||
private val declarationReturnTypeSanitizer: DeclarationReturnTypeSanitizer
|
||||
) {
|
||||
) : PlatformConfigurator {
|
||||
private val declarationCheckers: List<DeclarationChecker> = DEFAULT_DECLARATION_CHECKERS + additionalDeclarationCheckers
|
||||
private val callCheckers: List<CallChecker> = DEFAULT_CALL_CHECKERS + additionalCallCheckers
|
||||
private val typeCheckers: List<AdditionalTypeChecker> = DEFAULT_TYPE_CHECKERS + additionalTypeCheckers
|
||||
@@ -164,9 +75,7 @@ abstract class PlatformConfigurator(
|
||||
DEFAULT_CLASSIFIER_USAGE_CHECKERS + additionalClassifierUsageCheckers
|
||||
private val annotationCheckers: List<AdditionalAnnotationChecker> = DEFAULT_ANNOTATION_CHECKERS + additionalAnnotationCheckers
|
||||
|
||||
abstract fun configureModuleComponents(container: StorageComponentContainer)
|
||||
|
||||
val platformSpecificContainer = composeContainer(this::class.java.simpleName) {
|
||||
override val platformSpecificContainer = composeContainer(this::class.java.simpleName) {
|
||||
useInstance(dynamicTypesSettings)
|
||||
declarationCheckers.forEach { useInstance(it) }
|
||||
callCheckers.forEach { useInstance(it) }
|
||||
@@ -181,7 +90,7 @@ abstract class PlatformConfigurator(
|
||||
useInstance(declarationReturnTypeSanitizer)
|
||||
}
|
||||
|
||||
fun configureModuleDependentCheckers(container: StorageComponentContainer) {
|
||||
override fun configureModuleDependentCheckers(container: StorageComponentContainer) {
|
||||
container.useImpl<ExperimentalMarkerDeclarationAnnotationChecker>()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user