Infrastructure change: module descriptor now knows its platform kind & its sources kind
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.jvm.platform
|
package org.jetbrains.kotlin.resolve.jvm.platform
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.PlatformKind
|
||||||
import org.jetbrains.kotlin.platform.JvmBuiltIns
|
import org.jetbrains.kotlin.platform.JvmBuiltIns
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.ImportPath
|
import org.jetbrains.kotlin.resolve.ImportPath
|
||||||
@@ -47,4 +48,7 @@ object JvmPlatform : TargetPlatform("JVM") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val platformConfigurator: PlatformConfigurator = JvmPlatformConfigurator
|
override val platformConfigurator: PlatformConfigurator = JvmPlatformConfigurator
|
||||||
|
|
||||||
|
override val kind: PlatformKind
|
||||||
|
get() = PlatformKind.JVM
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.container.ComponentProvider
|
|||||||
import org.jetbrains.kotlin.context.ModuleContext
|
import org.jetbrains.kotlin.context.ModuleContext
|
||||||
import org.jetbrains.kotlin.context.ProjectContext
|
import org.jetbrains.kotlin.context.ProjectContext
|
||||||
import org.jetbrains.kotlin.context.withModule
|
import org.jetbrains.kotlin.context.withModule
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
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.LazyModuleDependencies
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
@@ -56,7 +53,7 @@ abstract class ResolverForProject<M : ModuleInfo> {
|
|||||||
abstract val name: String
|
abstract val name: String
|
||||||
abstract val allModules: Collection<M>
|
abstract val allModules: Collection<M>
|
||||||
|
|
||||||
override fun toString() = "$name"
|
override fun toString() = name
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmptyResolverForProject<M : ModuleInfo> : ResolverForProject<M>() {
|
class EmptyResolverForProject<M : ModuleInfo> : ResolverForProject<M>() {
|
||||||
@@ -160,8 +157,10 @@ abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
|||||||
targetEnvironment: TargetEnvironment = CompilerEnvironment,
|
targetEnvironment: TargetEnvironment = CompilerEnvironment,
|
||||||
builtIns: KotlinBuiltIns = DefaultBuiltIns.Instance,
|
builtIns: KotlinBuiltIns = DefaultBuiltIns.Instance,
|
||||||
delegateResolver: ResolverForProject<M> = EmptyResolverForProject(),
|
delegateResolver: ResolverForProject<M> = EmptyResolverForProject(),
|
||||||
packagePartProviderFactory: (M, ModuleContent) -> PackagePartProvider = { module, content -> PackagePartProvider.Empty },
|
packagePartProviderFactory: (M, ModuleContent) -> PackagePartProvider = { _, _ -> PackagePartProvider.Empty },
|
||||||
firstDependency: M? = null
|
firstDependency: M? = null,
|
||||||
|
modulePlatforms: (M) -> PlatformKind = { PlatformKind.DEFAULT },
|
||||||
|
moduleSources: (M) -> SourceKind = { SourceKind.NONE }
|
||||||
): ResolverForProject<M> {
|
): ResolverForProject<M> {
|
||||||
val storageManager = projectContext.storageManager
|
val storageManager = projectContext.storageManager
|
||||||
fun createResolverForProject(): ResolverForProjectImpl<M> {
|
fun createResolverForProject(): ResolverForProjectImpl<M> {
|
||||||
@@ -169,7 +168,8 @@ abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
|||||||
modules.forEach {
|
modules.forEach {
|
||||||
module ->
|
module ->
|
||||||
descriptorByModule[module] =
|
descriptorByModule[module] =
|
||||||
ModuleDescriptorImpl(module.name, storageManager, builtIns, module.capabilities)
|
ModuleDescriptorImpl(module.name, storageManager, builtIns,
|
||||||
|
modulePlatforms(module), moduleSources(module), module.capabilities)
|
||||||
}
|
}
|
||||||
return ResolverForProjectImpl(debugName, descriptorByModule, delegateResolver)
|
return ResolverForProjectImpl(debugName, descriptorByModule, delegateResolver)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve
|
|||||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||||
import org.jetbrains.kotlin.container.composeContainer
|
import org.jetbrains.kotlin.container.composeContainer
|
||||||
import org.jetbrains.kotlin.container.useInstance
|
import org.jetbrains.kotlin.container.useInstance
|
||||||
|
import org.jetbrains.kotlin.descriptors.PlatformKind
|
||||||
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
|
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.*
|
import org.jetbrains.kotlin.resolve.calls.checkers.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||||
@@ -34,6 +35,8 @@ abstract class TargetPlatform(val platformName: String) {
|
|||||||
abstract val platformConfigurator: PlatformConfigurator
|
abstract val platformConfigurator: PlatformConfigurator
|
||||||
abstract val defaultImports: List<ImportPath>
|
abstract val defaultImports: List<ImportPath>
|
||||||
|
|
||||||
|
abstract val kind: PlatformKind
|
||||||
|
|
||||||
object Default : TargetPlatform("Default") {
|
object Default : TargetPlatform("Default") {
|
||||||
override val defaultImports: List<ImportPath> = ArrayList<ImportPath>().apply {
|
override val defaultImports: List<ImportPath> = ArrayList<ImportPath>().apply {
|
||||||
add(ImportPath("kotlin.*"))
|
add(ImportPath("kotlin.*"))
|
||||||
@@ -55,6 +58,9 @@ abstract class TargetPlatform(val platformName: String) {
|
|||||||
container.useInstance(TypeSpecificityComparator.NONE)
|
container.useInstance(TypeSpecificityComparator.NONE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val kind: PlatformKind
|
||||||
|
get() = PlatformKind.DEFAULT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,7 @@ import org.jetbrains.kotlin.context.ContextKt;
|
|||||||
import org.jetbrains.kotlin.context.GlobalContext;
|
import org.jetbrains.kotlin.context.GlobalContext;
|
||||||
import org.jetbrains.kotlin.context.ModuleContext;
|
import org.jetbrains.kotlin.context.ModuleContext;
|
||||||
import org.jetbrains.kotlin.context.SimpleGlobalContext;
|
import org.jetbrains.kotlin.context.SimpleGlobalContext;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackagePartProvider;
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.CompositePackageFragmentProvider;
|
import org.jetbrains.kotlin.descriptors.impl.CompositePackageFragmentProvider;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||||
import org.jetbrains.kotlin.diagnostics.*;
|
import org.jetbrains.kotlin.diagnostics.*;
|
||||||
@@ -562,7 +559,9 @@ public abstract class AbstractDiagnosticsTest extends BaseDiagnosticsTest {
|
|||||||
? Collections.emptyMap()
|
? Collections.emptyMap()
|
||||||
: Collections.singletonMap(MultiTargetPlatform.CAPABILITY, platform);
|
: Collections.singletonMap(MultiTargetPlatform.CAPABILITY, platform);
|
||||||
return new ModuleDescriptorImpl(
|
return new ModuleDescriptorImpl(
|
||||||
Name.special("<" + moduleName + ">"), storageManager, new JvmBuiltIns(storageManager), capabilities
|
Name.special("<" + moduleName + ">"), storageManager, new JvmBuiltIns(storageManager),
|
||||||
|
platform == MultiTargetPlatform.Common.INSTANCE ? PlatformKind.DEFAULT : PlatformKind.JVM,
|
||||||
|
SourceKind.TEST, capabilities
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ interface ModuleDescriptor : DeclarationDescriptor {
|
|||||||
|
|
||||||
val builtIns: KotlinBuiltIns
|
val builtIns: KotlinBuiltIns
|
||||||
|
|
||||||
|
val platformKind: PlatformKind
|
||||||
|
|
||||||
|
val sourceKind: SourceKind
|
||||||
|
|
||||||
fun shouldSeeInternalsOf(targetModule: ModuleDescriptor): Boolean
|
fun shouldSeeInternalsOf(targetModule: ModuleDescriptor): Boolean
|
||||||
|
|
||||||
override fun substitute(substitutor: TypeSubstitutor): ModuleDescriptor {
|
override fun substitute(substitutor: TypeSubstitutor): ModuleDescriptor {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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 SourceKind {
|
||||||
|
NONE,
|
||||||
|
PRODUCTION,
|
||||||
|
TEST
|
||||||
|
}
|
||||||
@@ -17,9 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.descriptors.impl
|
package org.jetbrains.kotlin.descriptors.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -31,6 +29,8 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
|
|||||||
moduleName: Name,
|
moduleName: Name,
|
||||||
private val storageManager: StorageManager,
|
private val storageManager: StorageManager,
|
||||||
override val builtIns: KotlinBuiltIns,
|
override val builtIns: KotlinBuiltIns,
|
||||||
|
override val platformKind: PlatformKind = PlatformKind.DEFAULT,
|
||||||
|
override val sourceKind: SourceKind = SourceKind.NONE,
|
||||||
private val capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap()
|
private val capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap()
|
||||||
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor {
|
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor {
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -49,6 +49,18 @@ public class ErrorUtils {
|
|||||||
private static final ModuleDescriptor ERROR_MODULE;
|
private static final ModuleDescriptor ERROR_MODULE;
|
||||||
static {
|
static {
|
||||||
ERROR_MODULE = new ModuleDescriptor() {
|
ERROR_MODULE = new ModuleDescriptor() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PlatformKind getPlatformKind() {
|
||||||
|
return PlatformKind.DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public SourceKind getSourceKind() {
|
||||||
|
return SourceKind.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public <T> T getCapability(@NotNull Capability<T> capability) {
|
public <T> T getCapability(@NotNull Capability<T> capability) {
|
||||||
|
|||||||
+16
-1
@@ -29,7 +29,10 @@ import org.jetbrains.kotlin.analyzer.ResolverForProject
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.context.GlobalContextImpl
|
import org.jetbrains.kotlin.context.GlobalContextImpl
|
||||||
import org.jetbrains.kotlin.context.withProject
|
import org.jetbrains.kotlin.context.withProject
|
||||||
|
import org.jetbrains.kotlin.descriptors.PlatformKind
|
||||||
|
import org.jetbrains.kotlin.descriptors.SourceKind
|
||||||
import org.jetbrains.kotlin.idea.project.IdeaEnvironment
|
import org.jetbrains.kotlin.idea.project.IdeaEnvironment
|
||||||
|
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
@@ -72,7 +75,19 @@ fun createModuleResolverProvider(
|
|||||||
debugName, globalContext.withProject(project), modulesToCreateResolversFor, modulesContent,
|
debugName, globalContext.withProject(project), modulesToCreateResolversFor, modulesContent,
|
||||||
jvmPlatformParameters, IdeaEnvironment, builtIns,
|
jvmPlatformParameters, IdeaEnvironment, builtIns,
|
||||||
delegateResolver, { m, c -> IDEPackagePartProvider(c.moduleContentScope) },
|
delegateResolver, { m, c -> IDEPackagePartProvider(c.moduleContentScope) },
|
||||||
sdk?.let { SdkInfo(project, it) }
|
sdk?.let { SdkInfo(project, it) },
|
||||||
|
modulePlatforms = { moduleInfo ->
|
||||||
|
val module = (moduleInfo as? ModuleSourceInfo)?.module
|
||||||
|
module?.let { TargetPlatformDetector.getPlatform(module).kind } ?: PlatformKind.DEFAULT
|
||||||
|
},
|
||||||
|
moduleSources = { moduleInfo ->
|
||||||
|
when (moduleInfo) {
|
||||||
|
is ModuleProductionSourceInfo -> SourceKind.PRODUCTION
|
||||||
|
is ModuleTestSourceInfo -> SourceKind.TEST
|
||||||
|
else -> SourceKind.NONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
)
|
)
|
||||||
return resolverForProject
|
return resolverForProject
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.js.resolve
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.descriptors.PlatformKind
|
||||||
import org.jetbrains.kotlin.resolve.ImportPath
|
import org.jetbrains.kotlin.resolve.ImportPath
|
||||||
import org.jetbrains.kotlin.resolve.PlatformConfigurator
|
import org.jetbrains.kotlin.resolve.PlatformConfigurator
|
||||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||||
@@ -29,4 +30,8 @@ object JsPlatform : TargetPlatform("JS") {
|
|||||||
|
|
||||||
val builtIns: KotlinBuiltIns
|
val builtIns: KotlinBuiltIns
|
||||||
get() = DefaultBuiltIns.Instance
|
get() = DefaultBuiltIns.Instance
|
||||||
|
|
||||||
|
override val kind: PlatformKind
|
||||||
|
get() = PlatformKind.JS
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user