[Platform API] Introduce fundamental abstraction of Platform
This is a large commit, which introduces general API for working with
abstraction of Platform.
- Add new abstraction to 'core' - SimplePlatform - which represents
exactly one platform
- Clients are strongly prohibited to create instances of SimplePlatform
by hand, instead, corresponding *Platforms abstraction should be used
(e.g. JvmPlatforms, JsPlatforms, KonanPlatforms)
- Move TargetPlatform to 'core', it represents now a collection of
SimplePlatforms
- Clients are strongly encouraged to use TargetPlatform
(not SimplePlatform) in API, to enforce checks for multiplatform
- Provide a helper-extensions to work with TargetPlatform
(in particular, for getting a specific component platform)
- Remove MultiTargetPlatform in favour of TargetPlatform
- Notably, this commit leaves another widely used duplicated abstraction,
namely, IdePlatform. For the sake sanity, removal of IdePlatform is
extracted in the separate commit.
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.frontend.js.di
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
||||
import org.jetbrains.kotlin.container.get
|
||||
import org.jetbrains.kotlin.container.useImpl
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
@@ -28,7 +27,6 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.frontend.di.configureModule
|
||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
|
||||
@@ -46,7 +44,12 @@ fun createTopDownAnalyzerForJs(
|
||||
additionalPackages: List<PackageFragmentProvider>
|
||||
): LazyTopDownAnalyzer {
|
||||
val storageComponentContainer = createContainer("TopDownAnalyzerForJs", JsPlatformCompilerServices) {
|
||||
configureModule(moduleContext, JsPlatform, TargetPlatformVersion.NoVersion, JsPlatformCompilerServices, bindingTrace)
|
||||
configureModule(
|
||||
moduleContext,
|
||||
DefaultBuiltInPlatforms.jsPlatform,
|
||||
JsPlatformCompilerServices,
|
||||
bindingTrace
|
||||
)
|
||||
|
||||
useInstance(declarationProviderFactory)
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
|
||||
@@ -67,7 +67,7 @@ object TopDownAnalyzerFacadeForJS {
|
||||
ProjectContext(project),
|
||||
Name.special("<$moduleName>"),
|
||||
builtIns,
|
||||
multiTargetPlatform = null
|
||||
platform = null
|
||||
)
|
||||
|
||||
val additionalPackages = mutableListOf<PackageFragmentProvider>()
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.js.resolve
|
||||
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
|
||||
object JsPlatform : TargetPlatform("JS") {
|
||||
override val platform: MultiTargetPlatform
|
||||
get() = MultiTargetPlatform.Specific(platformName)
|
||||
}
|
||||
@@ -1,30 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2019 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.js.resolve
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.*
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
||||
import org.jetbrains.kotlin.container.get
|
||||
import org.jetbrains.kotlin.context.ModuleContext
|
||||
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.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.resolve.TargetEnvironment
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
@@ -41,8 +31,7 @@ object JsResolverForModuleFactory : ResolverForModuleFactory() {
|
||||
platformParameters: PlatformAnalysisParameters,
|
||||
targetEnvironment: TargetEnvironment,
|
||||
resolverForProject: ResolverForProject<M>,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
targetPlatformVersion: TargetPlatformVersion
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
): ResolverForModule {
|
||||
val (moduleInfo, syntheticFiles, moduleContentScope) = moduleContent
|
||||
val project = moduleContext.project
|
||||
@@ -58,8 +47,7 @@ object JsResolverForModuleFactory : ResolverForModuleFactory() {
|
||||
moduleContext,
|
||||
declarationProviderFactory,
|
||||
BindingTraceContext(/* allowSliceRewrite = */ true),
|
||||
JsPlatform,
|
||||
TargetPlatformVersion.NoVersion,
|
||||
moduleDescriptor.platform!!,
|
||||
JsPlatformCompilerServices,
|
||||
targetEnvironment,
|
||||
languageVersionSettings
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.platform.js
|
||||
|
||||
import org.jetbrains.kotlin.platform.SimplePlatform
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.toTargetPlatform
|
||||
|
||||
abstract class JsPlatform : SimplePlatform("JS") {
|
||||
override val oldFashionedDescription: String
|
||||
get() = "JavaScript "
|
||||
}
|
||||
|
||||
object JsPlatforms {
|
||||
val defaultJsPlatform: TargetPlatform = object : JsPlatform() {}.toTargetPlatform()
|
||||
|
||||
val allJsPlatforms: List<TargetPlatform> = listOf(defaultJsPlatform)
|
||||
}
|
||||
|
||||
fun TargetPlatform?.isJs(): Boolean = this?.singleOrNull() is JsPlatform
|
||||
Reference in New Issue
Block a user