Multi-platform refactoring: get rid of PlatformKind (replace with MultiTargetPlatform)
This commit is contained in:
@@ -138,7 +138,7 @@ public abstract class KotlinBuiltIns {
|
||||
}
|
||||
|
||||
protected void createBuiltInsModule() {
|
||||
builtInsModule = new ModuleDescriptorImpl(BUILTINS_MODULE_NAME, storageManager, this);
|
||||
builtInsModule = new ModuleDescriptorImpl(BUILTINS_MODULE_NAME, storageManager, this, null);
|
||||
PackageFragmentProvider packageFragmentProvider = BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider(
|
||||
storageManager, builtInsModule, BUILT_INS_PACKAGE_FQ_NAMES,
|
||||
getClassDescriptorFactories(),
|
||||
|
||||
@@ -26,8 +26,6 @@ interface ModuleDescriptor : DeclarationDescriptor {
|
||||
|
||||
val builtIns: KotlinBuiltIns
|
||||
|
||||
val platformKind: PlatformKind
|
||||
|
||||
val sourceKind: SourceKind
|
||||
|
||||
fun shouldSeeInternalsOf(targetModule: ModuleDescriptor): Boolean
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.descriptors
|
||||
|
||||
enum class PlatformKind {
|
||||
DEFAULT,
|
||||
JVM,
|
||||
JS
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.getMultiTargetPlatform
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.lang.IllegalArgumentException
|
||||
@@ -29,9 +31,10 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
moduleName: Name,
|
||||
private val storageManager: StorageManager,
|
||||
override val builtIns: KotlinBuiltIns,
|
||||
override val platformKind: PlatformKind = PlatformKind.DEFAULT,
|
||||
// May be null in compiler context, should be not-null in IDE context
|
||||
multiTargetPlatform: MultiTargetPlatform? = null,
|
||||
override val sourceKind: SourceKind = SourceKind.NONE,
|
||||
private val capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap()
|
||||
capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap()
|
||||
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor {
|
||||
init {
|
||||
if (!moduleName.isSpecial) {
|
||||
@@ -39,6 +42,8 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private val capabilities = capabilities + (multiTargetPlatform?.let { mapOf(MultiTargetPlatform.CAPABILITY to it) } ?: emptyMap())
|
||||
|
||||
private var dependencies: ModuleDependencies? = null
|
||||
private var packageFragmentProviderForModuleContent: PackageFragmentProvider? = null
|
||||
|
||||
@@ -81,9 +86,9 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
fun setDependencies(dependencies: ModuleDependencies) {
|
||||
assert(this.dependencies == null) { "Dependencies of $id were already set" }
|
||||
this.dependencies = dependencies
|
||||
if (platformKind == PlatformKind.DEFAULT) return
|
||||
if (getMultiTargetPlatform() == MultiTargetPlatform.Common) return
|
||||
for (dependencyModule in allDependencyModules) {
|
||||
if (dependencyModule.platformKind != PlatformKind.DEFAULT) continue
|
||||
if (dependencyModule.getMultiTargetPlatform() != MultiTargetPlatform.Common) continue
|
||||
if (dependencyModule.sourceKind != sourceKind) continue
|
||||
(dependencyModule as? ModuleDescriptorImpl)?.allImplementingModules?.add(this)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.MemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
|
||||
sealed class MultiTargetPlatform : Comparable<MultiTargetPlatform> {
|
||||
object Common : MultiTargetPlatform() {
|
||||
override fun compareTo(other: MultiTargetPlatform): Int =
|
||||
if (other is Common) 0 else -1
|
||||
}
|
||||
|
||||
data class Specific(val platform: String) : MultiTargetPlatform() {
|
||||
override fun compareTo(other: MultiTargetPlatform): Int =
|
||||
when (other) {
|
||||
is Common -> 1
|
||||
is Specific -> platform.compareTo(other.platform)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CAPABILITY = ModuleDescriptor.Capability<MultiTargetPlatform>("MULTI_TARGET_PLATFORM")
|
||||
}
|
||||
}
|
||||
|
||||
fun ModuleDescriptor.getMultiTargetPlatform(): MultiTargetPlatform? =
|
||||
module.getCapability(MultiTargetPlatform.CAPABILITY)
|
||||
|
||||
fun MemberDescriptor.getMultiTargetPlatform(): String? =
|
||||
(module.getMultiTargetPlatform() as? MultiTargetPlatform.Specific)?.platform
|
||||
@@ -50,12 +50,6 @@ public class ErrorUtils {
|
||||
private static final ModuleDescriptor ERROR_MODULE;
|
||||
static {
|
||||
ERROR_MODULE = new ModuleDescriptor() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PlatformKind getPlatformKind() {
|
||||
return PlatformKind.DEFAULT;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SourceKind getSourceKind() {
|
||||
|
||||
Reference in New Issue
Block a user