MPP: Refactoring, extract IDE platform kinds, allow to add custom platforms

This commit is contained in:
Yan Zhulanow
2018-08-30 18:46:59 +05:00
parent cf1b2bedf4
commit d00f5b335a
81 changed files with 1327 additions and 844 deletions
@@ -0,0 +1,33 @@
/*
* 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.extensions
import com.intellij.openapi.extensions.ExtensionPoint
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.extensions.Extensions
open class ApplicationExtensionDescriptor<T>(name: String, private val extensionClass: Class<T>) {
val extensionPointName: ExtensionPointName<T> = ExtensionPointName.create(name)
fun registerExtensionPoint() {
Extensions.getRootArea().registerExtensionPoint(
extensionPointName.name,
extensionClass.name,
ExtensionPoint.Kind.INTERFACE
)
}
fun registerExtension(extension: T) {
Extensions.getRootArea().getExtensionPoint(extensionPointName).registerExtension(extension)
}
fun getInstances(): List<T> {
val projectArea = Extensions.getRootArea()
if (!projectArea.hasExtensionPoint(extensionPointName.name)) return listOf()
return projectArea.getExtensionPoint(extensionPointName).extensions.toList()
}
}
@@ -0,0 +1,25 @@
/*
* 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.caches.resolve
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
import org.jetbrains.kotlin.analyzer.common.CommonAnalyzerFacade
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.context.GlobalContextImpl
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
class CommonPlatformKindResolution : IdePlatformKindResolution {
override val kind get() = CommonIdePlatformKind
override val resolverForModuleFactory: ResolverForModuleFactory
get() = CommonAnalyzerFacade
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
return DefaultBuiltIns.Instance
}
}
@@ -0,0 +1,59 @@
/*
* 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.caches.resolve
import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.context.GlobalContextImpl
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
import org.jetbrains.kotlin.platform.IdePlatformKind
interface IdePlatformKindResolution {
val kind: IdePlatformKind<*>
val resolverForModuleFactory: ResolverForModuleFactory
fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns
companion object : ApplicationExtensionDescriptor<IdePlatformKindResolution>(
"org.jetbrains.kotlin.idePlatformKindResolution", IdePlatformKindResolution::class.java
) {
private val CACHED_RESOLUTION_SUPPORT by lazy {
val allPlatformKinds = IdePlatformKind.ALL_KINDS
val groupedResolution = IdePlatformKindResolution.getInstances().groupBy { it.kind }.mapValues { it.value.single() }
for (kind in allPlatformKinds) {
if (kind !in groupedResolution) {
throw IllegalStateException(
"Resolution support for the platform '$kind' is missing. " +
"Implement 'IdePlatformKindResolution' for it."
)
}
}
groupedResolution
}
fun getResolution(kind: IdePlatformKind<*>): IdePlatformKindResolution {
return CACHED_RESOLUTION_SUPPORT[kind] ?: error("Unknown platform $this")
}
}
}
val IdePlatformKind<*>.resolution: IdePlatformKindResolution
get() = IdePlatformKindResolution.getResolution(this)
@@ -1,126 +0,0 @@
/*
* 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.caches.resolve
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
import org.jetbrains.kotlin.analyzer.common.CommonAnalyzerFacade
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.context.GlobalContextImpl
import org.jetbrains.kotlin.idea.caches.resolve.JsAnalyzerFacade
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
abstract class IdePlatformSupport {
abstract val platform: TargetPlatform
abstract val resolverForModuleFactory: ResolverForModuleFactory
abstract val libraryKind: PersistentLibraryKind<*>?
abstract fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns
abstract fun isModuleForPlatform(module: Module): Boolean
companion object {
val EP_NAME = ExtensionPointName.create<IdePlatformSupport>("org.jetbrains.kotlin.idePlatformSupport")
val platformSupport by lazy {
Extensions.getExtensions(EP_NAME).associateBy { it.platform }
}
val facades by lazy {
Extensions.getExtensions(EP_NAME).map { it.platform to it.resolverForModuleFactory }.toMap()
}
@JvmStatic
fun getPlatformForModule(module: Module): TargetPlatform {
return Extensions.getExtensions(EP_NAME).find { it.isModuleForPlatform(module) }?.platform ?: JvmPlatform
}
}
}
class JvmPlatformSupport : IdePlatformSupport() {
override val platform: TargetPlatform
get() = JvmPlatform
override val resolverForModuleFactory: ResolverForModuleFactory
get() = JvmAnalyzerFacade
override val libraryKind: PersistentLibraryKind<*>?
get() = null
override fun isModuleForPlatform(module: Module): Boolean {
val settings = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module)
return settings.targetPlatformKind is TargetPlatformKind.Jvm
}
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
return if (settings.sdk != null) JvmBuiltIns(sdkContext.storageManager) else DefaultBuiltIns.Instance
}
}
class JsPlatformSupport : IdePlatformSupport() {
override val platform: TargetPlatform
get() = JsPlatform
override val resolverForModuleFactory: ResolverForModuleFactory
get() = JsAnalyzerFacade
override val libraryKind: PersistentLibraryKind<*>?
get() = JSLibraryKind
override fun isModuleForPlatform(module: Module): Boolean {
val settings = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module)
return settings.targetPlatformKind is TargetPlatformKind.JavaScript
}
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
return JsPlatform.builtIns
}
}
class CommonPlatformSupport : IdePlatformSupport() {
override val platform: TargetPlatform
get() = TargetPlatform.Common
override val resolverForModuleFactory: ResolverForModuleFactory
get() = CommonAnalyzerFacade
override val libraryKind: PersistentLibraryKind<*>?
get() = CommonLibraryKind
override fun isModuleForPlatform(module: Module): Boolean {
val settings = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module)
return settings.targetPlatformKind is TargetPlatformKind.Common
}
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
return DefaultBuiltIns.Instance
}
}
@@ -0,0 +1,25 @@
/*
* 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.caches.resolve
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.context.GlobalContextImpl
import org.jetbrains.kotlin.idea.caches.resolve.JsAnalyzerFacade
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
class JsPlatformKindResolution : IdePlatformKindResolution {
override val kind get() = JsIdePlatformKind
override val resolverForModuleFactory: ResolverForModuleFactory
get() = JsAnalyzerFacade
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
return JsPlatform.builtIns
}
}
@@ -0,0 +1,26 @@
/*
* 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.caches.resolve
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
import org.jetbrains.kotlin.context.GlobalContextImpl
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
class JvmPlatformKindResolution : IdePlatformKindResolution {
override val kind get() = JvmIdePlatformKind
override val resolverForModuleFactory: ResolverForModuleFactory
get() = JvmAnalyzerFacade
override fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
return if (settings.sdk != null) JvmBuiltIns(sdkContext.storageManager) else DefaultBuiltIns.Instance
}
}
@@ -25,10 +25,9 @@ import com.intellij.psi.util.PsiModificationTracker
import com.intellij.util.containers.SLRUCache import com.intellij.util.containers.SLRUCache
import org.jetbrains.kotlin.analyzer.* import org.jetbrains.kotlin.analyzer.*
import org.jetbrains.kotlin.analyzer.common.CommonAnalysisParameters import org.jetbrains.kotlin.analyzer.common.CommonAnalysisParameters
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
import org.jetbrains.kotlin.caches.resolve.IdePlatformSupport import org.jetbrains.kotlin.caches.resolve.resolution
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.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
@@ -39,6 +38,7 @@ import org.jetbrains.kotlin.idea.compiler.IDELanguageSettingsProvider
import org.jetbrains.kotlin.idea.project.IdeaEnvironment import org.jetbrains.kotlin.idea.project.IdeaEnvironment
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.platform.idePlatformKind
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.CompositeBindingContext import org.jetbrains.kotlin.resolve.CompositeBindingContext
@@ -140,7 +140,7 @@ internal class ProjectResolutionFacade(
moduleLanguageSettingsProvider = IDELanguageSettingsProvider, moduleLanguageSettingsProvider = IDELanguageSettingsProvider,
resolverForModuleFactoryByPlatform = { modulePlatform -> resolverForModuleFactoryByPlatform = { modulePlatform ->
val platform = modulePlatform ?: settings.platform val platform = modulePlatform ?: settings.platform
IdePlatformSupport.facades[platform] ?: throw UnsupportedOperationException("Unsupported platform $platform") platform.idePlatformKind.resolution.resolverForModuleFactory
}, },
platformParameters = { platform -> platformParameters = { platform ->
when (platform) { when (platform) {
@@ -212,8 +212,7 @@ internal class ProjectResolutionFacade(
private companion object { private companion object {
private fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns { private fun createBuiltIns(settings: PlatformAnalysisSettings, sdkContext: GlobalContextImpl): KotlinBuiltIns {
val supportInstance = IdePlatformSupport.platformSupport[settings.platform] ?: return DefaultBuiltIns.Instance return settings.platform.idePlatformKind.resolution.createBuiltIns(settings, sdkContext)
return supportInstance.createBuiltIns(settings, sdkContext)
} }
} }
} }
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.config.TargetPlatformVersion
import org.jetbrains.kotlin.idea.caches.project.* import org.jetbrains.kotlin.idea.caches.project.*
import org.jetbrains.kotlin.idea.project.getLanguageVersionSettings import org.jetbrains.kotlin.idea.project.getLanguageVersionSettings
import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.script.KotlinScriptDefinition import org.jetbrains.kotlin.script.KotlinScriptDefinition
import org.jetbrains.kotlin.utils.Jsr305State import org.jetbrains.kotlin.utils.Jsr305State
@@ -74,7 +74,7 @@ object IDELanguageSettingsProvider : LanguageSettingsProvider {
override fun getTargetPlatform(moduleInfo: ModuleInfo, project: Project): TargetPlatformVersion = override fun getTargetPlatform(moduleInfo: ModuleInfo, project: Project): TargetPlatformVersion =
when (moduleInfo) { when (moduleInfo) {
is ModuleSourceInfo -> moduleInfo.module.targetPlatform?.version ?: TargetPlatformVersion.NoVersion is ModuleSourceInfo -> moduleInfo.module.platform?.version ?: TargetPlatformVersion.NoVersion
is ScriptModuleInfo -> getLanguageSettingsForScripts(project, moduleInfo.scriptDefinition).targetPlatformVersion is ScriptModuleInfo -> getLanguageSettingsForScripts(project, moduleInfo.scriptDefinition).targetPlatformVersion
is ScriptDependenciesInfo.ForFile -> getLanguageSettingsForScripts(project, moduleInfo.scriptDefinition).targetPlatformVersion is ScriptDependenciesInfo.ForFile -> getLanguageSettingsForScripts(project, moduleInfo.scriptDefinition).targetPlatformVersion
else -> TargetPlatformVersion.NoVersion else -> TargetPlatformVersion.NoVersion
@@ -20,9 +20,9 @@ import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.module.Module import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ModuleRootModel import com.intellij.openapi.roots.ModuleRootModel
import com.intellij.util.text.VersionComparatorUtil import com.intellij.util.text.VersionComparatorUtil
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.platform.orDefault
import org.jetbrains.kotlin.config.VersionView import org.jetbrains.kotlin.config.VersionView
interface KotlinVersionInfoProvider { interface KotlinVersionInfoProvider {
@@ -32,30 +32,30 @@ interface KotlinVersionInfoProvider {
fun getCompilerVersion(module: Module): String? fun getCompilerVersion(module: Module): String?
fun getLibraryVersions( fun getLibraryVersions(
module: Module, module: Module,
targetPlatform: TargetPlatformKind<*>, platformKind: IdePlatformKind<*>,
rootModel: ModuleRootModel? rootModel: ModuleRootModel?
): Collection<String> ): Collection<String>
} }
fun getRuntimeLibraryVersions( fun getRuntimeLibraryVersions(
module: Module, module: Module,
rootModel: ModuleRootModel?, rootModel: ModuleRootModel?,
targetPlatform: TargetPlatformKind<*> platformKind: IdePlatformKind<*>
): Collection<String> { ): Collection<String> {
return KotlinVersionInfoProvider.EP_NAME return KotlinVersionInfoProvider.EP_NAME
.extensions .extensions
.map { it.getLibraryVersions(module, targetPlatform, rootModel) } .map { it.getLibraryVersions(module, platformKind, rootModel) }
.firstOrNull { it.isNotEmpty() } ?: emptyList() .firstOrNull { it.isNotEmpty() } ?: emptyList()
} }
fun getLibraryLanguageLevel( fun getLibraryLanguageLevel(
module: Module, module: Module,
rootModel: ModuleRootModel?, rootModel: ModuleRootModel?,
targetPlatform: TargetPlatformKind<*>?, platformKind: IdePlatformKind<*>?,
coerceRuntimeLibraryVersionToReleased: Boolean = true coerceRuntimeLibraryVersionToReleased: Boolean = true
): LanguageVersion { ): LanguageVersion {
val minVersion = getRuntimeLibraryVersions(module, rootModel, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM) val minVersion = getRuntimeLibraryVersions(module, rootModel, platformKind.orDefault())
.addReleaseVersionIfNecessary(coerceRuntimeLibraryVersionToReleased) .addReleaseVersionIfNecessary(coerceRuntimeLibraryVersionToReleased)
.minWith(VersionComparatorUtil.COMPARATOR) .minWith(VersionComparatorUtil.COMPARATOR)
return getDefaultLanguageLevel(module, minVersion, coerceRuntimeLibraryVersionToReleased) return getDefaultLanguageLevel(module, minVersion, coerceRuntimeLibraryVersionToReleased)
@@ -85,8 +85,8 @@ private fun Iterable<String>.addReleaseVersionIfNecessary(shouldAdd: Boolean): I
if (shouldAdd) this + VersionView.RELEASED_VERSION.versionString else this if (shouldAdd) this + VersionView.RELEASED_VERSION.versionString else this
fun getRuntimeLibraryVersion(module: Module): String? { fun getRuntimeLibraryVersion(module: Module): String? {
val targetPlatform = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module).targetPlatformKind val targetPlatform = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module).platform
val versions = getRuntimeLibraryVersions(module, null, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM) val versions = getRuntimeLibraryVersions(module, null, targetPlatform.orDefault().kind)
return versions.toSet().singleOrNull() return versions.toSet().singleOrNull()
} }
@@ -39,6 +39,11 @@ import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgu
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
import org.jetbrains.kotlin.idea.facet.getLibraryLanguageLevel import org.jetbrains.kotlin.idea.facet.getLibraryLanguageLevel
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.UserDataProperty import org.jetbrains.kotlin.psi.UserDataProperty
@@ -56,7 +61,7 @@ var KtFile.forcedTargetPlatform: TargetPlatform? by UserDataProperty(Key.create(
fun Module.getAndCacheLanguageLevelByDependencies(): LanguageVersion { fun Module.getAndCacheLanguageLevelByDependencies(): LanguageVersion {
val facetSettings = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(this) val facetSettings = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(this)
val languageLevel = getLibraryLanguageLevel(this, null, facetSettings.targetPlatformKind) val languageLevel = getLibraryLanguageLevel(this, null, facetSettings.platform?.kind)
// Preserve inferred version in facet/project settings // Preserve inferred version in facet/project settings
if (facetSettings.useProjectSettings) { if (facetSettings.useProjectSettings) {
@@ -123,7 +128,7 @@ fun Project.getLanguageVersionSettings(
val compilerSettings = KotlinCompilerSettings.getInstance(this).settings val compilerSettings = KotlinCompilerSettings.getInstance(this).settings
val additionalArguments: CommonCompilerArguments = parseArguments( val additionalArguments: CommonCompilerArguments = parseArguments(
TargetPlatformKind.DEFAULT_PLATFORM, DefaultIdeTargetPlatformKindProvider.defaultPlatform,
compilerSettings.additionalArgumentsAsList compilerSettings.additionalArgumentsAsList
) )
@@ -187,7 +192,7 @@ private fun Module.computeLanguageVersionSettings(): LanguageVersionSettings {
val languageFeatures = facetSettings.mergedCompilerArguments?.configureLanguageFeatures(MessageCollector.NONE)?.apply { val languageFeatures = facetSettings.mergedCompilerArguments?.configureLanguageFeatures(MessageCollector.NONE)?.apply {
configureCoroutinesSupport(facetSettings.coroutineSupport, languageVersion) configureCoroutinesSupport(facetSettings.coroutineSupport, languageVersion)
configureMultiplatformSupport(facetSettings.targetPlatformKind, this@computeLanguageVersionSettings) configureMultiplatformSupport(facetSettings.platform?.kind, this@computeLanguageVersionSettings)
}.orEmpty() }.orEmpty()
val analysisFlags = facetSettings.mergedCompilerArguments?.configureAnalysisFlags(MessageCollector.NONE).orEmpty() val analysisFlags = facetSettings.mergedCompilerArguments?.configureAnalysisFlags(MessageCollector.NONE).orEmpty()
@@ -200,33 +205,25 @@ private fun Module.computeLanguageVersionSettings(): LanguageVersionSettings {
) )
} }
val Module.targetPlatform: TargetPlatformKind<*>? val Module.platform: IdePlatform<*, *>?
get() = KotlinFacetSettingsProvider.getInstance(project).getSettings(this)?.targetPlatformKind ?: project.targetPlatform get() = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(this).platform ?: project.platform
val Project.targetPlatform: TargetPlatformKind<*>? val Project.platform: IdePlatform<*, *>?
get() { get() {
val jvmTarget = Kotlin2JvmCompilerArgumentsHolder.getInstance(this).settings.jvmTarget ?: return null val jvmTarget = Kotlin2JvmCompilerArgumentsHolder.getInstance(this).settings.jvmTarget ?: return null
val version = JvmTarget.fromString(jvmTarget) ?: return null val version = JvmTarget.fromString(jvmTarget) ?: return null
return TargetPlatformKind.Jvm[version] return JvmIdePlatformKind.Platform(version)
} }
private val Module.implementsCommonModule: Boolean private val Module.implementsCommonModule: Boolean
get() = targetPlatform != TargetPlatformKind.Common get() = !platform.isCommon
&& ModuleRootManager.getInstance(this).dependencies.any { it.targetPlatform == TargetPlatformKind.Common } && ModuleRootManager.getInstance(this).dependencies.any { it.platform.isCommon }
private fun parseArguments( private fun parseArguments(
targetPlatformKind: TargetPlatformKind<*>, platformKind: IdePlatform<*, *>,
additionalArguments: List<String> additionalArguments: List<String>
): CommonCompilerArguments { ): CommonCompilerArguments {
val arguments = when (targetPlatformKind) { return platformKind.createArguments().also { parseCommandLineArguments(additionalArguments, it) }
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
TargetPlatformKind.Common -> K2MetadataCompilerArguments()
}
parseCommandLineArguments(additionalArguments, arguments)
return arguments
} }
fun MutableMap<LanguageFeature, LanguageFeature.State>.configureCoroutinesSupport( fun MutableMap<LanguageFeature, LanguageFeature.State>.configureCoroutinesSupport(
@@ -242,10 +239,10 @@ fun MutableMap<LanguageFeature, LanguageFeature.State>.configureCoroutinesSuppor
} }
fun MutableMap<LanguageFeature, LanguageFeature.State>.configureMultiplatformSupport( fun MutableMap<LanguageFeature, LanguageFeature.State>.configureMultiplatformSupport(
targetPlatformKind: TargetPlatformKind<*>?, platformKind: IdePlatformKind<*>?,
module: Module? module: Module?
) { ) {
if (targetPlatformKind == TargetPlatformKind.Common || module?.implementsCommonModule == true) { if (platformKind.isCommon || module?.implementsCommonModule == true) {
put(LanguageFeature.MultiPlatformProjects, LanguageFeature.State.ENABLED) put(LanguageFeature.MultiPlatformProjects, LanguageFeature.State.ENABLED)
} }
} }
@@ -23,7 +23,8 @@ import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.CachedValuesManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.caches.resolve.IdePlatformSupport; import org.jetbrains.kotlin.platform.IdePlatform;
import org.jetbrains.kotlin.platform.IdePlatformKindUtil;
import org.jetbrains.kotlin.resolve.TargetPlatform; import org.jetbrains.kotlin.resolve.TargetPlatform;
public class ProjectStructureUtil { public class ProjectStructureUtil {
@@ -36,12 +37,10 @@ public class ProjectStructureUtil {
/* package */ static TargetPlatform getCachedPlatformForModule(@NotNull final Module module) { /* package */ static TargetPlatform getCachedPlatformForModule(@NotNull final Module module) {
CachedValue<TargetPlatform> result = module.getUserData(PLATFORM_FOR_MODULE); CachedValue<TargetPlatform> result = module.getUserData(PLATFORM_FOR_MODULE);
if (result == null) { if (result == null) {
result = CachedValuesManager.getManager(module.getProject()).createCachedValue(new CachedValueProvider<TargetPlatform>() { result = CachedValuesManager.getManager(module.getProject()).createCachedValue(() -> {
@Override IdePlatform<?, ?> platform = IdePlatformKindUtil.orDefault(PlatformKt.getPlatform(module));
public Result<TargetPlatform> compute() { return CachedValueProvider.Result.create(platform.getKind().getCompilerPlatform(),
return Result.create(IdePlatformSupport.getPlatformForModule(module), ProjectRootModificationTracker.getInstance(module.getProject()));
ProjectRootModificationTracker.getInstance(module.getProject()));
}
}, false); }, false);
module.putUserData(PLATFORM_FOR_MODULE, result); module.putUserData(PLATFORM_FOR_MODULE, result);
@@ -14,9 +14,9 @@ import com.intellij.openapi.roots.ModuleRootModel
import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VfsUtilCore
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.core.isAndroidModule import org.jetbrains.kotlin.idea.core.isAndroidModule
import org.jetbrains.kotlin.idea.facet.KotlinFacet import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.plugins.gradle.execution.GradleOrderEnumeratorHandler import org.jetbrains.plugins.gradle.execution.GradleOrderEnumeratorHandler
import org.jetbrains.plugins.gradle.model.ExternalSourceDirectorySet import org.jetbrains.plugins.gradle.model.ExternalSourceDirectorySet
import org.jetbrains.plugins.gradle.service.project.data.ExternalProjectDataCache import org.jetbrains.plugins.gradle.service.project.data.ExternalProjectDataCache
@@ -97,5 +97,5 @@ class AndroidGradleOrderEnumerationHandler(module: Module) : GradleOrderEnumerat
private fun Module.isMultiplatformModule(): Boolean { private fun Module.isMultiplatformModule(): Boolean {
val settings = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(this) val settings = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(this)
return settings.targetPlatformKind is TargetPlatformKind.Common || settings.implementedModuleNames.isNotEmpty() return settings.platform.isCommon || settings.implementedModuleNames.isNotEmpty()
} }
@@ -30,7 +30,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.Library
import org.jetbrains.kotlin.idea.configuration.detectPlatformByPlugin import org.jetbrains.kotlin.idea.configuration.detectPlatformByPlugin
import org.jetbrains.kotlin.idea.framework.detectLibraryKind import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.framework.libraryKind import org.jetbrains.kotlin.idea.platform.tooling
import java.io.File import java.io.File
class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() { class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() {
@@ -43,7 +43,8 @@ class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaMod
modelsProvider: IdeModifiableModelsProvider modelsProvider: IdeModifiableModelsProvider
) { ) {
for (dataNode in toImport) { for (dataNode in toImport) {
val targetLibraryKind = detectPlatformByPlugin(dataNode.parent as DataNode<ModuleData>)?.libraryKind @Suppress("UNCHECKED_CAST")
val targetLibraryKind = detectPlatformByPlugin(dataNode.parent as DataNode<ModuleData>)?.tooling?.libraryKind
if (targetLibraryKind != null) { if (targetLibraryKind != null) {
for (dep in dataNode.data.jarLibraryDependencies) { for (dep in dataNode.data.jarLibraryDependencies) {
val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue
@@ -30,7 +30,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.Library
import org.jetbrains.kotlin.idea.configuration.detectPlatformByPlugin import org.jetbrains.kotlin.idea.configuration.detectPlatformByPlugin
import org.jetbrains.kotlin.idea.framework.detectLibraryKind import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.framework.libraryKind import org.jetbrains.kotlin.idea.platform.tooling
import java.io.File import java.io.File
class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() { class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() {
@@ -43,7 +43,8 @@ class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaMod
modelsProvider: IdeModifiableModelsProvider modelsProvider: IdeModifiableModelsProvider
) { ) {
for (dataNode in toImport) { for (dataNode in toImport) {
val targetLibraryKind = detectPlatformByPlugin(dataNode.parent as DataNode<ModuleData>)?.libraryKind @Suppress("UNCHECKED_CAST")
val targetLibraryKind = detectPlatformByPlugin(dataNode.parent as DataNode<ModuleData>)?.tooling?.libraryKind
if (targetLibraryKind != null) { if (targetLibraryKind != null) {
for (dep in dataNode.data.jarLibraryDependencies) { for (dep in dataNode.data.jarLibraryDependencies) {
val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue
@@ -30,7 +30,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.Library
import org.jetbrains.kotlin.idea.configuration.detectPlatformByPlugin import org.jetbrains.kotlin.idea.configuration.detectPlatformByPlugin
import org.jetbrains.kotlin.idea.framework.detectLibraryKind import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.framework.libraryKind import org.jetbrains.kotlin.idea.platform.tooling
import java.io.File import java.io.File
class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() { class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() {
@@ -43,7 +43,8 @@ class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaMod
modelsProvider: IdeModifiableModelsProvider modelsProvider: IdeModifiableModelsProvider
) { ) {
for (dataNode in toImport) { for (dataNode in toImport) {
val targetLibraryKind = detectPlatformByPlugin(dataNode.parent as DataNode<ModuleData>)?.libraryKind @Suppress("UNCHECKED_CAST")
val targetLibraryKind = detectPlatformByPlugin(dataNode.parent as DataNode<ModuleData>)?.tooling?.libraryKind
if (targetLibraryKind != null) { if (targetLibraryKind != null) {
for (dep in dataNode.data.jarLibraryDependencies) { for (dep in dataNode.data.jarLibraryDependencies) {
val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue
@@ -30,7 +30,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.Library
import org.jetbrains.kotlin.idea.configuration.detectPlatformByPlugin import org.jetbrains.kotlin.idea.configuration.detectPlatformByPlugin
import org.jetbrains.kotlin.idea.framework.detectLibraryKind import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.framework.libraryKind import org.jetbrains.kotlin.idea.platform.tooling
import java.io.File import java.io.File
class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() { class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaModuleModel, Void>() {
@@ -43,7 +43,8 @@ class KotlinAndroidGradleLibraryDataService : AbstractProjectDataService<JavaMod
modelsProvider: IdeModifiableModelsProvider modelsProvider: IdeModifiableModelsProvider
) { ) {
for (dataNode in toImport) { for (dataNode in toImport) {
val targetLibraryKind = detectPlatformByPlugin(dataNode.parent as DataNode<ModuleData>)?.libraryKind @Suppress("UNCHECKED_CAST")
val targetLibraryKind = detectPlatformByPlugin(dataNode.parent as DataNode<ModuleData>)?.tooling?.libraryKind
if (targetLibraryKind != null) { if (targetLibraryKind != null) {
for (dep in dataNode.data.jarLibraryDependencies) { for (dep in dataNode.data.jarLibraryDependencies) {
val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue val library = modelsProvider.findLibraryByBinaryPath(dep.binaryPath) as LibraryEx? ?: continue
@@ -25,6 +25,7 @@ import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.ModifiableModelsProvider import com.intellij.openapi.roots.ModifiableModelsProvider
import com.intellij.openapi.roots.ModifiableRootModel import com.intellij.openapi.roots.ModifiableRootModel
import org.jetbrains.kotlin.idea.KotlinIcons import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.idea.core.platform.impl.CommonIdePlatformKindTooling.MAVEN_COMMON_STDLIB_ID
import org.jetbrains.kotlin.idea.versions.* import org.jetbrains.kotlin.idea.versions.*
import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder
import org.jetbrains.plugins.gradle.frameworkSupport.GradleFrameworkSupportProvider import org.jetbrains.plugins.gradle.frameworkSupport.GradleFrameworkSupportProvider
@@ -36,10 +36,7 @@ import com.intellij.util.PathUtil
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
import org.jetbrains.kotlin.config.CoroutineSupport import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.gradle.ArgsInfo import org.jetbrains.kotlin.gradle.ArgsInfo
import org.jetbrains.kotlin.gradle.CompilerArgumentsBySourceSet import org.jetbrains.kotlin.gradle.CompilerArgumentsBySourceSet
@@ -51,7 +48,12 @@ import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.inspections.gradle.findAll import org.jetbrains.kotlin.idea.inspections.gradle.findAll
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
import org.jetbrains.kotlin.idea.inspections.gradle.getResolvedVersionByModuleData import org.jetbrains.kotlin.idea.inspections.gradle.getResolvedVersionByModuleData
import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.roots.migrateNonJvmSourceFolders import org.jetbrains.kotlin.idea.roots.migrateNonJvmSourceFolders
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.platform.impl.isJavaScript
import org.jetbrains.kotlin.platform.impl.isJvm
import org.jetbrains.kotlin.psi.UserDataProperty import org.jetbrains.kotlin.psi.UserDataProperty
import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
@@ -159,7 +161,9 @@ class KotlinGradleLibraryDataService : AbstractProjectDataService<LibraryData, V
val projectDataNode = toImport.first().parent!! val projectDataNode = toImport.first().parent!!
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
val moduleDataNodes = projectDataNode.children.filter { it.data is ModuleData } as List<DataNode<ModuleData>> val moduleDataNodes = projectDataNode.children.filter { it.data is ModuleData } as List<DataNode<ModuleData>>
val anyNonJvmModules = moduleDataNodes.any { detectPlatformByPlugin(it)?.takeIf { it !is TargetPlatformKind.Jvm } != null } val anyNonJvmModules = moduleDataNodes
.any { node -> detectPlatformByPlugin(node)?.takeIf { !it.isJvm } != null }
for (libraryDataNode in toImport) { for (libraryDataNode in toImport) {
val ideLibrary = modelsProvider.findIdeLibrary(libraryDataNode.data) ?: continue val ideLibrary = modelsProvider.findIdeLibrary(libraryDataNode.data) ?: continue
@@ -198,21 +202,17 @@ class KotlinGradleLibraryDataService : AbstractProjectDataService<LibraryData, V
} }
} }
fun detectPlatformByPlugin(moduleNode: DataNode<ModuleData>): TargetPlatformKind<*>? { fun detectPlatformByPlugin(moduleNode: DataNode<ModuleData>): IdePlatformKind<*>? {
return when (moduleNode.platformPluginId) { val pluginId = moduleNode.platformPluginId
"kotlin-platform-jvm" -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_6] return IdePlatformKind.ALL_KINDS.firstOrNull { it.tooling.gradlePluginId == pluginId }
"kotlin-platform-js" -> TargetPlatformKind.JavaScript
"kotlin-platform-common" -> TargetPlatformKind.Common
else -> null
}
} }
private fun detectPlatformByLibrary(moduleNode: DataNode<ModuleData>): TargetPlatformKind<*>? { private fun detectPlatformByLibrary(moduleNode: DataNode<ModuleData>): IdePlatformKind<*>? {
val detectedPlatforms = val detectedPlatforms =
mavenLibraryIdToPlatform.entries mavenLibraryIdToPlatform.entries
.filter { moduleNode.getResolvedVersionByModuleData(KOTLIN_GROUP_ID, listOf(it.key)) != null } .filter { moduleNode.getResolvedVersionByModuleData(KOTLIN_GROUP_ID, listOf(it.key)) != null }
.map { it.value }.distinct() .map { it.value }.distinct()
return detectedPlatforms.singleOrNull() ?: detectedPlatforms.firstOrNull { it != TargetPlatformKind.Common } return detectedPlatforms.singleOrNull() ?: detectedPlatforms.firstOrNull { !it.isCommon }
} }
@Suppress("unused") // Used in the Android plugin @Suppress("unused") // Used in the Android plugin
@@ -248,12 +248,15 @@ fun configureFacetByGradleModule(
?: return null ?: return null
val platformKind = detectPlatformByPlugin(moduleNode) ?: detectPlatformByLibrary(moduleNode) val platformKind = detectPlatformByPlugin(moduleNode) ?: detectPlatformByLibrary(moduleNode)
// TODO there should be a way to figure out the correct platform version
val platform = platformKind?.defaultPlatform
val coroutinesProperty = CoroutineSupport.byCompilerArgument( val coroutinesProperty = CoroutineSupport.byCompilerArgument(
moduleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project) moduleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project)
) )
val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false, GradleConstants.SYSTEM_ID.id) val kotlinFacet = ideModule.getOrCreateFacet(modelsProvider, false, GradleConstants.SYSTEM_ID.id)
kotlinFacet.configureFacet(compilerVersion, coroutinesProperty, platformKind, modelsProvider) kotlinFacet.configureFacet(compilerVersion, coroutinesProperty, platform, modelsProvider)
if (sourceSetNode == null) { if (sourceSetNode == null) {
ideModule.compilerArgumentsBySourceSet = moduleNode.compilerArgumentsBySourceSet ideModule.compilerArgumentsBySourceSet = moduleNode.compilerArgumentsBySourceSet
@@ -273,7 +276,7 @@ fun configureFacetByGradleModule(
kotlinFacet.noVersionAutoAdvance() kotlinFacet.noVersionAutoAdvance()
if (platformKind != null && platformKind !is TargetPlatformKind.Jvm) { if (platformKind != null && !platformKind.isJvm) {
migrateNonJvmSourceFolders(modelsProvider.getModifiableRootModel(ideModule)) migrateNonJvmSourceFolders(modelsProvider.getModifiableRootModel(ideModule))
} }
@@ -290,8 +293,11 @@ fun configureFacetByCompilerArguments(kotlinFacet: KotlinFacet, argsInfo: ArgsIn
adjustClasspath(kotlinFacet, dependencyClasspath) adjustClasspath(kotlinFacet, dependencyClasspath)
} }
private fun getExplicitOutputPath(moduleNode: DataNode<ModuleData>, platformKind: TargetPlatformKind<*>?, sourceSet: String): String? { private fun getExplicitOutputPath(moduleNode: DataNode<ModuleData>, platformKind: IdePlatformKind<*>?, sourceSet: String): String? {
if (platformKind !== TargetPlatformKind.JavaScript) return null if (!platformKind.isJavaScript) {
return null
}
val k2jsArgumentList = moduleNode.compilerArgumentsBySourceSet?.get(sourceSet)?.currentArguments ?: return null val k2jsArgumentList = moduleNode.compilerArgumentsBySourceSet?.get(sourceSet)?.currentArguments ?: return null
return K2JSCompilerArguments().apply { parseCommandLineArguments(k2jsArgumentList, this) }.outputFile return K2JSCompilerArguments().apply { parseCommandLineArguments(k2jsArgumentList, this) }.outputFile
} }
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.config.CoroutineSupport import org.jetbrains.kotlin.config.CoroutineSupport
import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.KotlinModuleKind import org.jetbrains.kotlin.config.KotlinModuleKind
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.gradle.KotlinCompilation import org.jetbrains.kotlin.gradle.KotlinCompilation
import org.jetbrains.kotlin.gradle.KotlinModule import org.jetbrains.kotlin.gradle.KotlinModule
import org.jetbrains.kotlin.gradle.KotlinPlatform import org.jetbrains.kotlin.gradle.KotlinPlatform
@@ -30,6 +29,9 @@ import org.jetbrains.kotlin.idea.facet.noVersionAutoAdvance
import org.jetbrains.kotlin.idea.inspections.gradle.findAll import org.jetbrains.kotlin.idea.inspections.gradle.findAll
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
import org.jetbrains.kotlin.idea.roots.migrateNonJvmSourceFolders import org.jetbrains.kotlin.idea.roots.migrateNonJvmSourceFolders
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
@@ -81,11 +83,12 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
?.data ?.data
?.let { findKotlinPluginVersion(it) } ?: return ?.let { findKotlinPluginVersion(it) } ?: return
val platformKind = when (kotlinSourceSet.platform) { val platformKind = when (kotlinSourceSet.platform) {
KotlinPlatform.JVM, KotlinPlatform.ANDROID -> TargetPlatformKind.Jvm[JvmTarget.fromString( KotlinPlatform.JVM, KotlinPlatform.ANDROID -> {
sourceSetData.targetCompatibility ?: "" val target = JvmTarget.fromString(sourceSetData.targetCompatibility ?: "") ?: JvmTarget.DEFAULT
) ?: JvmTarget.DEFAULT] JvmIdePlatformKind.Platform(target)
KotlinPlatform.JS -> TargetPlatformKind.JavaScript }
KotlinPlatform.COMMON -> TargetPlatformKind.Common KotlinPlatform.JS -> JsIdePlatformKind.Platform
KotlinPlatform.COMMON -> CommonIdePlatformKind.Platform
} }
val coroutinesProperty = CoroutineSupport.byCompilerArgument( val coroutinesProperty = CoroutineSupport.byCompilerArgument(
mainModuleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project) mainModuleNode.coroutines ?: findKotlinCoroutinesProperty(ideModule.project)
@@ -21,7 +21,8 @@ import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.idea.configuration.KOTLIN_GROUP_ID import org.jetbrains.kotlin.idea.configuration.KOTLIN_GROUP_ID
import org.jetbrains.kotlin.idea.inspections.gradle.GradleHeuristicHelper.PRODUCTION_DEPENDENCY_STATEMENTS import org.jetbrains.kotlin.idea.inspections.gradle.GradleHeuristicHelper.PRODUCTION_DEPENDENCY_STATEMENTS
import org.jetbrains.kotlin.idea.versions.* import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.plugins.gradle.codeInspection.GradleBaseInspection import org.jetbrains.plugins.gradle.codeInspection.GradleBaseInspection
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor
@@ -30,9 +31,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethod
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression
class DifferentStdlibGradleVersionInspection : GradleBaseInspection() { class DifferentStdlibGradleVersionInspection : GradleBaseInspection() {
override fun buildVisitor(): BaseInspectionVisitor = MyVisitor( override fun buildVisitor(): BaseInspectionVisitor = MyVisitor(KOTLIN_GROUP_ID, JvmIdePlatformKind.tooling.mavenLibraryIds)
KOTLIN_GROUP_ID, listOf(MAVEN_STDLIB_ID, MAVEN_STDLIB_ID_JRE7, MAVEN_STDLIB_ID_JDK7, MAVEN_STDLIB_ID_JRE8, MAVEN_STDLIB_ID_JDK8)
)
override fun buildErrorString(vararg args: Any) = override fun buildErrorString(vararg args: Any) =
"Plugin version (${args[0]}) is not the same as library version (${args[1]})" "Plugin version (${args[0]}) is not the same as library version (${args[1]})"
@@ -11,8 +11,10 @@ import org.jetbrains.jps.model.java.JavaSourceRootType
import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.KotlinResourceRootType import org.jetbrains.kotlin.config.KotlinResourceRootType
import org.jetbrains.kotlin.config.KotlinSourceRootType import org.jetbrains.kotlin.config.KotlinSourceRootType
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.junit.Test import org.junit.Test
import org.junit.runners.Parameterized import org.junit.runners.Parameterized
@@ -125,7 +127,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
module("app") module("app")
// TODO: Delete metadata modules (after KT-26253 fixed) // TODO: Delete metadata modules (after KT-26253 fixed)
module("app_metadataMain") { module("app_metadataMain") {
platform(TargetPlatformKind.Common) platform(CommonIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("app_commonMain", DependencyScope.COMPILE) moduleDependency("app_commonMain", DependencyScope.COMPILE)
moduleDependency("lib_metadataMain", DependencyScope.COMPILE) moduleDependency("lib_metadataMain", DependencyScope.COMPILE)
@@ -134,7 +136,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("app/build/classes/kotlin/metadata/main", true) outputPath("app/build/classes/kotlin/metadata/main", true)
} }
module("app_metadataTest") { module("app_metadataTest") {
platform(TargetPlatformKind.Common) platform(CommonIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("app_commonMain", DependencyScope.COMPILE) moduleDependency("app_commonMain", DependencyScope.COMPILE)
moduleDependency("app_commonTest", DependencyScope.COMPILE) moduleDependency("app_commonTest", DependencyScope.COMPILE)
@@ -145,14 +147,14 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("app/build/classes/kotlin/metadata/test", false) outputPath("app/build/classes/kotlin/metadata/test", false)
} }
module("app_commonMain") { module("app_commonMain") {
platform(TargetPlatformKind.Common) platform(CommonIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
sourceFolder("app/src/commonMain/kotlin", KotlinSourceRootType.Source) sourceFolder("app/src/commonMain/kotlin", KotlinSourceRootType.Source)
sourceFolder("app/src/commonMain/resources", KotlinResourceRootType.Resource) sourceFolder("app/src/commonMain/resources", KotlinResourceRootType.Resource)
inheritProjectOutput() inheritProjectOutput()
} }
module("app_commonTest") { module("app_commonTest") {
platform(TargetPlatformKind.Common) platform(CommonIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("app_commonMain", DependencyScope.COMPILE) moduleDependency("app_commonMain", DependencyScope.COMPILE)
sourceFolder("app/src/commonTest/kotlin", KotlinSourceRootType.TestSource) sourceFolder("app/src/commonTest/kotlin", KotlinSourceRootType.TestSource)
@@ -160,7 +162,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
inheritProjectOutput() inheritProjectOutput()
} }
module("app_jsMain") { module("app_jsMain") {
platform(TargetPlatformKind.JavaScript) platform(JsIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("lib_jsMain", DependencyScope.COMPILE) moduleDependency("lib_jsMain", DependencyScope.COMPILE)
@@ -170,7 +172,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("app/build/classes/kotlin/js/main", true) outputPath("app/build/classes/kotlin/js/main", true)
} }
module("app_jsTest") { module("app_jsTest") {
platform(TargetPlatformKind.JavaScript) platform(JsIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("lib_jsMain", DependencyScope.COMPILE) moduleDependency("lib_jsMain", DependencyScope.COMPILE)
@@ -182,7 +184,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("app/build/classes/kotlin/js/test", false) outputPath("app/build/classes/kotlin/js/test", false)
} }
module("app_jvmMain") { module("app_jvmMain") {
platform(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6]) platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6))
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
@@ -194,7 +196,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("app/build/classes/kotlin/jvm/main", true) outputPath("app/build/classes/kotlin/jvm/main", true)
} }
module("app_jvmTest") { module("app_jvmTest") {
platform(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6]) platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6))
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
@@ -208,7 +210,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("app/build/classes/kotlin/jvm/test", false) outputPath("app/build/classes/kotlin/jvm/test", false)
} }
module("app_main") { module("app_main") {
platform(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8]) platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8))
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
@@ -218,7 +220,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
inheritProjectOutput() inheritProjectOutput()
} }
module("app_test") { module("app_test") {
platform(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8]) platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8))
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
@@ -230,7 +232,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
} }
module("lib") module("lib")
module("lib_metadataMain") { module("lib_metadataMain") {
platform(TargetPlatformKind.Common) platform(CommonIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("lib_commonMain", DependencyScope.COMPILE) moduleDependency("lib_commonMain", DependencyScope.COMPILE)
sourceFolder("lib/src/metadataMain/kotlin", KotlinSourceRootType.Source) sourceFolder("lib/src/metadataMain/kotlin", KotlinSourceRootType.Source)
@@ -238,7 +240,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("lib/build/classes/kotlin/metadata/main", true) outputPath("lib/build/classes/kotlin/metadata/main", true)
} }
module("lib_metadataTest") { module("lib_metadataTest") {
platform(TargetPlatformKind.Common) platform(CommonIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("lib_commonMain", DependencyScope.COMPILE) moduleDependency("lib_commonMain", DependencyScope.COMPILE)
moduleDependency("lib_commonTest", DependencyScope.COMPILE) moduleDependency("lib_commonTest", DependencyScope.COMPILE)
@@ -248,14 +250,14 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("lib/build/classes/kotlin/metadata/test", false) outputPath("lib/build/classes/kotlin/metadata/test", false)
} }
module("lib_commonMain") { module("lib_commonMain") {
platform(TargetPlatformKind.Common) platform(CommonIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
sourceFolder("lib/src/commonMain/kotlin", KotlinSourceRootType.Source) sourceFolder("lib/src/commonMain/kotlin", KotlinSourceRootType.Source)
sourceFolder("lib/src/commonMain/resources", KotlinResourceRootType.Resource) sourceFolder("lib/src/commonMain/resources", KotlinResourceRootType.Resource)
inheritProjectOutput() inheritProjectOutput()
} }
module("lib_commonTest") { module("lib_commonTest") {
platform(TargetPlatformKind.Common) platform(CommonIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("lib_commonMain", DependencyScope.COMPILE) moduleDependency("lib_commonMain", DependencyScope.COMPILE)
sourceFolder("lib/src/commonTest/kotlin", KotlinSourceRootType.TestSource) sourceFolder("lib/src/commonTest/kotlin", KotlinSourceRootType.TestSource)
@@ -263,7 +265,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
inheritProjectOutput() inheritProjectOutput()
} }
module("lib_jsMain") { module("lib_jsMain") {
platform(TargetPlatformKind.JavaScript) platform(JsIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("lib_commonMain", DependencyScope.COMPILE) moduleDependency("lib_commonMain", DependencyScope.COMPILE)
@@ -272,7 +274,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("lib/build/classes/kotlin/js/main", true) outputPath("lib/build/classes/kotlin/js/main", true)
} }
module("lib_jsTest") { module("lib_jsTest") {
platform(TargetPlatformKind.JavaScript) platform(JsIdePlatformKind.Platform)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
moduleDependency("lib_commonMain", DependencyScope.COMPILE) moduleDependency("lib_commonMain", DependencyScope.COMPILE)
@@ -283,7 +285,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("lib/build/classes/kotlin/js/test", false) outputPath("lib/build/classes/kotlin/js/test", false)
} }
module("lib_jvmMain") { module("lib_jvmMain") {
platform(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6]) platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6))
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
@@ -293,7 +295,7 @@ class NewMultiplatformProjectImportingTest : GradleImportingTestCase() {
outputPath("lib/build/classes/kotlin/jvm/main", true) outputPath("lib/build/classes/kotlin/jvm/main", true)
} }
module("lib_jvmTest") { module("lib_jvmTest") {
platform(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6]) platform(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6))
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", DependencyScope.COMPILE)
libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE) libraryDependency("Gradle: org.jetbrains:annotations:13.0", DependencyScope.COMPILE)
@@ -13,9 +13,9 @@ import com.intellij.openapi.roots.*
import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.jps.model.module.JpsModuleSourceRootType import org.jetbrains.jps.model.module.JpsModuleSourceRootType
import org.jetbrains.jps.util.JpsPathUtil import org.jetbrains.jps.util.JpsPathUtil
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.platform.IdePlatform
class MessageCollector { class MessageCollector {
private val builder = StringBuilder() private val builder = StringBuilder()
@@ -100,8 +100,8 @@ class ModuleInfo(
} }
} }
fun platform(platform: TargetPlatformKind<*>) { fun platform(platform: IdePlatform<*, *>) {
val actualPlatform = module.targetPlatform val actualPlatform = module.platform
if (actualPlatform != platform) { if (actualPlatform != platform) {
messageCollector.report( messageCollector.report(
"Module '${module.name}': expected platform '${platform.description}' but found '${actualPlatform?.description}'" "Module '${module.name}': expected platform '${platform.description}' but found '${actualPlatform?.description}'"
@@ -48,6 +48,9 @@ import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.idea.util.projectStructure.sdk import org.jetbrains.kotlin.idea.util.projectStructure.sdk
import org.jetbrains.kotlin.js.resolve.JsPlatform import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.platform.impl.isJavaScript
import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
@@ -132,7 +135,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -144,7 +147,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -258,7 +261,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -268,7 +271,7 @@ compileTestKotlin {
with(testFacetSettings) { with(testFacetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -346,7 +349,7 @@ compileTestKotlin {
with(facetSettings("project_myMain")) { with(facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -356,7 +359,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -439,7 +442,7 @@ compileTestKotlin {
with(facetSettings("project_myMain")) { with(facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -449,7 +452,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -594,7 +597,7 @@ compileTestKotlin {
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(true, sourceMap) Assert.assertEquals(true, sourceMap)
Assert.assertEquals("plain", moduleKind) Assert.assertEquals("plain", moduleKind)
@@ -610,7 +613,7 @@ compileTestKotlin {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(false, sourceMap) Assert.assertEquals(false, sourceMap)
Assert.assertEquals("umd", moduleKind) Assert.assertEquals("umd", moduleKind)
@@ -680,7 +683,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project_main")) val rootManager = ModuleRootManager.getInstance(getModule("project_main"))
@@ -761,7 +764,7 @@ compileTestKotlin {
with(facetSettings("project_myMain")) { with(facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(true, sourceMap) Assert.assertEquals(true, sourceMap)
Assert.assertEquals("plain", moduleKind) Assert.assertEquals("plain", moduleKind)
@@ -775,7 +778,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(false, sourceMap) Assert.assertEquals(false, sourceMap)
Assert.assertEquals("umd", moduleKind) Assert.assertEquals("umd", moduleKind)
@@ -832,7 +835,7 @@ compileTestKotlin {
importProject() importProject()
with(facetSettings) { with(facetSettings) {
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
} }
@@ -864,7 +867,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
} }
Assert.assertEquals( Assert.assertEquals(
@@ -915,7 +918,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project_main")) val rootManager = ModuleRootManager.getInstance(getModule("project_main"))
@@ -974,7 +977,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project_main")) val rootManager = ModuleRootManager.getInstance(getModule("project_main"))
@@ -1031,7 +1034,7 @@ compileTestKotlin {
with(facetSettings("project")) { with(facetSettings("project")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -1077,7 +1080,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
} }
Assert.assertEquals( Assert.assertEquals(
@@ -1122,7 +1125,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
Assert.assertEquals( Assert.assertEquals(
@@ -1396,7 +1399,7 @@ compileTestKotlin {
importProject() importProject()
with(facetSettings("js-module")) { with(facetSettings("js-module")) {
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
val rootManager = ModuleRootManager.getInstance(getModule("js-module")) val rootManager = ModuleRootManager.getInstance(getModule("js-module"))
@@ -2081,7 +2084,7 @@ compileTestKotlin {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
Assert.assertEquals("my/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath) Assert.assertEquals("my/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath)
Assert.assertEquals("my/destination", (compilerArguments as K2MetadataCompilerArguments).destination) Assert.assertEquals("my/destination", (compilerArguments as K2MetadataCompilerArguments).destination)
} }
@@ -2091,7 +2094,7 @@ compileTestKotlin {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
Assert.assertEquals("my/test/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath) Assert.assertEquals("my/test/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath)
Assert.assertEquals("my/test/destination", (compilerArguments as K2MetadataCompilerArguments).destination) Assert.assertEquals("my/test/destination", (compilerArguments as K2MetadataCompilerArguments).destination)
} }
@@ -44,11 +44,15 @@ import org.jetbrains.kotlin.idea.framework.KotlinSdkType
import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.idea.util.projectStructure.sdk import org.jetbrains.kotlin.idea.util.projectStructure.sdk
import org.jetbrains.kotlin.js.resolve.JsPlatform import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.platform.impl.isJavaScript
import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import java.util.*
internal fun GradleImportingTestCase.facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings internal fun GradleImportingTestCase.facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings
@@ -101,7 +105,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -114,7 +118,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -215,7 +219,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -226,7 +230,7 @@ compileTestKotlin {
with (testFacetSettings) { with (testFacetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -293,7 +297,7 @@ compileTestKotlin {
with (facetSettings("project_myMain")) { with (facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -303,7 +307,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -373,7 +377,7 @@ compileTestKotlin {
with (facetSettings("project_myMain")) { with (facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -383,7 +387,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -590,7 +594,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -658,7 +662,7 @@ compileTestKotlin {
with (facetSettings("project_myMain")) { with (facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(true, sourceMap) Assert.assertEquals(true, sourceMap)
Assert.assertEquals("plain", moduleKind) Assert.assertEquals("plain", moduleKind)
@@ -672,7 +676,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(false, sourceMap) Assert.assertEquals(false, sourceMap)
Assert.assertEquals("umd", moduleKind) Assert.assertEquals("umd", moduleKind)
@@ -716,7 +720,7 @@ compileTestKotlin {
importProject() importProject()
with(facetSettings) { with(facetSettings) {
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
} }
@@ -748,7 +752,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
} }
} }
@@ -786,7 +790,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -832,7 +836,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -876,7 +880,7 @@ compileTestKotlin {
with(facetSettings("project")) { with(facetSettings("project")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -913,7 +917,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
} }
} }
@@ -945,7 +949,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
} }
@@ -1888,7 +1892,7 @@ compileTestKotlin {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
Assert.assertEquals("my/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath) Assert.assertEquals("my/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath)
Assert.assertEquals("my/destination", (compilerArguments as K2MetadataCompilerArguments).destination) Assert.assertEquals("my/destination", (compilerArguments as K2MetadataCompilerArguments).destination)
} }
@@ -1898,7 +1902,7 @@ compileTestKotlin {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
Assert.assertEquals("my/test/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath) Assert.assertEquals("my/test/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath)
Assert.assertEquals("my/test/destination", (compilerArguments as K2MetadataCompilerArguments).destination) Assert.assertEquals("my/test/destination", (compilerArguments as K2MetadataCompilerArguments).destination)
} }
@@ -44,11 +44,15 @@ import org.jetbrains.kotlin.idea.framework.KotlinSdkType
import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.idea.util.projectStructure.sdk import org.jetbrains.kotlin.idea.util.projectStructure.sdk
import org.jetbrains.kotlin.js.resolve.JsPlatform import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.platform.impl.isJavaScript
import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import java.util.*
internal fun GradleImportingTestCase.facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings internal fun GradleImportingTestCase.facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings
@@ -101,7 +105,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -114,7 +118,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -215,7 +219,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -226,7 +230,7 @@ compileTestKotlin {
with (testFacetSettings) { with (testFacetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -293,7 +297,7 @@ compileTestKotlin {
with (facetSettings("project_myMain")) { with (facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -303,7 +307,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -373,7 +377,7 @@ compileTestKotlin {
with (facetSettings("project_myMain")) { with (facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), platform)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmp -Xsingle-module", "-Xdump-declarations-to=tmp -Xsingle-module",
@@ -383,7 +387,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals( Assert.assertEquals(
"-Xdump-declarations-to=tmpTest", "-Xdump-declarations-to=tmpTest",
@@ -590,7 +594,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -658,7 +662,7 @@ compileTestKotlin {
with (facetSettings("project_myMain")) { with (facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(true, sourceMap) Assert.assertEquals(true, sourceMap)
Assert.assertEquals("plain", moduleKind) Assert.assertEquals("plain", moduleKind)
@@ -672,7 +676,7 @@ compileTestKotlin {
with(facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(false, sourceMap) Assert.assertEquals(false, sourceMap)
Assert.assertEquals("umd", moduleKind) Assert.assertEquals("umd", moduleKind)
@@ -716,7 +720,7 @@ compileTestKotlin {
importProject() importProject()
with(facetSettings) { with(facetSettings) {
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
} }
@@ -748,7 +752,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
} }
} }
@@ -786,7 +790,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -832,7 +836,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -876,7 +880,7 @@ compileTestKotlin {
with(facetSettings("project")) { with(facetSettings("project")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
@@ -913,7 +917,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), platform)
} }
} }
@@ -945,7 +949,7 @@ compileTestKotlin {
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertTrue(platform.isJavaScript)
} }
} }
@@ -1888,7 +1892,7 @@ compileTestKotlin {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
Assert.assertEquals("my/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath) Assert.assertEquals("my/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath)
Assert.assertEquals("my/destination", (compilerArguments as K2MetadataCompilerArguments).destination) Assert.assertEquals("my/destination", (compilerArguments as K2MetadataCompilerArguments).destination)
} }
@@ -1898,7 +1902,7 @@ compileTestKotlin {
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertTrue(platform.isCommon)
Assert.assertEquals("my/test/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath) Assert.assertEquals("my/test/classpath", (compilerArguments as K2MetadataCompilerArguments).classpath)
Assert.assertEquals("my/test/destination", (compilerArguments as K2MetadataCompilerArguments).destination) Assert.assertEquals("my/test/destination", (compilerArguments as K2MetadataCompilerArguments).destination)
} }
+1
View File
@@ -10,6 +10,7 @@ dependencies {
compile(project(":compiler:util")) compile(project(":compiler:util"))
compile(project(":compiler:cli-common")) compile(project(":compiler:cli-common"))
compile(project(":compiler:frontend.java")) compile(project(":compiler:frontend.java"))
compile(project(":js:js.frontend"))
compileOnly(intellijDep()) compileOnly(intellijDep())
compileOnly(intellijDep("jps-standalone")) { includeJars("jps-model") } compileOnly(intellijDep("jps-standalone")) { includeJars("jps-model") }
} }
@@ -20,33 +20,12 @@ import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.module.Module import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.utils.DescriptionAware import org.jetbrains.kotlin.utils.DescriptionAware
sealed class TargetPlatformKind<out Version : TargetPlatformVersion>(
val version: Version,
val name: String
) : DescriptionAware {
override val description = "$name ${version.description}"
class Jvm(version: JvmTarget) : TargetPlatformKind<JvmTarget>(version, "JVM") {
companion object {
val JVM_PLATFORMS by lazy { JvmTarget.values().map(::Jvm) }
operator fun get(version: JvmTarget) = JVM_PLATFORMS[version.ordinal]
}
}
object JavaScript : TargetPlatformKind<TargetPlatformVersion.NoVersion>(TargetPlatformVersion.NoVersion, "JavaScript")
object Common : TargetPlatformKind<TargetPlatformVersion.NoVersion>(TargetPlatformVersion.NoVersion, "Common (experimental)")
companion object {
val ALL_PLATFORMS: List<TargetPlatformKind<*>> by lazy { Jvm.JVM_PLATFORMS + JavaScript + Common }
val DEFAULT_PLATFORM: TargetPlatformKind<*>
get() = Jvm[JvmTarget.DEFAULT]
}
}
object CoroutineSupport { object CoroutineSupport {
@JvmStatic @JvmStatic
fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State = fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State =
@@ -183,15 +162,16 @@ class KotlinFacetSettings {
compilerArguments!!.apiVersion = value?.versionString compilerArguments!!.apiVersion = value?.versionString
} }
val targetPlatformKind: TargetPlatformKind<*>? val platform: IdePlatform<*, *>?
get() = compilerArguments?.let { get() {
when (it) { val compilerArguments = this.compilerArguments
return when (compilerArguments) {
is K2JVMCompilerArguments -> { is K2JVMCompilerArguments -> {
val jvmTarget = it.jvmTarget ?: JvmTarget.DEFAULT.description val jvmTarget = compilerArguments.jvmTarget ?: JvmTarget.DEFAULT.description
TargetPlatformKind.Jvm.JVM_PLATFORMS.firstOrNull { it.version.description >= jvmTarget } JvmIdePlatformKind.platforms.firstOrNull { it.version.description >= jvmTarget }
} }
is K2JSCompilerArguments -> TargetPlatformKind.JavaScript is K2JSCompilerArguments -> JsIdePlatformKind.Platform
is K2MetadataCompilerArguments -> TargetPlatformKind.Common is K2MetadataCompilerArguments -> CommonIdePlatformKind.Platform
else -> null else -> null
} }
} }
@@ -220,22 +200,6 @@ class KotlinFacetSettings {
var sourceSetNames: List<String> = emptyList() var sourceSetNames: List<String> = emptyList()
} }
fun TargetPlatformKind<*>.createCompilerArguments(init: CommonCompilerArguments.() -> Unit = {}): CommonCompilerArguments {
val arguments = when (this) {
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
is TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
is TargetPlatformKind.Common -> K2MetadataCompilerArguments()
}
arguments.init()
if (arguments is K2JVMCompilerArguments) {
arguments.jvmTarget = this@createCompilerArguments.version.description
}
return arguments
}
interface KotlinFacetSettingsProvider { interface KotlinFacetSettingsProvider {
fun getSettings(module: Module): KotlinFacetSettings? fun getSettings(module: Module): KotlinFacetSettings?
fun getInitializedSettings(module: Module): KotlinFacetSettings fun getInitializedSettings(module: Module): KotlinFacetSettings
@@ -25,7 +25,10 @@ import org.jdom.Element
import org.jdom.Text import org.jdom.Text
import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.orDefault
import java.lang.reflect.Modifier import java.lang.reflect.Modifier
import kotlin.reflect.KClass import kotlin.reflect.KClass
import kotlin.reflect.full.superclasses import kotlin.reflect.full.superclasses
@@ -44,8 +47,9 @@ private fun readV1Config(element: Element): KotlinFacetSettings {
val targetPlatformName = versionInfoElement?.getOptionValue("targetPlatformName") val targetPlatformName = versionInfoElement?.getOptionValue("targetPlatformName")
val languageLevel = versionInfoElement?.getOptionValue("languageLevel") val languageLevel = versionInfoElement?.getOptionValue("languageLevel")
val apiLevel = versionInfoElement?.getOptionValue("apiLevel") val apiLevel = versionInfoElement?.getOptionValue("apiLevel")
val targetPlatform = TargetPlatformKind.ALL_PLATFORMS.firstOrNull { it.description == targetPlatformName } val targetPlatform = IdePlatformKind.All_PLATFORMS
?: TargetPlatformKind.Jvm[JvmTarget.DEFAULT] .firstOrNull { it.description == targetPlatformName }
?: JvmIdePlatformKind.defaultPlatform
val compilerInfoElement = element.getOptionBody("compilerInfo") val compilerInfoElement = element.getOptionBody("compilerInfo")
@@ -59,7 +63,7 @@ private fun readV1Config(element: Element): KotlinFacetSettings {
val jvmArgumentsElement = compilerInfoElement?.getOptionBody("k2jvmCompilerArguments") val jvmArgumentsElement = compilerInfoElement?.getOptionBody("k2jvmCompilerArguments")
val jsArgumentsElement = compilerInfoElement?.getOptionBody("k2jsCompilerArguments") val jsArgumentsElement = compilerInfoElement?.getOptionBody("k2jsCompilerArguments")
val compilerArguments = targetPlatform.createCompilerArguments { freeArgs = ArrayList() } val compilerArguments = targetPlatform.createArguments { freeArgs = arrayListOf() }
commonArgumentsElement?.let { XmlSerializer.deserializeInto(compilerArguments, it) } commonArgumentsElement?.let { XmlSerializer.deserializeInto(compilerArguments, it) }
when (compilerArguments) { when (compilerArguments) {
@@ -94,15 +98,17 @@ private fun readV1Config(element: Element): KotlinFacetSettings {
} }
} }
fun Element.getFacetPlatformByConfigurationElement(): TargetPlatformKind<*> { fun Element.getFacetPlatformByConfigurationElement(): IdePlatform<*, *> {
val platformName = getAttributeValue("platform") val platformName = getAttributeValue("platform")
return TargetPlatformKind.ALL_PLATFORMS.firstOrNull { it.description == platformName } ?: TargetPlatformKind.DEFAULT_PLATFORM return IdePlatformKind.All_PLATFORMS
.firstOrNull { it.description == platformName }
.orDefault()
} }
private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings { private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings {
return KotlinFacetSettings().apply { return KotlinFacetSettings().apply {
element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() } element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() }
val platformKind = element.getFacetPlatformByConfigurationElement() val targetPlatform = element.getFacetPlatformByConfigurationElement()
element.getChild("implements")?.let { element.getChild("implements")?.let {
val items = it.getChildren("implement") val items = it.getChildren("implement")
implementedModuleNames = if (items.isNotEmpty()) { implementedModuleNames = if (items.isNotEmpty()) {
@@ -130,7 +136,7 @@ private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings {
XmlSerializer.deserializeInto(compilerSettings!!, it) XmlSerializer.deserializeInto(compilerSettings!!, it)
} }
element.getChild("compilerArguments")?.let { element.getChild("compilerArguments")?.let {
compilerArguments = platformKind.createCompilerArguments { freeArgs = ArrayList() } compilerArguments = targetPlatform.createArguments { freeArgs = ArrayList() }
XmlSerializer.deserializeInto(compilerArguments!!, it) XmlSerializer.deserializeInto(compilerArguments!!, it)
compilerArguments!!.detectVersionAutoAdvance() compilerArguments!!.detectVersionAutoAdvance()
} }
@@ -256,7 +262,7 @@ private fun buildChildElement(element: Element, tag: String, bean: Any, filter:
private fun KotlinFacetSettings.writeLatestConfig(element: Element) { private fun KotlinFacetSettings.writeLatestConfig(element: Element) {
val filter = SkipDefaultsSerializationFilter() val filter = SkipDefaultsSerializationFilter()
targetPlatformKind?.let { platform?.let {
element.setAttribute("platform", it.description) element.setAttribute("platform", it.description)
} }
if (!useProjectSettings) { if (!useProjectSettings) {
@@ -0,0 +1,26 @@
/*
* 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.platform
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ServiceManager
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
interface DefaultIdeTargetPlatformKindProvider {
val defaultPlatform: IdePlatform<*, *>
companion object {
val defaultPlatform: IdePlatform<*, *>
get() {
if (ApplicationManager.getApplication() == null) {
// TODO support passing custom platforms in JPS
return JvmIdePlatformKind.defaultPlatform
}
return ServiceManager.getService(DefaultIdeTargetPlatformKindProvider::class.java).defaultPlatform
}
}
}
@@ -0,0 +1,21 @@
/*
* 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.platform
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.config.TargetPlatformVersion
abstract class IdePlatform<Kind : IdePlatformKind<Kind>, Arguments : CommonCompilerArguments> {
abstract val kind: Kind
abstract val version: TargetPlatformVersion
abstract fun createArguments(init: Arguments.() -> Unit = {}): Arguments
val description
get() = kind.name + " " + version.description
override fun toString() = description
}
@@ -0,0 +1,61 @@
/*
* 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.
*/
@file:JvmName("IdePlatformKindUtil")
package org.jetbrains.kotlin.platform
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.resolve.TargetPlatform
abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
abstract val compilerPlatform: TargetPlatform
abstract val platforms: List<IdePlatform<Kind, *>>
abstract val defaultPlatform: IdePlatform<Kind, *>
abstract val argumentsClass: Class<out CommonCompilerArguments>
abstract val name: String
override fun equals(other: Any?): Boolean = javaClass == other?.javaClass
override fun hashCode(): Int = javaClass.hashCode()
companion object : ApplicationExtensionDescriptor<IdePlatformKind<*>>(
"org.jetbrains.kotlin.idePlatformKind", IdePlatformKind::class.java
) {
// For using only in JPS
private val JPS_KINDS = listOf(JvmIdePlatformKind, JsIdePlatformKind, CommonIdePlatformKind)
val ALL_KINDS by lazy {
if (ApplicationManager.getApplication() == null) {
return@lazy JPS_KINDS
}
val kinds = getInstances()
require(kinds.isNotEmpty()) { "Platform list is empty" }
kinds
}
val All_PLATFORMS by lazy { ALL_KINDS.flatMap { it.platforms } }
val IDE_PLATFORMS_BY_COMPILER_PLATFORMS by lazy { ALL_KINDS.map { it.compilerPlatform to it }.toMap() }
}
}
val TargetPlatform.idePlatformKind: IdePlatformKind<*>
get() = IdePlatformKind.IDE_PLATFORMS_BY_COMPILER_PLATFORMS[this] ?: error("Unknown platform $this")
fun IdePlatformKind<*>?.orDefault(): IdePlatformKind<*> {
return this ?: DefaultIdeTargetPlatformKindProvider.defaultPlatform.kind
}
fun IdePlatform<*, *>?.orDefault(): IdePlatform<*, *> {
return this ?: DefaultIdeTargetPlatformKindProvider.defaultPlatform
}
@@ -0,0 +1,37 @@
/*
* 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.
*/
@file:JvmName("CommonIdePlatformUtil")
package org.jetbrains.kotlin.platform.impl
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.config.TargetPlatformVersion
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.resolve.TargetPlatform
object CommonIdePlatformKind : IdePlatformKind<CommonIdePlatformKind>() {
override val compilerPlatform get() = TargetPlatform.Common
override val platforms get() = listOf(Platform)
override val defaultPlatform get() = Platform
override val argumentsClass get() = K2MetadataCompilerArguments::class.java
override val name get() = "Common (experimental)"
object Platform : IdePlatform<CommonIdePlatformKind, CommonCompilerArguments>() {
override val kind get() = CommonIdePlatformKind
override val version get() = TargetPlatformVersion.NoVersion
override fun createArguments(init: CommonCompilerArguments.() -> Unit) = K2MetadataCompilerArguments().apply(init)
}
}
val IdePlatformKind<*>?.isCommon
get() = this is CommonIdePlatformKind
val IdePlatform<*, *>?.isCommon
get() = this is CommonIdePlatformKind.Platform
@@ -0,0 +1,12 @@
/*
* 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.platform.impl
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
class IdeaDefaultIdeTargetPlatformKindProvider private constructor() : DefaultIdeTargetPlatformKindProvider {
override val defaultPlatform = JvmIdePlatformKind.defaultPlatform
}
@@ -0,0 +1,36 @@
/*
* 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.
*/
@file:JvmName("JsIdePlatformUtil")
package org.jetbrains.kotlin.platform.impl
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.config.TargetPlatformVersion
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
override val compilerPlatform get() = JsPlatform
override val platforms get() = listOf(Platform)
override val defaultPlatform get() = Platform
override val argumentsClass get() = K2JSCompilerArguments::class.java
override val name get() = "JavaScript"
object Platform : IdePlatform<JsIdePlatformKind, K2JSCompilerArguments>() {
override val kind get() = JsIdePlatformKind
override val version get() = TargetPlatformVersion.NoVersion
override fun createArguments(init: K2JSCompilerArguments.() -> Unit) = K2JSCompilerArguments().apply(init)
}
}
val IdePlatformKind<*>?.isJavaScript
get() = this is JsIdePlatformKind
val IdePlatform<*, *>?.isJavaScript
get() = this is JsIdePlatformKind.Platform
@@ -0,0 +1,38 @@
/*
* 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.
*/
@file:JvmName("JvmIdePlatformUtil")
package org.jetbrains.kotlin.platform.impl
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
object JvmIdePlatformKind : IdePlatformKind<JvmIdePlatformKind>() {
override val compilerPlatform get() = JvmPlatform
override val platforms = JvmTarget.values().map { ver -> Platform(ver) }
override val defaultPlatform get() = Platform(JvmTarget.JVM_1_6)
override val argumentsClass get() = K2JVMCompilerArguments::class.java
override val name get() = "JVM"
data class Platform(override val version: JvmTarget) : IdePlatform<JvmIdePlatformKind, K2JVMCompilerArguments>() {
override val kind get() = JvmIdePlatformKind
override fun createArguments(init: K2JVMCompilerArguments.() -> Unit) = K2JVMCompilerArguments()
.apply(init)
.apply { jvmTarget = this@Platform.version.description }
}
}
val IdePlatformKind<*>?.isJvm
get() = this is JvmIdePlatformKind
val IdePlatform<*, *>?.isJvm
get() = this is JvmIdePlatformKind.Platform
@@ -29,7 +29,6 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.Library
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.facet.getOrCreateFacet import org.jetbrains.kotlin.idea.facet.getOrCreateFacet
import org.jetbrains.kotlin.idea.facet.initializeIfNeeded import org.jetbrains.kotlin.idea.facet.initializeIfNeeded
@@ -40,6 +39,7 @@ import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.idea.util.projectStructure.sdk import org.jetbrains.kotlin.idea.util.projectStructure.sdk
import org.jetbrains.kotlin.idea.util.projectStructure.version import org.jetbrains.kotlin.idea.util.projectStructure.version
import org.jetbrains.kotlin.idea.versions.LibraryJarDescriptor import org.jetbrains.kotlin.idea.versions.LibraryJarDescriptor
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
@@ -113,7 +113,7 @@ open class KotlinJavaModuleConfigurator protected constructor() : KotlinWithLibr
try { try {
val facet = module.getOrCreateFacet(modelsProvider, useProjectSettings = false, commitModel = true) val facet = module.getOrCreateFacet(modelsProvider, useProjectSettings = false, commitModel = true)
val facetSettings = facet.configuration.settings val facetSettings = facet.configuration.settings
facetSettings.initializeIfNeeded(module, null, TargetPlatformKind.Jvm(JvmTarget.JVM_1_8)) facetSettings.initializeIfNeeded(module, null, JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8))
(facetSettings.compilerArguments as? K2JVMCompilerArguments)?.jvmTarget = "1.8" (facetSettings.compilerArguments as? K2JVMCompilerArguments)?.jvmTarget = "1.8"
} finally { } finally {
modelsProvider.dispose() modelsProvider.dispose()
@@ -25,10 +25,9 @@ import com.intellij.ide.IdeBundle
import com.intellij.openapi.roots.ui.configuration.libraries.AddCustomLibraryDialog import com.intellij.openapi.roots.ui.configuration.libraries.AddCustomLibraryDialog
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager
import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.framework.CommonStandardLibraryDescription import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.idea.framework.JSLibraryStdDescription import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription
import javax.swing.JComponent import javax.swing.JComponent
// Based on com.intellij.facet.impl.ui.libraries.FrameworkLibraryValidatorImpl // Based on com.intellij.facet.impl.ui.libraries.FrameworkLibraryValidatorImpl
@@ -36,27 +35,20 @@ class FrameworkLibraryValidatorWithDynamicDescription(
private val context: LibrariesValidatorContext, private val context: LibrariesValidatorContext,
private val validatorsManager: FacetValidatorsManager, private val validatorsManager: FacetValidatorsManager,
private val libraryCategoryName: String, private val libraryCategoryName: String,
private val getTargetPlatform: () -> TargetPlatformKind<*> private val getPlatform: () -> IdePlatformKind<*>
) : FrameworkLibraryValidator() { ) : FrameworkLibraryValidator() {
private val TargetPlatformKind<*>.libraryDescription: CustomLibraryDescription private val IdePlatformKind<*>.libraryDescription: CustomLibraryDescription
get() { get() = this.tooling.getLibraryDescription(context.module.project)
val project = context.module.project
return when (this) {
is TargetPlatformKind.Jvm -> JavaRuntimeLibraryDescription(project)
is TargetPlatformKind.JavaScript -> JSLibraryStdDescription(project)
is TargetPlatformKind.Common -> CommonStandardLibraryDescription(project)
}
}
private fun checkLibraryIsConfigured(targetPlatform: TargetPlatformKind<*>): Boolean { private fun checkLibraryIsConfigured(platform: IdePlatformKind<*>): Boolean {
// TODO: propose to configure kotlin-stdlib-common once it's available // TODO: propose to configure kotlin-stdlib-common once it's available
if (targetPlatform == TargetPlatformKind.Common) return true if (platform.isCommon) return true
if (KotlinVersionInfoProvider.EP_NAME.extensions.any { if (KotlinVersionInfoProvider.EP_NAME.extensions.any {
it.getLibraryVersions(context.module, targetPlatform, context.rootModel).isNotEmpty() it.getLibraryVersions(context.module, platform, context.rootModel).isNotEmpty()
}) return true }) return true
val libraryDescription = targetPlatform.libraryDescription val libraryDescription = platform.libraryDescription
val libraryKinds = libraryDescription.suitableLibraryKinds val libraryKinds = libraryDescription.suitableLibraryKinds
var found = false var found = false
val presentationManager = LibraryPresentationManager.getInstance() val presentationManager = LibraryPresentationManager.getInstance()
@@ -75,12 +67,12 @@ class FrameworkLibraryValidatorWithDynamicDescription(
} }
override fun check(): ValidationResult { override fun check(): ValidationResult {
val targetPlatform = getTargetPlatform() val targetPlatform = getPlatform()
if (checkLibraryIsConfigured(targetPlatform)) { if (checkLibraryIsConfigured(targetPlatform)) {
val conflictingPlatforms = TargetPlatformKind.ALL_PLATFORMS.filter { val conflictingPlatforms = IdePlatformKind.getInstances()
it != TargetPlatformKind.Common && it.name != targetPlatform.name && checkLibraryIsConfigured(it) .filter { !it.isCommon && it.name != targetPlatform.name && checkLibraryIsConfigured(it) }
}
if (conflictingPlatforms.isNotEmpty()) { if (conflictingPlatforms.isNotEmpty()) {
val platformText = conflictingPlatforms.mapTo(LinkedHashSet()) { it.name }.joinToString() val platformText = conflictingPlatforms.mapTo(LinkedHashSet()) { it.name }.joinToString()
return ValidationResult("Libraries for the following platform are also present in the module dependencies: $platformText") return ValidationResult("Libraries for the following platform are also present in the module dependencies: $platformText")
@@ -20,8 +20,8 @@ import com.intellij.facet.impl.ui.libraries.DelegatingLibrariesValidatorContext
import com.intellij.facet.ui.FacetEditorContext import com.intellij.facet.ui.FacetEditorContext
import com.intellij.facet.ui.FacetEditorValidator import com.intellij.facet.ui.FacetEditorValidator
import com.intellij.facet.ui.FacetValidatorsManager import com.intellij.facet.ui.FacetValidatorsManager
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.facet.KotlinFacetEditorGeneralTab.EditorComponent import org.jetbrains.kotlin.idea.facet.KotlinFacetEditorGeneralTab.EditorComponent
import org.jetbrains.kotlin.platform.IdePlatformKind
class KotlinLibraryValidatorCreator : KotlinFacetValidatorCreator() { class KotlinLibraryValidatorCreator : KotlinFacetValidatorCreator() {
override fun create(editor: EditorComponent, validatorsManager: FacetValidatorsManager, editorContext: FacetEditorContext): FacetEditorValidator { override fun create(editor: EditorComponent, validatorsManager: FacetValidatorsManager, editorContext: FacetEditorContext): FacetEditorValidator {
@@ -29,6 +29,6 @@ class KotlinLibraryValidatorCreator : KotlinFacetValidatorCreator() {
DelegatingLibrariesValidatorContext(editorContext), DelegatingLibrariesValidatorContext(editorContext),
validatorsManager, validatorsManager,
"kotlin" "kotlin"
) { editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*> } ) { editor.targetPlatformComboBox.selectedItem as IdePlatformKind<*> }
} }
} }
@@ -30,7 +30,6 @@ import com.intellij.openapi.roots.libraries.ui.RootDetector
import com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor import com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor
import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.KotlinIcons import org.jetbrains.kotlin.idea.KotlinIcons
import javax.swing.JComponent import javax.swing.JComponent
@@ -83,11 +82,4 @@ class JSLibraryType : LibraryType<DummyLibraryProperties>(JSLibraryKind) {
} }
} }
private fun isAcceptedForJsLibrary(extension: String?) = extension == "js" || extension == "kjsm" private fun isAcceptedForJsLibrary(extension: String?) = extension == "js" || extension == "kjsm"
val TargetPlatformKind<*>.libraryKind: PersistentLibraryKind<*>?
get() = when(this) {
TargetPlatformKind.JavaScript -> JSLibraryKind
TargetPlatformKind.Common -> CommonLibraryKind
else -> null
}
@@ -0,0 +1,62 @@
/*
* 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.idea.core.platform.impl
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.Library
import org.jetbrains.kotlin.analyzer.common.CommonAnalyzerFacade
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.caches.project.implementingModules
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
import org.jetbrains.kotlin.idea.framework.CommonStandardLibraryDescription
import org.jetbrains.kotlin.idea.framework.getCommonRuntimeLibraryVersion
import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling
import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.util.module
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import javax.swing.Icon
object CommonIdePlatformKindTooling : IdePlatformKindTooling() {
const val MAVEN_COMMON_STDLIB_ID = "kotlin-stdlib-common" // TODO: KotlinCommonMavenConfigurator
override val kind = CommonIdePlatformKind
override fun compilerArgumentsForProject(project: Project): CommonCompilerArguments? = null
override val resolverForModuleFactory = CommonAnalyzerFacade
override val mavenLibraryIds = listOf(MAVEN_COMMON_STDLIB_ID)
override val gradlePluginId = "kotlin-platform-common"
override val libraryKind = CommonLibraryKind
override fun getLibraryDescription(project: Project) = CommonStandardLibraryDescription(project)
override fun getLibraryVersionProvider(project: Project): (Library) -> String? {
return ::getCommonRuntimeLibraryVersion
}
override fun getTestIcon(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor): Icon? {
return IdePlatformKindTooling.getInstances()
.asSequence()
.filter { it != this }
.mapNotNull { it.getTestIcon(declaration, descriptor) }
.distinct()
.singleOrNull()
}
override fun acceptsAsEntryPoint(function: KtFunction): Boolean {
val module = function.containingKtFile.module ?: return false
return module.implementingModules.any { implementingModule ->
implementingModule.platform?.kind?.takeIf { !it.isCommon }?.tooling?.acceptsAsEntryPoint(function) ?: false
}
}
}
@@ -0,0 +1,115 @@
/*
* 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.idea.core.platform.impl
import com.intellij.execution.actions.RunConfigurationProducer
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.JsAnalyzerFacade
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.idea.framework.JSLibraryStdDescription
import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil
import org.jetbrains.kotlin.idea.highlighter.KotlinTestRunLineMarkerContributor.Companion.getTestStateIcon
import org.jetbrains.kotlin.idea.js.KotlinJSRunConfigurationDataProvider
import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling
import org.jetbrains.kotlin.idea.util.string.joinWithEscape
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import org.jetbrains.kotlin.utils.PathUtil
import javax.swing.Icon
class JsIdePlatformKindTooling : IdePlatformKindTooling() {
companion object {
private const val MAVEN_OLD_JS_STDLIB_ID = "kotlin-js-library"
private val TEST_FQ_NAME = FqName("kotlin.test.Test")
private val IGNORE_FQ_NAME = FqName("kotlin.test.Ignore")
}
override val kind = JsIdePlatformKind
override fun compilerArgumentsForProject(project: Project) = Kotlin2JsCompilerArgumentsHolder.getInstance(project).settings
override val resolverForModuleFactory = JsAnalyzerFacade
override val mavenLibraryIds = listOf(PathUtil.JS_LIB_NAME, MAVEN_OLD_JS_STDLIB_ID)
override val gradlePluginId = "kotlin-platform-js"
override val libraryKind = JSLibraryKind
override fun getLibraryDescription(project: Project) = JSLibraryStdDescription(project)
override fun getLibraryVersionProvider(project: Project) = { library: Library ->
JsLibraryStdDetectionUtil.getJsLibraryStdVersion(library, project)
}
override fun getTestIcon(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor): Icon? {
if (!descriptor.isTest()) return null
val runConfigData = RunConfigurationProducer
.getProducers(declaration.project)
.asSequence()
.filterIsInstance<KotlinJSRunConfigurationDataProvider<*>>()
.filter { it.isForTests }
.mapNotNull { it.getConfigurationData(declaration) }
.firstOrNull() ?: return null
val locations = ArrayList<String>()
locations += FileUtil.toSystemDependentName(runConfigData.jsOutputFilePath)
val klass = when (declaration) {
is KtClassOrObject -> declaration
is KtNamedFunction -> declaration.containingClassOrObject ?: return null
else -> return null
}
locations += klass.parentsWithSelf.filterIsInstance<KtNamedDeclaration>().mapNotNull { it.name }.toList().asReversed()
val testName = (declaration as? KtNamedFunction)?.name
if (testName != null) {
locations += "$testName"
}
val prefix = if (testName != null) "test://" else "suite://"
val url = prefix + locations.joinWithEscape('.')
return getTestStateIcon(url, declaration.project)
}
override fun acceptsAsEntryPoint(function: KtFunction): Boolean {
return RunConfigurationProducer
.getProducers(function.project)
.asSequence()
.filterIsInstance<KotlinJSRunConfigurationDataProvider<*>>()
.filter { !it.isForTests }
.mapNotNull { it.getConfigurationData(function) }
.firstOrNull() != null
}
private fun DeclarationDescriptor.isIgnored(): Boolean =
annotations.any { it.fqName == IGNORE_FQ_NAME } || ((containingDeclaration as? ClassDescriptor)?.isIgnored() ?: false)
private fun DeclarationDescriptor.isTest(): Boolean {
if (isIgnored()) return false
if (annotations.any { it.fqName == TEST_FQ_NAME }) return true
if (this is ClassDescriptorWithResolutionScopes) {
return declaredCallableMembers.any { it.isTest() }
}
return false
}
}
@@ -0,0 +1,80 @@
/*
* 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.idea.core.platform.impl
import com.intellij.codeInsight.TestFrameworks
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil
import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription
import org.jetbrains.kotlin.idea.highlighter.KotlinTestRunLineMarkerContributor.Companion.getTestStateIcon
import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
import org.jetbrains.kotlin.utils.PathUtil
import javax.swing.Icon
class JvmIdePlatformKindTooling : IdePlatformKindTooling() {
override val kind = JvmIdePlatformKind
override fun compilerArgumentsForProject(project: Project) = Kotlin2JvmCompilerArgumentsHolder.getInstance(project).settings
override val resolverForModuleFactory = JvmAnalyzerFacade
override val mavenLibraryIds = listOf(
PathUtil.KOTLIN_JAVA_STDLIB_NAME,
PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME,
PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME,
PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME,
PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME
)
override val gradlePluginId = "kotlin-platform-jvm"
override val libraryKind: PersistentLibraryKind<*>? = null
override fun getLibraryDescription(project: Project) = JavaRuntimeLibraryDescription(project)
override fun getLibraryVersionProvider(project: Project): (Library) -> String? {
return JavaRuntimeDetectionUtil::getJavaRuntimeVersion
}
override fun getTestIcon(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor): Icon? {
val (url, framework) = when (declaration) {
is KtClassOrObject -> {
val lightClass = declaration.toLightClass() ?: return null
val framework = TestFrameworks.detectFramework(lightClass) ?: return null
if (!framework.isTestClass(lightClass)) return null
val qualifiedName = lightClass.qualifiedName ?: return null
"java:suite://$qualifiedName" to framework
}
is KtNamedFunction -> {
val lightMethod = declaration.toLightMethods().firstOrNull() ?: return null
val lightClass = lightMethod.containingClass as? KtLightClass ?: return null
val framework = TestFrameworks.detectFramework(lightClass) ?: return null
if (!framework.isTestMethod(lightMethod)) return null
"java:test://${lightClass.qualifiedName}.${lightMethod.name}" to framework
}
else -> return null
}
return getTestStateIcon(url, declaration.project) ?: framework.icon
}
override fun acceptsAsEntryPoint(function: KtFunction) = true
}
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea.run
import com.intellij.execution.JUnitRecognizer import com.intellij.execution.JUnitRecognizer
import com.intellij.psi.PsiMethod import com.intellij.psi.PsiMethod
import org.jetbrains.kotlin.asJava.elements.KtLightMethod import org.jetbrains.kotlin.asJava.elements.KtLightMethod
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
@@ -27,8 +26,9 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.idea.caches.project.implementingDescriptors import org.jetbrains.kotlin.idea.caches.project.implementingDescriptors
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.util.module import org.jetbrains.kotlin.idea.util.module
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.resolve.descriptorUtil.classId import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
@@ -38,7 +38,7 @@ class KotlinMultiplatformJUnitRecognizer : JUnitRecognizer() {
override fun isTestAnnotated(method: PsiMethod): Boolean { override fun isTestAnnotated(method: PsiMethod): Boolean {
if (method !is KtLightMethod) return false if (method !is KtLightMethod) return false
val origin = method.kotlinOrigin ?: return false val origin = method.kotlinOrigin ?: return false
if (origin.module?.targetPlatform !is TargetPlatformKind.Common) return false if (!origin.module?.platform.isCommon) return false
val moduleDescriptor = origin.containingKtFile.findModuleDescriptor() val moduleDescriptor = origin.containingKtFile.findModuleDescriptor()
val implModules = moduleDescriptor.implementingDescriptors val implModules = moduleDescriptor.implementingDescriptors
@@ -26,14 +26,15 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.util.ClassUtil import com.intellij.psi.util.ClassUtil
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName
import org.jetbrains.kotlin.idea.MainFunctionDetector import org.jetbrains.kotlin.idea.MainFunctionDetector
import org.jetbrains.kotlin.idea.caches.project.implementingModules import org.jetbrains.kotlin.idea.caches.project.implementingModules
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.platform.impl.isJvm
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
@@ -127,6 +128,6 @@ class KotlinRunConfigurationProducer : RunConfigurationProducer<KotlinRunConfigu
} }
fun Module.findJvmImplementationModule(): Module? { fun Module.findJvmImplementationModule(): Module? {
if (targetPlatform != TargetPlatformKind.Common) return null if (!platform.isCommon) return null
return implementingModules.firstOrNull { it.targetPlatform is TargetPlatformKind.Jvm } return implementingModules.firstOrNull { it.platform.isJvm }
} }
@@ -26,7 +26,6 @@ import com.intellij.openapi.roots.*
import com.intellij.openapi.roots.impl.libraries.LibraryEx import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.util.AsyncResult import com.intellij.openapi.util.AsyncResult
import com.intellij.util.PairConsumer
import com.intellij.util.PathUtil import com.intellij.util.PathUtil
import org.jdom.Element import org.jdom.Element
import org.jdom.Text import org.jdom.Text
@@ -38,16 +37,20 @@ import org.jetbrains.jps.model.java.JavaSourceRootType
import org.jetbrains.jps.model.module.JpsModuleSourceRootType import org.jetbrains.jps.model.module.JpsModuleSourceRootType
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.idea.facet.* import org.jetbrains.kotlin.idea.facet.*
import org.jetbrains.kotlin.idea.framework.detectLibraryKind import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.framework.libraryKind
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addIfNotNull
import java.io.File import java.io.File
@@ -105,7 +108,7 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
if (changes.dependencies) { if (changes.dependencies) {
scheduleDownloadStdlibSources(mavenProject, module) scheduleDownloadStdlibSources(mavenProject, module)
val targetLibraryKind = detectPlatformByExecutions(mavenProject)?.libraryKind val targetLibraryKind = detectPlatformByExecutions(mavenProject)?.tooling?.libraryKind
if (targetLibraryKind != null) { if (targetLibraryKind != null) {
modifiableModelsProvider.getModifiableRootModel(module).orderEntries().forEachLibrary { library -> modifiableModelsProvider.getModifiableRootModel(module).orderEntries().forEachLibrary { library ->
if ((library as LibraryEx).kind == null) { if ((library as LibraryEx).kind == null) {
@@ -177,13 +180,9 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
private fun getCompilerArgumentsByConfigurationElement( private fun getCompilerArgumentsByConfigurationElement(
mavenProject: MavenProject, mavenProject: MavenProject,
configuration: Element?, configuration: Element?,
platform: TargetPlatformKind<*> platform: IdePlatform<*, *>
): List<String> { ): List<String> {
val arguments = when (platform) { val arguments = platform.createArguments()
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
TargetPlatformKind.Common -> K2MetadataCompilerArguments()
}
arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?: arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?:
mavenProject.properties["kotlin.compiler.apiVersion"]?.toString() mavenProject.properties["kotlin.compiler.apiVersion"]?.toString()
@@ -252,11 +251,13 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
false, false,
ExternalProjectSystemRegistry.MAVEN_EXTERNAL_SOURCE_ID ExternalProjectSystemRegistry.MAVEN_EXTERNAL_SOURCE_ID
) )
val platform = detectPlatform(mavenProject)
// TODO There should be a way to figure out the correct platform version
val platform = detectPlatform(mavenProject)?.defaultPlatform
kotlinFacet.configureFacet(compilerVersion, LanguageFeature.Coroutines.defaultState, platform, modifiableModelsProvider) kotlinFacet.configureFacet(compilerVersion, LanguageFeature.Coroutines.defaultState, platform, modifiableModelsProvider)
val facetSettings = kotlinFacet.configuration.settings val facetSettings = kotlinFacet.configuration.settings
val configuredPlatform = kotlinFacet.configuration.settings.targetPlatformKind!! val configuredPlatform = kotlinFacet.configuration.settings.platform!!
val configuration = mavenPlugin.configurationElement val configuration = mavenPlugin.configurationElement
val sharedArguments = getCompilerArgumentsByConfigurationElement(mavenProject, configuration, configuredPlatform) val sharedArguments = getCompilerArgumentsByConfigurationElement(mavenProject, configuration, configuredPlatform)
val executionArguments = mavenPlugin.executions val executionArguments = mavenPlugin.executions
@@ -277,22 +278,28 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
private fun detectPlatform(mavenProject: MavenProject) = private fun detectPlatform(mavenProject: MavenProject) =
detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject) detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject)
private fun detectPlatformByExecutions(mavenProject: MavenProject): TargetPlatformKind<*>? { private fun detectPlatformByExecutions(mavenProject: MavenProject): IdePlatformKind<*>? {
return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals } return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals }
?.mapNotNull { goal -> ?.mapNotNull { goal ->
when (goal) { when (goal) {
PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_6] PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> JvmIdePlatformKind
PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> TargetPlatformKind.JavaScript PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> JsIdePlatformKind
PomFile.KotlinGoals.MetaData -> TargetPlatformKind.Common PomFile.KotlinGoals.MetaData -> CommonIdePlatformKind
else -> null else -> null
} }
}?.distinct()?.singleOrNull() }?.distinct()?.singleOrNull()
} }
private fun detectPlatformByLibraries(mavenProject: MavenProject): TargetPlatformKind<*>? { private fun detectPlatformByLibraries(mavenProject: MavenProject): IdePlatformKind<*>? {
return TargetPlatformKind.ALL_PLATFORMS.firstOrNull { for (kind in IdePlatformKind.ALL_KINDS) {
it.mavenLibraryIds.any { mavenProject.findDependencies(KOTLIN_PLUGIN_GROUP_ID, it).isNotEmpty() } val mavenLibraryIds = kind.tooling.mavenLibraryIds
if (mavenLibraryIds.any { mavenProject.findDependencies(KOTLIN_PLUGIN_GROUP_ID, it).isNotEmpty() }) {
// TODO we could return here the correct version
return kind
}
} }
return null
} }
// TODO in theory it should work like this but it doesn't as it couldn't unmark source roots that are not roots anymore. // TODO in theory it should work like this but it doesn't as it couldn't unmark source roots that are not roots anymore.
@@ -362,12 +369,12 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
}.distinct() }.distinct()
private fun setImplementedModuleName(kotlinFacet: KotlinFacet, mavenProject: MavenProject, module: Module) { private fun setImplementedModuleName(kotlinFacet: KotlinFacet, mavenProject: MavenProject, module: Module) {
if (kotlinFacet.configuration.settings.targetPlatformKind == TargetPlatformKind.Common) { if (kotlinFacet.configuration.settings.platform.isCommon) {
kotlinFacet.configuration.settings.implementedModuleNames = emptyList() kotlinFacet.configuration.settings.implementedModuleNames = emptyList()
} else { } else {
val manager = MavenProjectsManager.getInstance(module.project) val manager = MavenProjectsManager.getInstance(module.project)
val mavenDependencies = mavenProject.dependencies.mapNotNull { manager?.findProject(it) } val mavenDependencies = mavenProject.dependencies.mapNotNull { manager?.findProject(it) }
val implemented = mavenDependencies.filter { detectPlatformByExecutions(it) == TargetPlatformKind.Common } val implemented = mavenDependencies.filter { detectPlatformByExecutions(it).isCommon }
kotlinFacet.configuration.settings.implementedModuleNames = implemented.map { manager.findModule(it)?.name ?: it.displayName } kotlinFacet.configuration.settings.implementedModuleNames = implemented.map { manager.findModule(it)?.name ?: it.displayName }
} }
@@ -45,9 +45,14 @@ import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.idea.facet.* import org.jetbrains.kotlin.idea.facet.*
import org.jetbrains.kotlin.idea.framework.detectLibraryKind import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.framework.libraryKind
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addIfNotNull
import java.io.File import java.io.File
@@ -105,7 +110,7 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
if (changes.dependencies) { if (changes.dependencies) {
scheduleDownloadStdlibSources(mavenProject, module) scheduleDownloadStdlibSources(mavenProject, module)
val targetLibraryKind = detectPlatformByExecutions(mavenProject)?.libraryKind val targetLibraryKind = detectPlatformByExecutions(mavenProject)?.tooling?.libraryKind
if (targetLibraryKind != null) { if (targetLibraryKind != null) {
modifiableModelsProvider.getModifiableRootModel(module).orderEntries().forEachLibrary { library -> modifiableModelsProvider.getModifiableRootModel(module).orderEntries().forEachLibrary { library ->
if ((library as LibraryEx).kind == null) { if ((library as LibraryEx).kind == null) {
@@ -177,13 +182,9 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
private fun getCompilerArgumentsByConfigurationElement( private fun getCompilerArgumentsByConfigurationElement(
mavenProject: MavenProject, mavenProject: MavenProject,
configuration: Element?, configuration: Element?,
platform: TargetPlatformKind<*> platform: IdePlatform<*, *>
): List<String> { ): List<String> {
val arguments = when (platform) { val arguments = platform.createArguments()
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
TargetPlatformKind.Common -> K2MetadataCompilerArguments()
}
arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?: arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?:
mavenProject.properties["kotlin.compiler.apiVersion"]?.toString() mavenProject.properties["kotlin.compiler.apiVersion"]?.toString()
@@ -252,11 +253,13 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
false, false,
ExternalProjectSystemRegistry.MAVEN_EXTERNAL_SOURCE_ID ExternalProjectSystemRegistry.MAVEN_EXTERNAL_SOURCE_ID
) )
val platform = detectPlatform(mavenProject)
// TODO There should be a way to figure out the correct platform version
val platform = detectPlatform(mavenProject)?.defaultPlatform
kotlinFacet.configureFacet(compilerVersion, LanguageFeature.Coroutines.defaultState, platform, modifiableModelsProvider) kotlinFacet.configureFacet(compilerVersion, LanguageFeature.Coroutines.defaultState, platform, modifiableModelsProvider)
val facetSettings = kotlinFacet.configuration.settings val facetSettings = kotlinFacet.configuration.settings
val configuredPlatform = kotlinFacet.configuration.settings.targetPlatformKind!! val configuredPlatform = kotlinFacet.configuration.settings.platform!!
val configuration = mavenPlugin.configurationElement val configuration = mavenPlugin.configurationElement
val sharedArguments = getCompilerArgumentsByConfigurationElement(mavenProject, configuration, configuredPlatform) val sharedArguments = getCompilerArgumentsByConfigurationElement(mavenProject, configuration, configuredPlatform)
val executionArguments = mavenPlugin.executions val executionArguments = mavenPlugin.executions
@@ -277,22 +280,28 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
private fun detectPlatform(mavenProject: MavenProject) = private fun detectPlatform(mavenProject: MavenProject) =
detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject) detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject)
private fun detectPlatformByExecutions(mavenProject: MavenProject): TargetPlatformKind<*>? { private fun detectPlatformByExecutions(mavenProject: MavenProject): IdePlatformKind<*>? {
return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals } return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals }
?.mapNotNull { goal -> ?.mapNotNull { goal ->
when (goal) { when (goal) {
PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_6] PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> JvmIdePlatformKind
PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> TargetPlatformKind.JavaScript PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> JsIdePlatformKind
PomFile.KotlinGoals.MetaData -> TargetPlatformKind.Common PomFile.KotlinGoals.MetaData -> CommonIdePlatformKind
else -> null else -> null
} }
}?.distinct()?.singleOrNull() }?.distinct()?.singleOrNull()
} }
private fun detectPlatformByLibraries(mavenProject: MavenProject): TargetPlatformKind<*>? { private fun detectPlatformByLibraries(mavenProject: MavenProject): IdePlatformKind<*>? {
return TargetPlatformKind.ALL_PLATFORMS.firstOrNull { for (kind in IdePlatformKind.ALL_KINDS) {
it.mavenLibraryIds.any { mavenProject.findDependencies(KOTLIN_PLUGIN_GROUP_ID, it).isNotEmpty() } val mavenLibraryIds = kind.tooling.mavenLibraryIds
if (mavenLibraryIds.any { mavenProject.findDependencies(KOTLIN_PLUGIN_GROUP_ID, it).isNotEmpty() }) {
// TODO we could return here the correct version
return kind
}
} }
return null
} }
// TODO in theory it should work like this but it doesn't as it couldn't unmark source roots that are not roots anymore. // TODO in theory it should work like this but it doesn't as it couldn't unmark source roots that are not roots anymore.
@@ -362,12 +371,12 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
}.distinct() }.distinct()
private fun setImplementedModuleName(kotlinFacet: KotlinFacet, mavenProject: MavenProject, module: Module) { private fun setImplementedModuleName(kotlinFacet: KotlinFacet, mavenProject: MavenProject, module: Module) {
if (kotlinFacet.configuration.settings.targetPlatformKind == TargetPlatformKind.Common) { if (kotlinFacet.configuration.settings.platform.isCommon) {
kotlinFacet.configuration.settings.implementedModuleNames = emptyList() kotlinFacet.configuration.settings.implementedModuleNames = emptyList()
} else { } else {
val manager = MavenProjectsManager.getInstance(module.project) val manager = MavenProjectsManager.getInstance(module.project)
val mavenDependencies = mavenProject.dependencies.mapNotNull { manager?.findProject(it) } val mavenDependencies = mavenProject.dependencies.mapNotNull { manager?.findProject(it) }
val implemented = mavenDependencies.filter { detectPlatformByExecutions(it) == TargetPlatformKind.Common } val implemented = mavenDependencies.filter { detectPlatformByExecutions(it).isCommon }
kotlinFacet.configuration.settings.implementedModuleNames = implemented.map { manager.findModule(it)?.name ?: it.displayName } kotlinFacet.configuration.settings.implementedModuleNames = implemented.map { manager.findModule(it)?.name ?: it.displayName }
} }
@@ -31,7 +31,7 @@ import org.jetbrains.idea.maven.project.MavenProject
import org.jetbrains.idea.maven.project.MavenProjectsManager import org.jetbrains.idea.maven.project.MavenProjectsManager
import org.jetbrains.kotlin.idea.maven.PomFile import org.jetbrains.kotlin.idea.maven.PomFile
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID import org.jetbrains.kotlin.utils.PathUtil
class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) { class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) { override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
@@ -44,7 +44,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProj
val manager = MavenProjectsManager.getInstance(module.project) ?: return val manager = MavenProjectsManager.getInstance(module.project) ?: return
val project = manager.findProject(module) ?: return val project = manager.findProject(module) ?: return
val stdlibVersion = project.findDependencies(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID).map { it.version }.distinct() val stdlibVersion = project.findDependencies(KotlinMavenConfigurator.GROUP_ID, PathUtil.KOTLIN_JAVA_STDLIB_NAME).map { it.version }.distinct()
val pluginVersion = project.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID)?.version val pluginVersion = project.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID)?.version
if (pluginVersion == null || stdlibVersion.isEmpty() || stdlibVersion.singleOrNull() == pluginVersion) { if (pluginVersion == null || stdlibVersion.isEmpty() || stdlibVersion.singleOrNull() == pluginVersion) {
@@ -65,7 +65,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProj
) )
} }
pomFile.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID, null)) pomFile.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, PathUtil.KOTLIN_JAVA_STDLIB_NAME, null))
.filter { it.version.stringValue != pluginVersion } .filter { it.version.stringValue != pluginVersion }
.forEach { dependency -> .forEach { dependency ->
val fixes = dependency.version.stringValue?.let { version -> val fixes = dependency.version.stringValue?.let { version ->
@@ -38,19 +38,15 @@ import org.jetbrains.idea.maven.project.MavenProjectsManager
import org.jetbrains.idea.maven.utils.MavenArtifactScope import org.jetbrains.idea.maven.utils.MavenArtifactScope
import org.jetbrains.kotlin.idea.maven.PomFile import org.jetbrains.kotlin.idea.maven.PomFile
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.versions.* import org.jetbrains.kotlin.idea.versions.*
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import java.util.* import java.util.*
class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) { class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
companion object { companion object {
private val STDLIB_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID, null) private val JVM_STDLIB_IDS = JvmIdePlatformKind.tooling
private val STDLIB_JRE7_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JRE7, null) .mavenLibraryIds.map { MavenId(KotlinMavenConfigurator.GROUP_ID, it, null) }
private val STDLIB_JDK7_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JDK7, null)
private val STDLIB_JRE8_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JRE8, null)
private val STDLIB_JDK8_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JDK8, null)
private val JVM_STDLIB_IDS =
listOf(STDLIB_MAVEN_ID, STDLIB_JRE7_MAVEN_ID, STDLIB_JDK7_MAVEN_ID, STDLIB_JRE8_MAVEN_ID, STDLIB_JDK8_MAVEN_ID)
private val JS_STDLIB_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_JS_STDLIB_ID, null) private val JS_STDLIB_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_JS_STDLIB_ID, null)
} }
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.idea.framework.KotlinSdkType
import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.refactoring.toPsiFile import org.jetbrains.kotlin.idea.refactoring.toPsiFile
import org.jetbrains.kotlin.js.resolve.JsPlatform import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.platform.impl.*
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
@@ -491,7 +492,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(true, compilerArguments!!.suppressWarnings) Assert.assertEquals(true, compilerArguments!!.suppressWarnings)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath) Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath)
Assert.assertEquals( Assert.assertEquals(
@@ -612,7 +613,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("1.0", compilerArguments!!.languageVersion) Assert.assertEquals("1.0", compilerArguments!!.languageVersion)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals("1.0", compilerArguments!!.apiVersion) Assert.assertEquals("1.0", compilerArguments!!.apiVersion)
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
} }
@@ -687,7 +688,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(true, compilerArguments!!.suppressWarnings) Assert.assertEquals(true, compilerArguments!!.suppressWarnings)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertTrue(targetPlatformKind == TargetPlatformKind.JavaScript) Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) { with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(true, sourceMap) Assert.assertEquals(true, sourceMap)
Assert.assertEquals("commonjs", moduleKind) Assert.assertEquals("commonjs", moduleKind)
@@ -842,7 +843,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("1.0", compilerArguments!!.apiVersion) Assert.assertEquals("1.0", compilerArguments!!.apiVersion)
Assert.assertEquals(true, compilerArguments!!.suppressWarnings) Assert.assertEquals(true, compilerArguments!!.suppressWarnings)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath) Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath)
Assert.assertEquals("-Xmulti-platform", compilerSettings!!.additionalArguments) Assert.assertEquals("-Xmulti-platform", compilerSettings!!.additionalArguments)
@@ -902,7 +903,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent() assertImporterStatePresent()
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals("c:/program files/jdk1.8", (compilerArguments as K2JVMCompilerArguments).classpath) Assert.assertEquals("c:/program files/jdk1.8", (compilerArguments as K2JVMCompilerArguments).classpath)
@@ -958,7 +959,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent() assertImporterStatePresent()
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals("c:/program files/jdk1.8", (compilerArguments as K2JVMCompilerArguments).classpath) Assert.assertEquals("c:/program files/jdk1.8", (compilerArguments as K2JVMCompilerArguments).classpath)
@@ -1012,7 +1013,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), facetSettings.platform)
assertContentFolders("project", JavaSourceRootType.SOURCE, "src/main/kotlin") assertContentFolders("project", JavaSourceRootType.SOURCE, "src/main/kotlin")
assertContentFolders("project", JavaSourceRootType.TEST_SOURCE, "src/test/java") assertContentFolders("project", JavaSourceRootType.TEST_SOURCE, "src/test/java")
@@ -1067,7 +1068,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), facetSettings.platform)
} }
fun testJvmDetectionByGoalWithCommonStdlib() { fun testJvmDetectionByGoalWithCommonStdlib() {
@@ -1117,7 +1118,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), facetSettings.platform)
assertContentFolders("project", JavaSourceRootType.SOURCE, "src/main/kotlin") assertContentFolders("project", JavaSourceRootType.SOURCE, "src/main/kotlin")
assertContentFolders("project", JavaSourceRootType.TEST_SOURCE, "src/test/java") assertContentFolders("project", JavaSourceRootType.TEST_SOURCE, "src/test/java")
@@ -1172,7 +1173,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isJavaScript)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType) Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1229,7 +1230,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isJavaScript)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType) Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1286,7 +1287,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isJavaScript)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType) Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1348,7 +1349,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isJavaScript)
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
val libraries = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().map { it.library as LibraryEx } val libraries = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().map { it.library as LibraryEx }
@@ -1402,7 +1403,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isCommon)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType) Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1453,7 +1454,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isCommon)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType) Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1504,7 +1505,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isCommon)
val rootManager = ModuleRootManager.getInstance(getModule("project")) val rootManager = ModuleRootManager.getInstance(getModule("project"))
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().single().library val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().single().library
@@ -1565,7 +1566,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), facetSettings.platform)
assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin") assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin")
assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java") assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java")
@@ -1620,7 +1621,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isJavaScript)
assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin") assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin")
assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java") assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java")
@@ -1675,7 +1676,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project") assertModules("project")
assertImporterStatePresent() assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind) Assert.assertTrue(facetSettings.platform.isCommon)
assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin") assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin")
assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java") assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java")
@@ -1889,7 +1890,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent() assertImporterStatePresent()
with(facetSettings) { with(facetSettings) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.1", languageLevel!!.description) Assert.assertEquals("1.1", languageLevel!!.description)
Assert.assertEquals("1.1", apiLevel!!.description) Assert.assertEquals("1.1", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
@@ -2112,7 +2113,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent() assertImporterStatePresent()
with(facetSettings("myModule1")) { with(facetSettings("myModule1")) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.1", languageLevel!!.description) Assert.assertEquals("1.1", languageLevel!!.description)
Assert.assertEquals("1.0", apiLevel!!.description) Assert.assertEquals("1.0", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
@@ -2123,7 +2124,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
} }
with(facetSettings("myModule2")) { with(facetSettings("myModule2")) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.1", languageLevel!!.description) Assert.assertEquals("1.1", languageLevel!!.description)
Assert.assertEquals("1.0", apiLevel!!.description) Assert.assertEquals("1.0", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
@@ -2134,7 +2135,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
} }
with(facetSettings("myModule3")) { with(facetSettings("myModule3")) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description) Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals(LanguageVersion.LATEST_STABLE, languageLevel) Assert.assertEquals(LanguageVersion.LATEST_STABLE, languageLevel)
Assert.assertEquals(LanguageVersion.LATEST_STABLE, apiLevel) Assert.assertEquals(LanguageVersion.LATEST_STABLE, apiLevel)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
@@ -2373,20 +2374,20 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent() assertImporterStatePresent()
with(facetSettings("my-common-module1")) { with(facetSettings("my-common-module1")) {
Assert.assertEquals(TargetPlatformKind.Common.description, targetPlatformKind!!.description) Assert.assertEquals(CommonIdePlatformKind.Platform.description, platform!!.description)
} }
with(facetSettings("my-common-module2")) { with(facetSettings("my-common-module2")) {
Assert.assertEquals(TargetPlatformKind.Common.description, targetPlatformKind!!.description) Assert.assertEquals(CommonIdePlatformKind.Platform.description, platform!!.description)
} }
with(facetSettings("my-jvm-module")) { with(facetSettings("my-jvm-module")) {
Assert.assertEquals(TargetPlatformKind.Jvm(JvmTarget.JVM_1_6).description, targetPlatformKind!!.description) Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6).description, platform!!.description)
Assert.assertEquals(listOf("my-common-module1", "my-common-module2"), implementedModuleNames) Assert.assertEquals(listOf("my-common-module1", "my-common-module2"), implementedModuleNames)
} }
with(facetSettings("my-js-module")) { with(facetSettings("my-js-module")) {
Assert.assertEquals(TargetPlatformKind.JavaScript.description, targetPlatformKind!!.description) Assert.assertEquals(JsIdePlatformKind.Platform.description, platform!!.description)
Assert.assertEquals(listOf("my-common-module1"), implementedModuleNames) Assert.assertEquals(listOf("my-common-module1"), implementedModuleNames)
} }
} }
+10 -5
View File
@@ -15,8 +15,8 @@
interface="org.jetbrains.kotlin.android.model.AndroidModuleInfoProvider" interface="org.jetbrains.kotlin.android.model.AndroidModuleInfoProvider"
area="IDEA_MODULE"/> area="IDEA_MODULE"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformSupport" <extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformKindResolution"
interface="org.jetbrains.kotlin.caches.resolve.IdePlatformSupport"/> interface="org.jetbrains.kotlin.caches.resolve.IdePlatformKindResolution"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.highlighterExtension" <extensionPoint qualifiedName="org.jetbrains.kotlin.highlighterExtension"
interface="org.jetbrains.kotlin.idea.highlighter.HighlighterExtension"/> interface="org.jetbrains.kotlin.idea.highlighter.HighlighterExtension"/>
@@ -37,6 +37,11 @@
interface="org.jetbrains.kotlin.idea.completion.KotlinCompletionExtension"/> interface="org.jetbrains.kotlin.idea.completion.KotlinCompletionExtension"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.buildSystemTypeDetector" <extensionPoint qualifiedName="org.jetbrains.kotlin.buildSystemTypeDetector"
interface="org.jetbrains.kotlin.idea.configuration.BuildSystemTypeDetector"/> interface="org.jetbrains.kotlin.idea.configuration.BuildSystemTypeDetector"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformKind"
interface="org.jetbrains.kotlin.platform.IdePlatformKind"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformKindTooling"
interface="org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling"/>
</extensionPoints> </extensionPoints>
<extensions defaultExtensionNs="org.jetbrains.kotlin"> <extensions defaultExtensionNs="org.jetbrains.kotlin">
@@ -58,9 +63,9 @@
<scriptDefinitionContributor id="ConsoleScriptDefinitionContributor" <scriptDefinitionContributor id="ConsoleScriptDefinitionContributor"
implementation="org.jetbrains.kotlin.console.ConsoleScriptDefinitionContributor"/> implementation="org.jetbrains.kotlin.console.ConsoleScriptDefinitionContributor"/>
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.JvmPlatformSupport"/> <idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.JvmPlatformKindResolution"/>
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.JsPlatformSupport"/> <idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.JsPlatformKindResolution"/>
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.CommonPlatformSupport"/> <idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.CommonPlatformKindResolution"/>
<scratchFileLanguageProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.scratch.KtScratchFileLanguageProvider"/> <scratchFileLanguageProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.scratch.KtScratchFileLanguageProvider"/>
</extensions> </extensions>
+5 -5
View File
@@ -7,8 +7,8 @@
interface="org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension" interface="org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension"
area="IDEA_PROJECT"/> area="IDEA_PROJECT"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformSupport" <extensionPoint qualifiedName="org.jetbrains.kotlin.idePlatformKindResolution"
interface="org.jetbrains.kotlin.caches.resolve.IdePlatformSupport"/> interface="org.jetbrains.kotlin.caches.resolve.IdePlatformKindResolution"/>
<extensionPoint qualifiedName="org.jetbrains.kotlin.highlighterExtension" <extensionPoint qualifiedName="org.jetbrains.kotlin.highlighterExtension"
interface="org.jetbrains.kotlin.idea.highlighter.HighlighterExtension"/> interface="org.jetbrains.kotlin.idea.highlighter.HighlighterExtension"/>
@@ -50,9 +50,9 @@
<scriptDefinitionContributor id="ConsoleScriptDefinitionContributor" <scriptDefinitionContributor id="ConsoleScriptDefinitionContributor"
implementation="org.jetbrains.kotlin.console.ConsoleScriptDefinitionContributor"/> implementation="org.jetbrains.kotlin.console.ConsoleScriptDefinitionContributor"/>
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.JvmPlatformSupport"/> <idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.JvmPlatformKindResolution"/>
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.JsPlatformSupport"/> <idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.JsPlatformKindResolution"/>
<idePlatformSupport implementation="org.jetbrains.kotlin.caches.resolve.CommonPlatformSupport"/> <idePlatformKindResolution implementation="org.jetbrains.kotlin.caches.resolve.CommonPlatformKindResolution"/>
<scratchFileLanguageProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.scratch.KtScratchFileLanguageProvider"/> <scratchFileLanguageProvider language="kotlin" implementationClass="org.jetbrains.kotlin.idea.scratch.KtScratchFileLanguageProvider"/>
</extensions> </extensions>
+10
View File
@@ -131,6 +131,10 @@
<projectService serviceInterface="org.jetbrains.uast.kotlin.KotlinUastResolveProviderService" <projectService serviceInterface="org.jetbrains.uast.kotlin.KotlinUastResolveProviderService"
serviceImplementation="org.jetbrains.uast.kotlin.internal.IdeaKotlinUastResolveProviderService"/> serviceImplementation="org.jetbrains.uast.kotlin.internal.IdeaKotlinUastResolveProviderService"/>
<applicationService
serviceInterface="org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider"
serviceImplementation="org.jetbrains.kotlin.platform.impl.IdeaDefaultIdeTargetPlatformKindProvider"/>
</extensions> </extensions>
<extensions defaultExtensionNs="org.jetbrains.uast"> <extensions defaultExtensionNs="org.jetbrains.uast">
@@ -158,5 +162,11 @@
<gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleKotlinDSLKotlinJavaFrameworkSupportProvider" /> <gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleKotlinDSLKotlinJavaFrameworkSupportProvider" />
<gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleKotlinDSLKotlinJSFrameworkSupportProvider" /> <gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleKotlinDSLKotlinJSFrameworkSupportProvider" />
<gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleGroovyFrameworkSupportProvider" /> <gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleGroovyFrameworkSupportProvider" />
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind"/>
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.JsIdePlatformKind"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.JvmIdePlatformKindTooling"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.JsIdePlatformKindTooling"/>
</extensions> </extensions>
</idea-plugin> </idea-plugin>
+4
View File
@@ -3106,6 +3106,10 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/> <binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/>
<highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/> <highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/>
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.CommonIdePlatformKindTooling"/>
</extensions> </extensions>
<extensions defaultExtensionNs="com.intellij.jvm"> <extensions defaultExtensionNs="com.intellij.jvm">
+4
View File
@@ -3104,6 +3104,10 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/> <binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/>
<highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/> <highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/>
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.CommonIdePlatformKindTooling"/>
</extensions> </extensions>
</idea-plugin> </idea-plugin>
+4
View File
@@ -3105,6 +3105,10 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/> <binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/>
<highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/> <highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/>
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.CommonIdePlatformKindTooling"/>
</extensions> </extensions>
</idea-plugin> </idea-plugin>
+4
View File
@@ -3106,6 +3106,10 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/> <binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/>
<highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/> <highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/>
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.CommonIdePlatformKindTooling"/>
</extensions> </extensions>
<extensions defaultExtensionNs="com.intellij.jvm"> <extensions defaultExtensionNs="com.intellij.jvm">
+4
View File
@@ -3104,6 +3104,10 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/> <binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/>
<highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/> <highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/>
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.CommonIdePlatformKindTooling"/>
</extensions> </extensions>
</idea-plugin> </idea-plugin>
+4
View File
@@ -3106,6 +3106,10 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/> <highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/>
<pluginUpdateVerifier implementation="org.jetbrains.kotlin.idea.update.GooglePluginUpdateVerifier"/> <pluginUpdateVerifier implementation="org.jetbrains.kotlin.idea.update.GooglePluginUpdateVerifier"/>
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.CommonIdePlatformKindTooling"/>
</extensions> </extensions>
</idea-plugin> </idea-plugin>
+4
View File
@@ -3108,6 +3108,10 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
<highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/> <highlighterExtension implementation="org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension"/>
<pluginUpdateVerifier implementation="org.jetbrains.kotlin.idea.update.GooglePluginUpdateVerifier"/> <pluginUpdateVerifier implementation="org.jetbrains.kotlin.idea.update.GooglePluginUpdateVerifier"/>
<idePlatformKind implementation="org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind"/>
<idePlatformKindTooling implementation="org.jetbrains.kotlin.idea.core.platform.impl.CommonIdePlatformKindTooling"/>
</extensions> </extensions>
<extensions defaultExtensionNs="com.intellij.jvm"> <extensions defaultExtensionNs="com.intellij.jvm">
@@ -14,18 +14,17 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.ResolveScopeEnlarger import com.intellij.psi.ResolveScopeEnlarger
import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.SearchScope import com.intellij.psi.search.SearchScope
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.caches.project.implementingModules import org.jetbrains.kotlin.idea.caches.project.implementingModules
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.platform.impl.isJvm
class CommonModuleResolveScopeEnlarger : ResolveScopeEnlarger() { class CommonModuleResolveScopeEnlarger : ResolveScopeEnlarger() {
override fun getAdditionalResolveScope(file: VirtualFile, project: Project): SearchScope? { override fun getAdditionalResolveScope(file: VirtualFile, project: Project): SearchScope? {
val module = ProjectFileIndex.getInstance(project).getModuleForFile(file) val module = ProjectFileIndex.getInstance(project).getModuleForFile(file) ?: return null
if (module?.targetPlatform != TargetPlatformKind.Common) return null if (!module.platform.isCommon) return null
val implementingModule = module.implementingModules.find { val implementingModule = module.implementingModules.find { it.platform.isJvm } ?: return null
it.targetPlatform is TargetPlatformKind.Jvm
} ?: return null
var result = GlobalSearchScope.EMPTY_SCOPE var result = GlobalSearchScope.EMPTY_SCOPE
for (entry in ModuleRootManager.getInstance(implementingModule).orderEntries) { for (entry in ModuleRootManager.getInstance(implementingModule).orderEntries) {
@@ -15,10 +15,8 @@ import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable; import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
import com.intellij.openapi.ui.TextComponentAccessor; import com.intellij.openapi.ui.TextComponentAccessor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.ListCellRendererWrapper; import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.RawCommandLineEditor; import com.intellij.ui.RawCommandLineEditor;
@@ -44,6 +42,11 @@ import org.jetbrains.kotlin.idea.facet.DescriptionListCellRenderer;
import org.jetbrains.kotlin.idea.facet.KotlinFacet; import org.jetbrains.kotlin.idea.facet.KotlinFacet;
import org.jetbrains.kotlin.idea.roots.ProjectRootUtilsKt; import org.jetbrains.kotlin.idea.roots.ProjectRootUtilsKt;
import org.jetbrains.kotlin.idea.util.application.ApplicationUtilsKt; import org.jetbrains.kotlin.idea.util.application.ApplicationUtilsKt;
import org.jetbrains.kotlin.platform.IdePlatform;
import org.jetbrains.kotlin.platform.IdePlatformKind;
import org.jetbrains.kotlin.platform.impl.JsIdePlatformUtil;
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformUtil;
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@@ -353,7 +356,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void fillJvmVersionList() { private void fillJvmVersionList() {
for (TargetPlatformKind.Jvm jvm : TargetPlatformKind.Jvm.Companion.getJVM_PLATFORMS()) { for (IdePlatform<JvmIdePlatformKind, ?> jvm : JvmIdePlatformKind.INSTANCE.getPlatforms()) {
jvmVersionComboBox.addItem(jvm.getVersion().getDescription()); jvmVersionComboBox.addItem(jvm.getVersion().getDescription());
} }
} }
@@ -384,9 +387,9 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
coroutineSupportComboBox.setRenderer(new DescriptionListCellRenderer()); coroutineSupportComboBox.setRenderer(new DescriptionListCellRenderer());
} }
public void setTargetPlatform(@Nullable TargetPlatformKind<?> targetPlatform) { public void setTargetPlatform(@Nullable IdePlatformKind<?> targetPlatform) {
k2jsPanel.setVisible(TargetPlatformKind.JavaScript.INSTANCE.equals(targetPlatform)); k2jsPanel.setVisible(JsIdePlatformUtil.isJavaScript(targetPlatform));
scriptPanel.setVisible(targetPlatform instanceof TargetPlatformKind.Jvm); scriptPanel.setVisible(JvmIdePlatformUtil.isJvm(targetPlatform));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -23,12 +23,13 @@ import com.intellij.ui.HoverHyperlinkLabel
import com.intellij.util.ui.FormBuilder import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.ThreeStateCheckBox import com.intellij.util.ui.ThreeStateCheckBox
import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.config.createCompilerArguments
import org.jetbrains.kotlin.config.splitArgumentString
import org.jetbrains.kotlin.idea.compiler.configuration.* import org.jetbrains.kotlin.idea.compiler.configuration.*
import org.jetbrains.kotlin.idea.util.onTextChange import org.jetbrains.kotlin.idea.util.onTextChange
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.platform.impl.isJavaScript
import org.jetbrains.kotlin.platform.impl.isJvm
import java.awt.BorderLayout import java.awt.BorderLayout
import javax.swing.* import javax.swing.*
import javax.swing.border.EmptyBorder import javax.swing.border.EmptyBorder
@@ -85,7 +86,7 @@ class KotlinFacetEditorGeneralTab(
val useProjectSettingsCheckBox = ThreeStateCheckBox("Use project settings").apply { isThirdStateEnabled = isMultiEditor } val useProjectSettingsCheckBox = ThreeStateCheckBox("Use project settings").apply { isThirdStateEnabled = isMultiEditor }
val targetPlatformComboBox = val targetPlatformComboBox =
JComboBox<TargetPlatformKind<*>>(TargetPlatformKind.ALL_PLATFORMS.toTypedArray()).apply { JComboBox<IdePlatformKind<*>>(IdePlatformKind.ALL_KINDS.toTypedArray()).apply {
setRenderer(DescriptionListCellRenderer()) setRenderer(DescriptionListCellRenderer())
} }
@@ -143,14 +144,14 @@ class KotlinFacetEditorGeneralTab(
compilerConfigurable.reset() compilerConfigurable.reset()
} }
private val chosenPlatform: TargetPlatformKind<*>? private val chosenPlatform: IdePlatformKind<*>?
get() = targetPlatformComboBox.selectedItem as TargetPlatformKind<*>? get() = targetPlatformComboBox.selectedItem as IdePlatformKind<*>?
} }
inner class ArgumentConsistencyValidator : FacetEditorValidator() { inner class ArgumentConsistencyValidator : FacetEditorValidator() {
override fun check(): ValidationResult { override fun check(): ValidationResult {
val platform = editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*>? ?: return ValidationResult.OK val platformKind = editor.targetPlatformComboBox.selectedItem as IdePlatformKind<*>? ?: return ValidationResult.OK
val primaryArguments = platform.createCompilerArguments().apply { val primaryArguments = platformKind.defaultPlatform.createArguments().apply {
editor.compilerConfigurable.applyTo( editor.compilerConfigurable.applyTo(
this, this,
this as? K2JVMCompilerArguments ?: K2JVMCompilerArguments(), this as? K2JVMCompilerArguments ?: K2JVMCompilerArguments(),
@@ -164,10 +165,10 @@ class KotlinFacetEditorGeneralTab(
validateArguments(errors)?.let { message -> return ValidationResult(message) } validateArguments(errors)?.let { message -> return ValidationResult(message) }
} }
val emptyArguments = argumentClass.newInstance() val emptyArguments = argumentClass.newInstance()
val fieldNamesToCheck = when (platform) { val fieldNamesToCheck = when {
is TargetPlatformKind.Jvm -> jvmUIExposedFields platformKind.isJvm -> jvmUIExposedFields
is TargetPlatformKind.JavaScript -> jsUIExposedFields platformKind.isJavaScript -> jsUIExposedFields
is TargetPlatformKind.Common-> metadataUIExposedFields platformKind.isCommon -> metadataUIExposedFields
else -> commonUIExposedFields else -> commonUIExposedFields
} }
@@ -266,14 +267,14 @@ class KotlinFacetEditorGeneralTab(
override fun isModified(): Boolean { override fun isModified(): Boolean {
if (editor.useProjectSettingsCheckBox.isSelected != configuration.settings.useProjectSettings) return true if (editor.useProjectSettingsCheckBox.isSelected != configuration.settings.useProjectSettings) return true
if (editor.targetPlatformComboBox.selectedItem != configuration.settings.targetPlatformKind) return true if (editor.targetPlatformComboBox.selectedItem != configuration.settings.platform) return true
return !editor.useProjectSettingsCheckBox.isSelected && editor.compilerConfigurable.isModified return !editor.useProjectSettingsCheckBox.isSelected && editor.compilerConfigurable.isModified
} }
override fun reset() { override fun reset() {
validateOnce { validateOnce {
editor.useProjectSettingsCheckBox.isSelected = configuration.settings.useProjectSettings editor.useProjectSettingsCheckBox.isSelected = configuration.settings.useProjectSettings
editor.targetPlatformComboBox.selectedItem = configuration.settings.targetPlatformKind editor.targetPlatformComboBox.selectedItem = configuration.settings.platform
editor.compilerConfigurable.reset() editor.compilerConfigurable.reset()
editor.updateCompilerConfigurable() editor.updateCompilerConfigurable()
} }
@@ -284,14 +285,14 @@ class KotlinFacetEditorGeneralTab(
editor.compilerConfigurable.apply() editor.compilerConfigurable.apply()
with(configuration.settings) { with(configuration.settings) {
useProjectSettings = editor.useProjectSettingsCheckBox.isSelected useProjectSettings = editor.useProjectSettingsCheckBox.isSelected
(editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?)?.let { (editor.targetPlatformComboBox.selectedItem as IdePlatformKind<*>?)?.let {
if (it != targetPlatformKind) { if (it != platform) {
val platformArguments = when (it) { val platformArguments = when {
is TargetPlatformKind.Jvm -> editor.compilerConfigurable.k2jvmCompilerArguments it.isJvm -> editor.compilerConfigurable.k2jvmCompilerArguments
is TargetPlatformKind.JavaScript -> editor.compilerConfigurable.k2jsCompilerArguments it.isJavaScript -> editor.compilerConfigurable.k2jsCompilerArguments
else -> null else -> null
} }
compilerArguments = it.createCompilerArguments { compilerArguments = it.defaultPlatform.createArguments {
if (platformArguments != null) { if (platformArguments != null) {
mergeBeans(platformArguments, this) mergeBeans(platformArguments, this)
} }
@@ -20,27 +20,24 @@ import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.LibraryOrderEntry import com.intellij.openapi.roots.LibraryOrderEntry
import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ModuleRootModel import com.intellij.openapi.roots.ModuleRootModel
import com.intellij.openapi.roots.libraries.Library import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil
import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil
import org.jetbrains.kotlin.idea.framework.getCommonRuntimeLibraryVersion
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
import org.jetbrains.kotlin.platform.IdePlatformKind
class KotlinVersionInfoProviderByModuleDependencies : KotlinVersionInfoProvider { class KotlinVersionInfoProviderByModuleDependencies : KotlinVersionInfoProvider {
override fun getCompilerVersion(module: Module) = bundledRuntimeVersion() override fun getCompilerVersion(module: Module) = bundledRuntimeVersion()
override fun getLibraryVersions(module: Module, targetPlatform: TargetPlatformKind<*>, rootModel: ModuleRootModel?): Collection<String> { override fun getLibraryVersions(
val versionProvider: (Library) -> String? = when (targetPlatform) { module: Module,
is TargetPlatformKind.JavaScript -> fun(library: Library) = JsLibraryStdDetectionUtil.getJsLibraryStdVersion(library, module.project) platformKind: IdePlatformKind<*>,
is TargetPlatformKind.Jvm -> JavaRuntimeDetectionUtil::getJavaRuntimeVersion rootModel: ModuleRootModel?
is TargetPlatformKind.Common -> ::getCommonRuntimeLibraryVersion ): Collection<String> {
} val versionProvider = platformKind.tooling.getLibraryVersionProvider(module.project)
return (rootModel ?: ModuleRootManager.getInstance(module)) return (rootModel ?: ModuleRootManager.getInstance(module))
.orderEntries .orderEntries
.asSequence() .asSequence()
.filterIsInstance<LibraryOrderEntry>() .filterIsInstance<LibraryOrderEntry>()
.mapNotNull { it.library?.let { versionProvider(it) } } .mapNotNull { libraryEntry -> libraryEntry.library?.let { versionProvider(it) } }
.toList() .toList()
} }
} }
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.facet
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
import com.intellij.openapi.module.Module import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.JavaSdk import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.projectRoots.JavaSdkVersion import com.intellij.openapi.projectRoots.JavaSdkVersion
import com.intellij.openapi.projectRoots.ProjectJdkTable import com.intellij.openapi.projectRoots.ProjectJdkTable
@@ -30,35 +29,37 @@ import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
import org.jetbrains.kotlin.idea.configuration.externalCompilerVersion import org.jetbrains.kotlin.idea.configuration.externalCompilerVersion
import org.jetbrains.kotlin.idea.framework.KotlinSdkType import org.jetbrains.kotlin.idea.framework.KotlinSdkType
import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.idea.versions.* import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import kotlin.reflect.KProperty1 import kotlin.reflect.KProperty1
private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?): TargetPlatformKind<*> { private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?): IdePlatform<*, *> {
for (platform in TargetPlatformKind.ALL_PLATFORMS) { for (platform in IdePlatformKind.ALL_KINDS) {
if (getRuntimeLibraryVersions(module, rootModel, platform).isNotEmpty()) { if (getRuntimeLibraryVersions(module, rootModel, platform).isNotEmpty()) {
return platform //TODO investigate, looks strange
return platform.defaultPlatform
} }
} }
val sdk = ((rootModel ?: ModuleRootManager.getInstance(module))).sdk val sdk = ((rootModel ?: ModuleRootManager.getInstance(module))).sdk
val sdkVersion = (sdk?.sdkType as? JavaSdk)?.getVersion(sdk!!) val sdkVersion = (sdk?.sdkType as? JavaSdk)?.getVersion(sdk)
return when { return when {
sdkVersion == null || sdkVersion >= JavaSdkVersion.JDK_1_8 -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_8] sdkVersion == null || sdkVersion >= JavaSdkVersion.JDK_1_8 -> JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8)
else -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_6] else -> JvmIdePlatformKind.defaultPlatform
} }
} }
fun KotlinFacetSettings.initializeIfNeeded( fun KotlinFacetSettings.initializeIfNeeded(
module: Module, module: Module,
rootModel: ModuleRootModel?, rootModel: ModuleRootModel?,
platformKind: TargetPlatformKind<*>? = null, // if null, detect by module dependencies platform: IdePlatform<*, *>? = null, // if null, detect by module dependencies
compilerVersion: String? = null compilerVersion: String? = null
) { ) {
val project = module.project val project = module.project
@@ -73,9 +74,9 @@ fun KotlinFacetSettings.initializeIfNeeded(
val commonArguments = KotlinCommonCompilerArgumentsHolder.getInstance(module.project).settings val commonArguments = KotlinCommonCompilerArgumentsHolder.getInstance(module.project).settings
if (compilerArguments == null) { if (compilerArguments == null) {
val targetPlatformKind = platformKind ?: getDefaultTargetPlatform(module, rootModel) val targetPlatform = platform ?: getDefaultTargetPlatform(module, rootModel)
compilerArguments = targetPlatformKind.createCompilerArguments { compilerArguments = targetPlatform.createArguments {
targetPlatformKind.getPlatformCompilerArgumentsByProject(module.project)?.let { mergeBeans(it, this) } targetPlatform.kind.tooling.compilerArgumentsForProject(module.project)?.let { mergeBeans(it, this) }
mergeBeans(commonArguments, this) mergeBeans(commonArguments, this)
} }
} }
@@ -93,7 +94,7 @@ fun KotlinFacetSettings.initializeIfNeeded(
getLibraryLanguageLevel( getLibraryLanguageLevel(
module, module,
rootModel, rootModel,
targetPlatformKind, this.platform?.kind,
coerceRuntimeLibraryVersionToReleased = compilerVersion == null coerceRuntimeLibraryVersionToReleased = compilerVersion == null
) )
) )
@@ -101,30 +102,9 @@ fun KotlinFacetSettings.initializeIfNeeded(
} }
} }
fun TargetPlatformKind<*>.getPlatformCompilerArgumentsByProject(project: Project): CommonCompilerArguments? { val mavenLibraryIdToPlatform: Map<String, IdePlatformKind<*>> by lazy {
return when (this) { IdePlatformKind.ALL_KINDS
is TargetPlatformKind.Jvm -> Kotlin2JvmCompilerArgumentsHolder.getInstance(project).settings .flatMap { platform -> platform.tooling.mavenLibraryIds.map { it to platform } }
is TargetPlatformKind.JavaScript -> Kotlin2JsCompilerArgumentsHolder.getInstance(project).settings
else -> null
}
}
val TargetPlatformKind<*>.mavenLibraryIds: List<String>
get() = when (this) {
is TargetPlatformKind.Jvm -> listOf(
MAVEN_STDLIB_ID,
MAVEN_STDLIB_ID_JRE7,
MAVEN_STDLIB_ID_JDK7,
MAVEN_STDLIB_ID_JRE8,
MAVEN_STDLIB_ID_JDK8
)
is TargetPlatformKind.JavaScript -> listOf(MAVEN_JS_STDLIB_ID, MAVEN_OLD_JS_STDLIB_ID)
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
}
val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
TargetPlatformKind.ALL_PLATFORMS
.flatMap { platform -> platform.mavenLibraryIds.map { it to platform } }
.sortedByDescending { it.first.length } .sortedByDescending { it.first.length }
.toMap() .toMap()
} }
@@ -155,7 +135,7 @@ fun Module.getOrCreateFacet(
fun KotlinFacet.configureFacet( fun KotlinFacet.configureFacet(
compilerVersion: String, compilerVersion: String,
coroutineSupport: LanguageFeature.State, coroutineSupport: LanguageFeature.State,
platformKind: TargetPlatformKind<*>?, // if null, detect by module dependencies platform: IdePlatform<*, *>?, // if null, detect by module dependencies
modelsProvider: IdeModifiableModelsProvider modelsProvider: IdeModifiableModelsProvider
) { ) {
val module = module val module = module
@@ -165,7 +145,7 @@ fun KotlinFacet.configureFacet(
initializeIfNeeded( initializeIfNeeded(
module, module,
modelsProvider.getModifiableRootModel(module), modelsProvider.getModifiableRootModel(module),
platformKind, platform,
compilerVersion compilerVersion
) )
val apiLevel = apiLevel val apiLevel = apiLevel
@@ -28,14 +28,14 @@ import com.intellij.psi.*
import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.caches.lightClasses.KtFakeLightClass import org.jetbrains.kotlin.idea.caches.lightClasses.KtFakeLightClass
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.search.allScope import org.jetbrains.kotlin.idea.search.allScope
import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
import org.jetbrains.kotlin.idea.util.module import org.jetbrains.kotlin.idea.util.module
import org.jetbrains.kotlin.platform.impl.isJvm
import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtConstructor import org.jetbrains.kotlin.psi.KtConstructor
import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtNamedFunction
@@ -46,7 +46,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
class KotlinTypeHierarchyProvider : JavaTypeHierarchyProvider() { class KotlinTypeHierarchyProvider : JavaTypeHierarchyProvider() {
private fun getOriginalPsiClassOrCreateLightClass(classOrObject: KtClassOrObject, module: Module?): PsiClass? { private fun getOriginalPsiClassOrCreateLightClass(classOrObject: KtClassOrObject, module: Module?): PsiClass? {
val fqName = classOrObject.fqName val fqName = classOrObject.fqName
if (fqName != null && module?.targetPlatform is TargetPlatformKind.Jvm) { if (fqName != null && module?.platform.isJvm) {
val javaClassId = JavaToKotlinClassMap.mapKotlinToJava(fqName.toUnsafe()) val javaClassId = JavaToKotlinClassMap.mapKotlinToJava(fqName.toUnsafe())
if (javaClassId != null) { if (javaClassId != null) {
return JavaPsiFacade.getInstance(classOrObject.project).findClass( return JavaPsiFacade.getInstance(classOrObject.project).findClass(
@@ -16,23 +16,16 @@
package org.jetbrains.kotlin.idea.highlighter package org.jetbrains.kotlin.idea.highlighter
import com.intellij.execution.actions.RunConfigurationProducer
import com.intellij.execution.lineMarker.ExecutorAction import com.intellij.execution.lineMarker.ExecutorAction
import com.intellij.execution.lineMarker.RunLineMarkerContributor import com.intellij.execution.lineMarker.RunLineMarkerContributor
import com.intellij.icons.AllIcons import com.intellij.icons.AllIcons
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.MainFunctionDetector import org.jetbrains.kotlin.idea.MainFunctionDetector
import org.jetbrains.kotlin.idea.caches.project.implementingModules
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.js.KotlinJSRunConfigurationDataProvider import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.project.targetPlatform
import org.jetbrains.kotlin.idea.util.module import org.jetbrains.kotlin.idea.util.module
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
class KotlinRunLineMarkerContributor : RunLineMarkerContributor() { class KotlinRunLineMarkerContributor : RunLineMarkerContributor() {
override fun getInfo(element: PsiElement): Info? { override fun getInfo(element: PsiElement): Info? {
@@ -45,34 +38,12 @@ class KotlinRunLineMarkerContributor : RunLineMarkerContributor() {
} }
if (detector.isMain(function)) { if (detector.isMain(function)) {
val platform = function.containingKtFile.module?.targetPlatform ?: return null val platform = function.containingKtFile.module?.platform ?: return null
if (!platform.acceptsAsEntryPoint(function)) return null if (!platform.kind.tooling.acceptsAsEntryPoint(function)) return null
return RunLineMarkerContributor.Info(AllIcons.RunConfigurations.TestState.Run, null, ExecutorAction.getActions(0)) return RunLineMarkerContributor.Info(AllIcons.RunConfigurations.TestState.Run, null, ExecutorAction.getActions(0))
} }
return null return null
} }
private fun TargetPlatformKind<*>.acceptsAsEntryPoint(function: KtNamedFunction): Boolean {
return when (this) {
is TargetPlatformKind.Common -> {
val module = function.containingKtFile.module ?: return false
return module.implementingModules.any { implementingModule ->
implementingModule.targetPlatform?.takeIf { it !is TargetPlatformKind.Common }?.acceptsAsEntryPoint(function) ?: false
}
}
is TargetPlatformKind.Jvm -> true
is TargetPlatformKind.JavaScript -> {
RunConfigurationProducer
.getProducers(function.project)
.asSequence()
.filterIsInstance<KotlinJSRunConfigurationDataProvider<*>>()
.filter { !it.isForTests }
.mapNotNull { it.getConfigurationData(function) }
.firstOrNull() != null
}
}
}
} }
@@ -16,127 +16,39 @@
package org.jetbrains.kotlin.idea.highlighter package org.jetbrains.kotlin.idea.highlighter
import com.intellij.codeInsight.TestFrameworks
import com.intellij.execution.TestStateStorage import com.intellij.execution.TestStateStorage
import com.intellij.execution.actions.RunConfigurationProducer
import com.intellij.execution.lineMarker.ExecutorAction import com.intellij.execution.lineMarker.ExecutorAction
import com.intellij.execution.lineMarker.RunLineMarkerContributor import com.intellij.execution.lineMarker.RunLineMarkerContributor
import com.intellij.execution.testframework.TestIconMapper import com.intellij.execution.testframework.TestIconMapper
import com.intellij.execution.testframework.sm.runner.states.TestStateInfo import com.intellij.execution.testframework.sm.runner.states.TestStateInfo
import com.intellij.icons.AllIcons import com.intellij.icons.AllIcons
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.util.io.FileUtil
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.js.KotlinJSRunConfigurationDataProvider import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.project.targetPlatform import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.util.projectStructure.module import org.jetbrains.kotlin.idea.util.projectStructure.module
import org.jetbrains.kotlin.idea.util.string.joinWithEscape
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtNamedDeclaration import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import javax.swing.Icon import javax.swing.Icon
class KotlinTestRunLineMarkerContributor : RunLineMarkerContributor() { class KotlinTestRunLineMarkerContributor : RunLineMarkerContributor() {
companion object { companion object {
private val TEST_FQ_NAME = FqName("kotlin.test.Test") fun getTestStateIcon(url: String, project: Project): Icon? {
private val IGNORE_FQ_NAME = FqName("kotlin.test.Ignore") val defaultIcon = AllIcons.RunConfigurations.TestState.Run
} val state = TestStateStorage.getInstance(project).getState(url) ?: return defaultIcon
val magnitude = TestIconMapper.getMagnitude(state.magnitude)
private fun getTestStateIcon(url: String, project: Project): Icon? { return when (magnitude) {
val defaultIcon = AllIcons.RunConfigurations.TestState.Run TestStateInfo.Magnitude.ERROR_INDEX,
val state = TestStateStorage.getInstance(project).getState(url) ?: return defaultIcon TestStateInfo.Magnitude.FAILED_INDEX -> AllIcons.RunConfigurations.TestState.Red2
val magnitude = TestIconMapper.getMagnitude(state.magnitude) TestStateInfo.Magnitude.PASSED_INDEX,
return when (magnitude) { TestStateInfo.Magnitude.COMPLETE_INDEX -> AllIcons.RunConfigurations.TestState.Green2
TestStateInfo.Magnitude.ERROR_INDEX, else -> defaultIcon
TestStateInfo.Magnitude.FAILED_INDEX -> AllIcons.RunConfigurations.TestState.Red2
TestStateInfo.Magnitude.PASSED_INDEX,
TestStateInfo.Magnitude.COMPLETE_INDEX -> AllIcons.RunConfigurations.TestState.Green2
else -> defaultIcon
}
}
private fun getJavaTestIcon(declaration: KtNamedDeclaration): Icon? {
val (url, framework) = when (declaration) {
is KtClassOrObject -> {
val lightClass = declaration.toLightClass() ?: return null
val framework = TestFrameworks.detectFramework(lightClass) ?: return null
if (!framework.isTestClass(lightClass)) return null
val qualifiedName = lightClass.qualifiedName ?: return null
"java:suite://$qualifiedName" to framework
} }
is KtNamedFunction -> {
val lightMethod = declaration.toLightMethods().firstOrNull() ?: return null
val lightClass = lightMethod.containingClass as? KtLightClass ?: return null
val framework = TestFrameworks.detectFramework(lightClass) ?: return null
if (!framework.isTestMethod(lightMethod)) return null
"java:test://${lightClass.qualifiedName}.${lightMethod.name}" to framework
}
else -> return null
} }
return getTestStateIcon(url, declaration.project) ?: framework.icon
}
private fun DeclarationDescriptor.isIgnored(): Boolean =
annotations.any { it.fqName == IGNORE_FQ_NAME } || ((containingDeclaration as? ClassDescriptor)?.isIgnored() ?: false)
private fun DeclarationDescriptor.isTest(): Boolean {
if (isIgnored()) return false
if (annotations.any { it.fqName == TEST_FQ_NAME }) return true
if (this is ClassDescriptorWithResolutionScopes) {
return declaredCallableMembers.any { it.isTest() }
}
return false
}
private fun getJavaScriptTestIcon(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor): Icon? {
if (!descriptor.isTest()) return null
val runConfigData = RunConfigurationProducer
.getProducers(declaration.project)
.asSequence()
.filterIsInstance<KotlinJSRunConfigurationDataProvider<*>>()
.filter { it.isForTests }
.mapNotNull { it.getConfigurationData(declaration) }
.firstOrNull() ?: return null
val locations = ArrayList<String>()
locations += FileUtil.toSystemDependentName(runConfigData.jsOutputFilePath)
val klass = when (declaration) {
is KtClassOrObject -> declaration
is KtNamedFunction -> declaration.containingClassOrObject ?: return null
else -> return null
}
locations += klass.parentsWithSelf.filterIsInstance<KtNamedDeclaration>().mapNotNull { it.name }.toList().asReversed()
val testName = (declaration as? KtNamedFunction)?.name
if (testName != null) {
locations += "$testName"
}
val prefix = if (testName != null) "test://" else "suite://"
val url = prefix + locations.joinWithEscape('.')
return getTestStateIcon(url, declaration.project)
} }
override fun getInfo(element: PsiElement): RunLineMarkerContributor.Info? { override fun getInfo(element: PsiElement): RunLineMarkerContributor.Info? {
@@ -150,23 +62,8 @@ class KotlinTestRunLineMarkerContributor : RunLineMarkerContributor() {
// To prevent IDEA failing on red code // To prevent IDEA failing on red code
val descriptor = declaration.resolveToDescriptorIfAny() ?: return null val descriptor = declaration.resolveToDescriptorIfAny() ?: return null
val icon = getTestIcon(declaration, descriptor) ?: return null val targetPlatform = declaration.module?.platform ?: return null
val icon = targetPlatform.kind.tooling.getTestIcon(declaration, descriptor) ?: return null
return RunLineMarkerContributor.Info(icon, { "Run Test" }, ExecutorAction.getActions()) return RunLineMarkerContributor.Info(icon, { "Run Test" }, ExecutorAction.getActions())
} }
private fun getTestIcon(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor): Icon? {
val module = declaration.module ?: return null
val targetPlatformKind = module.targetPlatform ?: return null
return when (targetPlatformKind) {
is TargetPlatformKind.JavaScript -> getJavaScriptTestIcon(declaration, descriptor)
is TargetPlatformKind.Jvm -> getJavaTestIcon(declaration)
is TargetPlatformKind.Common -> {
val icons = listOfNotNull(getJavaScriptTestIcon(declaration, descriptor), getJavaTestIcon(declaration))
when (icons.size) {
0 -> null
else -> icons.distinct().singleOrNull() ?: AllIcons.RunConfigurations.TestState.Run
}
}
}
}
} }
@@ -0,0 +1,68 @@
/*
* 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.idea.platform
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription
import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import javax.swing.Icon
abstract class IdePlatformKindTooling {
abstract val kind: IdePlatformKind<*>
abstract fun compilerArgumentsForProject(project: Project): CommonCompilerArguments?
abstract val resolverForModuleFactory: ResolverForModuleFactory
abstract val mavenLibraryIds: List<String>
abstract val gradlePluginId: String
abstract val libraryKind: PersistentLibraryKind<*>?
abstract fun getLibraryDescription(project: Project): CustomLibraryDescription
abstract fun getLibraryVersionProvider(project: Project): (Library) -> String?
abstract fun getTestIcon(declaration: KtNamedDeclaration, descriptor: DeclarationDescriptor): Icon?
abstract fun acceptsAsEntryPoint(function: KtFunction): Boolean
override fun equals(other: Any?): Boolean = javaClass == other?.javaClass
override fun hashCode(): Int = javaClass.hashCode()
companion object : ApplicationExtensionDescriptor<IdePlatformKindTooling>(
"org.jetbrains.kotlin.idePlatformKindTooling", IdePlatformKindTooling::class.java
) {
private val CACHED_TOOLING_SUPPORT by lazy {
val allPlatformKinds = IdePlatformKind.ALL_KINDS
val groupedTooling = IdePlatformKindTooling.getInstances().groupBy { it.kind }.mapValues { it.value.single() }
for (kind in allPlatformKinds) {
if (kind !in groupedTooling) {
throw IllegalStateException(
"Tooling support for the platform '$kind' is missing. " +
"Implement 'IdePlatformKindTooling' for it."
)
}
}
groupedTooling
}
fun getTooling(kind: IdePlatformKind<*>): IdePlatformKindTooling {
return CACHED_TOOLING_SUPPORT[kind] ?: error("Unknown platform $this")
}
}
}
val IdePlatformKind<*>.tooling: IdePlatformKindTooling
get() = IdePlatformKindTooling.getTooling(this)
@@ -137,7 +137,7 @@ class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jv
getFacetElement(KotlinFacetType.ID) getFacetElement(KotlinFacetType.ID)
?.getChild(JpsFacetSerializer.CONFIGURATION_TAG) ?.getChild(JpsFacetSerializer.CONFIGURATION_TAG)
?.getFacetPlatformByConfigurationElement() ?.getFacetPlatformByConfigurationElement()
?.asTargetPlatform() ?.kind?.compilerPlatform
private fun ModuleSettings.detectPlatformByDependencies(): TargetPlatform? { private fun ModuleSettings.detectPlatformByDependencies(): TargetPlatform? {
var hasCommonStdlib = false var hasCommonStdlib = false
@@ -17,10 +17,6 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRoot
import org.jetbrains.jps.model.module.JpsModuleSourceRootType import org.jetbrains.jps.model.module.JpsModuleSourceRootType
import org.jetbrains.kotlin.config.KotlinResourceRootType import org.jetbrains.kotlin.config.KotlinResourceRootType
import org.jetbrains.kotlin.config.KotlinSourceRootType import org.jetbrains.kotlin.config.KotlinSourceRootType
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
private fun JpsModuleSourceRoot.getOrCreateProperties() = private fun JpsModuleSourceRoot.getOrCreateProperties() =
getProperties(rootType)?.also { (it as? JpsElementBase<*>)?.setParent(null) } ?: rootType.createDefaultProperties() getProperties(rootType)?.also { (it as? JpsElementBase<*>)?.setParent(null) } ?: rootType.createDefaultProperties()
@@ -49,12 +45,6 @@ fun migrateNonJvmSourceFolders(modifiableRootModel: ModifiableRootModel) {
} }
} }
fun TargetPlatformKind<*>.asTargetPlatform() = when (this) {
is TargetPlatformKind.Jvm -> JvmPlatform
is TargetPlatformKind.JavaScript -> JsPlatform
is TargetPlatformKind.Common -> TargetPlatform.Common
}
fun Project.invalidateProjectRoots() { fun Project.invalidateProjectRoots() {
ProjectRootManagerEx.getInstanceEx(this).makeRootsChange(EmptyRunnable.INSTANCE, false, true) ProjectRootManagerEx.getInstanceEx(this).makeRootsChange(EmptyRunnable.INSTANCE, false, true)
} }
@@ -269,8 +269,7 @@ const val MAVEN_STDLIB_ID_JDK8 = PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME
const val MAVEN_JS_STDLIB_ID = PathUtil.JS_LIB_NAME const val MAVEN_JS_STDLIB_ID = PathUtil.JS_LIB_NAME
const val MAVEN_JS_TEST_ID = PathUtil.KOTLIN_TEST_JS_NAME const val MAVEN_JS_TEST_ID = PathUtil.KOTLIN_TEST_JS_NAME
const val MAVEN_OLD_JS_STDLIB_ID = "kotlin-js-library"
const val MAVEN_COMMON_STDLIB_ID = "kotlin-stdlib-common" // TODO: KotlinCommonMavenConfigurator
const val MAVEN_TEST_ID = PathUtil.KOTLIN_TEST_NAME const val MAVEN_TEST_ID = PathUtil.KOTLIN_TEST_NAME
const val MAVEN_TEST_JUNIT_ID = "kotlin-test-junit" const val MAVEN_TEST_JUNIT_ID = "kotlin-test-junit"
const val MAVEN_COMMON_TEST_ID = "kotlin-test-common" const val MAVEN_COMMON_TEST_ID = "kotlin-test-common"
@@ -26,6 +26,7 @@ public class DataFlowValueRenderingTestGenerated extends AbstractDataFlowValueRe
} }
public void testAllFilesPresentInDataFlowValueRendering() throws Exception { public void testAllFilesPresentInDataFlowValueRendering() throws Exception {
assertTrue(false);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/dataFlowValueRendering"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/dataFlowValueRendering"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
} }
@@ -44,6 +44,8 @@ import org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderKt;
import org.jetbrains.kotlin.idea.project.PlatformKt; import org.jetbrains.kotlin.idea.project.PlatformKt;
import org.jetbrains.kotlin.idea.util.Java9StructureUtilKt; import org.jetbrains.kotlin.idea.util.Java9StructureUtilKt;
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt; import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt;
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind;
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind;
import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleKt; import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleKt;
import org.jetbrains.kotlin.utils.PathUtil; import org.jetbrains.kotlin.utils.PathUtil;
@@ -210,7 +212,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind()); assertEquals(new JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
@@ -225,7 +227,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.JavaScript.INSTANCE, settings.getTargetPlatformKind()); assertEquals(JsIdePlatformKind.Platform.INSTANCE, settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
@@ -240,7 +242,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind()); assertEquals(new JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
@@ -255,7 +257,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.JavaScript.INSTANCE, settings.getTargetPlatformKind()); assertEquals(JsIdePlatformKind.Platform.INSTANCE, settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments));
@@ -270,7 +272,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind()); assertEquals(new JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
@@ -332,15 +334,15 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(getProject()); IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
try { try {
KotlinFacet facet = FacetUtilsKt.getOrCreateFacet(getModule(), modelsProvider, false, null, false); KotlinFacet facet = FacetUtilsKt.getOrCreateFacet(getModule(), modelsProvider, false, null, false);
TargetPlatformKind.Jvm platformKind = TargetPlatformKind.Jvm.Companion.get(jvmTarget); JvmIdePlatformKind.Platform platform = new JvmIdePlatformKind.Platform(jvmTarget);
FacetUtilsKt.configureFacet( FacetUtilsKt.configureFacet(
facet, facet,
"1.1", "1.1",
LanguageFeature.State.ENABLED, LanguageFeature.State.ENABLED,
platformKind, platform,
modelsProvider modelsProvider
); );
assertEquals(platformKind, facet.getConfiguration().getSettings().getTargetPlatformKind()); assertEquals(platform, facet.getConfiguration().getSettings().getPlatform());
assertEquals(jvmTarget.getDescription(), assertEquals(jvmTarget.getDescription(),
((K2JVMCompilerArguments) facet.getConfiguration().getSettings().getCompilerArguments()).getJvmTarget()); ((K2JVMCompilerArguments) facet.getConfiguration().getSettings().getCompilerArguments()).getJvmTarget());
} }
@@ -360,7 +362,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
} }
public void testProjectWithoutFacetWithJvmTarget18() { public void testProjectWithoutFacetWithJvmTarget18() {
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), PlatformKt.getTargetPlatform(getModule())); assertEquals(new JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), PlatformKt.getPlatform(getModule()));
} }
private static class LibraryCountingRootPolicy extends RootPolicy<Integer> { private static class LibraryCountingRootPolicy extends RootPolicy<Integer> {
@@ -44,6 +44,8 @@ import org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderKt;
import org.jetbrains.kotlin.idea.project.PlatformKt; import org.jetbrains.kotlin.idea.project.PlatformKt;
import org.jetbrains.kotlin.idea.util.Java9StructureUtilKt; import org.jetbrains.kotlin.idea.util.Java9StructureUtilKt;
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt; import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt;
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind;
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind;
import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleKt; import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleKt;
import org.jetbrains.kotlin.utils.PathUtil; import org.jetbrains.kotlin.utils.PathUtil;
@@ -210,7 +212,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind()); assertEquals(new JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
@@ -225,7 +227,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.JavaScript.INSTANCE, settings.getTargetPlatformKind()); assertEquals(JsIdePlatformKind.Platform.INSTANCE, settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
@@ -240,7 +242,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind()); assertEquals(new JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
@@ -255,7 +257,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.JavaScript.INSTANCE, settings.getTargetPlatformKind()); assertEquals(JsIdePlatformKind.Platform.INSTANCE, settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments));
@@ -270,7 +272,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(false, settings.getUseProjectSettings()); assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription()); assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription()); assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind()); assertEquals(new JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), settings.getPlatform());
assertEquals("1.1", arguments.getLanguageVersion()); assertEquals("1.1", arguments.getLanguageVersion());
assertEquals("1.0", arguments.getApiVersion()); assertEquals("1.0", arguments.getApiVersion());
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments)); assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
@@ -332,15 +334,15 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(getProject()); IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
try { try {
KotlinFacet facet = FacetUtilsKt.getOrCreateFacet(getModule(), modelsProvider, false, null, false); KotlinFacet facet = FacetUtilsKt.getOrCreateFacet(getModule(), modelsProvider, false, null, false);
TargetPlatformKind.Jvm platformKind = TargetPlatformKind.Jvm.Companion.get(jvmTarget); JvmIdePlatformKind.Platform platform = new JvmIdePlatformKind.Platform(jvmTarget);
FacetUtilsKt.configureFacet( FacetUtilsKt.configureFacet(
facet, facet,
"1.1", "1.1",
LanguageFeature.State.ENABLED, LanguageFeature.State.ENABLED,
platformKind, platform,
modelsProvider modelsProvider
); );
assertEquals(platformKind, facet.getConfiguration().getSettings().getTargetPlatformKind()); assertEquals(platform, facet.getConfiguration().getSettings().getPlatform());
assertEquals(jvmTarget.getDescription(), assertEquals(jvmTarget.getDescription(),
((K2JVMCompilerArguments) facet.getConfiguration().getSettings().getCompilerArguments()).getJvmTarget()); ((K2JVMCompilerArguments) facet.getConfiguration().getSettings().getCompilerArguments()).getJvmTarget());
} }
@@ -360,7 +362,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
} }
public void testProjectWithoutFacetWithJvmTarget18() { public void testProjectWithoutFacetWithJvmTarget18() {
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), PlatformKt.getTargetPlatform(getModule())); assertEquals(new JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8), PlatformKt.getPlatform(getModule()));
} }
private static class LibraryCountingRootPolicy extends RootPolicy<Integer> { private static class LibraryCountingRootPolicy extends RootPolicy<Integer> {
@@ -22,14 +22,12 @@ import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.stubs.createFacet import org.jetbrains.kotlin.idea.stubs.createFacet
import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.test.MockLibraryUtil import org.jetbrains.kotlin.test.MockLibraryUtil
import org.jetbrains.kotlin.utils.Jsr305State
import org.jetbrains.kotlin.utils.ReportLevel import org.jetbrains.kotlin.utils.ReportLevel
import org.jetbrains.kotlin.utils.ReportLevel.Companion.findByDescription
class Jsr305HighlightingTest : KotlinLightCodeInsightFixtureTestCase() { class Jsr305HighlightingTest : KotlinLightCodeInsightFixtureTestCase() {
override fun getProjectDescriptor(): LightProjectDescriptor { override fun getProjectDescriptor(): LightProjectDescriptor {
@@ -45,7 +43,7 @@ class Jsr305HighlightingTest : KotlinLightCodeInsightFixtureTestCase() {
) { ) {
override fun configureModule(module: Module, model: ModifiableRootModel) { override fun configureModule(module: Module, model: ModifiableRootModel) {
super.configureModule(module, model) super.configureModule(module, model)
module.createFacet(TargetPlatformKind.Jvm(JvmTarget.JVM_1_8)) module.createFacet(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8))
val facetSettings = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(module) val facetSettings = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(module)
facetSettings.apply { facetSettings.apply {
@@ -14,13 +14,14 @@ import com.intellij.openapi.vfs.LocalFileSystem
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
import org.jetbrains.kotlin.idea.framework.JSLibraryKind import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest
import org.jetbrains.kotlin.idea.stubs.createFacet import org.jetbrains.kotlin.idea.stubs.createFacet
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.impl.*
import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.TestJdkKind
import java.io.File import java.io.File
@@ -39,14 +40,18 @@ fun AbstractMultiModuleTest.setupMppProjectFromDirStructure(testRoot: File) {
infosByModuleId.entries.forEach { (id, rootInfos) -> infosByModuleId.entries.forEach { (id, rootInfos) ->
val module = modulesById[id]!! val module = modulesById[id]!!
rootInfos.flatMap { it.dependencies }.forEach { rootInfos.flatMap { it.dependencies }.forEach {
val platform = id.platform
when (it) { when (it) {
is ModuleDependency -> module.addDependency(modulesById[it.moduleId]!!) is ModuleDependency -> module.addDependency(modulesById[it.moduleId]!!)
is StdlibDependency -> when (id.platform) { is StdlibDependency -> {
is TargetPlatformKind.Common -> module.addLibrary( when {
ForTestCompileRuntime.stdlibCommonForTests(), kind = CommonLibraryKind platform.isCommon -> module.addLibrary(
) ForTestCompileRuntime.stdlibCommonForTests(), kind = CommonLibraryKind
is TargetPlatformKind.Jvm -> module.addLibrary(ForTestCompileRuntime.runtimeJarForTests()) )
is TargetPlatformKind.JavaScript -> module.addLibrary(ForTestCompileRuntime.stdlibJsForTests(), kind = JSLibraryKind) platform.isJvm -> module.addLibrary(ForTestCompileRuntime.runtimeJarForTests())
platform.isJavaScript -> module.addLibrary(ForTestCompileRuntime.stdlibJsForTests(), kind = JSLibraryKind)
else -> error("Unknown platform $this")
}
} }
is FullJdkDependency -> { is FullJdkDependency -> {
ConfigLibraryUtil.configureSdk(module, PluginTestCaseBase.addJdk(testRootDisposable) { ConfigLibraryUtil.configureSdk(module, PluginTestCaseBase.addJdk(testRootDisposable) {
@@ -54,9 +59,9 @@ fun AbstractMultiModuleTest.setupMppProjectFromDirStructure(testRoot: File) {
}) })
} }
is CoroutinesDependency -> module.enableCoroutines() is CoroutinesDependency -> module.enableCoroutines()
is KotlinTestDependency -> when (id.platform) { is KotlinTestDependency -> when {
is TargetPlatformKind.Jvm -> module.addLibrary(ForTestCompileRuntime.kotlinTestJUnitJarForTests()) platform.isJvm -> module.addLibrary(ForTestCompileRuntime.kotlinTestJUnitJarForTests())
is TargetPlatformKind.JavaScript -> module.addLibrary(ForTestCompileRuntime.kotlinTestJsJarForTests(), kind = JSLibraryKind) platform.isJavaScript -> module.addLibrary(ForTestCompileRuntime.kotlinTestJsJarForTests(), kind = JSLibraryKind)
} }
} }
} }
@@ -64,10 +69,10 @@ fun AbstractMultiModuleTest.setupMppProjectFromDirStructure(testRoot: File) {
modulesById.forEach { (nameAndPlatform, module) -> modulesById.forEach { (nameAndPlatform, module) ->
val (name, platform) = nameAndPlatform val (name, platform) = nameAndPlatform
when (platform) { when {
TargetPlatformKind.Common -> module.createFacet(TargetPlatformKind.Common, useProjectSettings = false) platform.isCommon -> module.createFacet(platform, useProjectSettings = false)
else -> { else -> {
val commonModuleId = ModuleId(name, TargetPlatformKind.Common) val commonModuleId = ModuleId(name, CommonIdePlatformKind.Platform)
module.createFacet(platform, implementedModuleName = commonModuleId.ideaModuleName()) module.createFacet(platform, implementedModuleName = commonModuleId.ideaModuleName())
module.enableMultiPlatform() module.enableMultiPlatform()
@@ -88,7 +93,7 @@ private fun AbstractMultiModuleTest.createModuleWithRoots(
for ((_, isTestRoot, moduleRoot) in infos) { for ((_, isTestRoot, moduleRoot) in infos) {
addRoot(module, moduleRoot, isTestRoot) addRoot(module, moduleRoot, isTestRoot)
if (moduleId.platform is TargetPlatformKind.JavaScript && isTestRoot) { if (moduleId.platform.isJavaScript && isTestRoot) {
setupJsTestOutput(module) setupJsTestOutput(module)
} }
} }
@@ -121,11 +126,11 @@ private fun AbstractMultiModuleTest.createModule(name: String): Module {
private val testSuffixes = setOf("test", "tests") private val testSuffixes = setOf("test", "tests")
private val platformNames = mapOf( private val platformNames = mapOf(
listOf("header", "common", "expect") to TargetPlatformKind.Common, listOf("header", "common", "expect") to CommonIdePlatformKind.Platform,
listOf("java", "jvm") to TargetPlatformKind.Jvm[JvmTarget.DEFAULT], listOf("java", "jvm") to JvmIdePlatformKind.defaultPlatform,
listOf("java8", "jvm8") to TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], listOf("java8", "jvm8") to JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8),
listOf("java6", "jvm6") to TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], listOf("java6", "jvm6") to JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6),
listOf("js", "javascript") to TargetPlatformKind.JavaScript listOf("js", "javascript") to JsIdePlatformKind.Platform
) )
private fun parseDirName(dir: File): RootInfo { private fun parseDirName(dir: File): RootInfo {
@@ -154,7 +159,7 @@ private fun parseModuleId(parts: List<String>): ModuleId {
val platform = parsePlatform(parts) val platform = parsePlatform(parts)
val name = parseModuleName(parts) val name = parseModuleName(parts)
val id = parseIndex(parts) ?: 0 val id = parseIndex(parts) ?: 0
assert(id == 0 || platform !is TargetPlatformKind.Common) assert(id == 0 || !platform.isCommon)
return ModuleId(name, platform, id) return ModuleId(name, platform, id)
} }
@@ -177,7 +182,7 @@ private fun parseIndex(parts: List<String>): Int? {
private data class ModuleId( private data class ModuleId(
val groupName: String, val groupName: String,
val platform: TargetPlatformKind<*>, val platform: IdePlatform<*, *>,
val index: Int = 0 val index: Int = 0
) { ) {
fun ideaModuleName(): String { fun ideaModuleName(): String {
@@ -186,11 +191,12 @@ private data class ModuleId(
} }
} }
private val TargetPlatformKind<*>.presentableName: String private val IdePlatform<*, *>.presentableName: String
get() = when (this) { get() = when {
is TargetPlatformKind.Common -> "Common" isCommon -> "Common"
is TargetPlatformKind.Jvm -> "JVM" isJvm -> "JVM"
is TargetPlatformKind.JavaScript -> "JS" isJavaScript -> "JS"
else -> error("Unknown platform $this")
} }
private data class RootInfo( private data class RootInfo(
@@ -15,13 +15,14 @@ import com.intellij.testFramework.PlatformTestCase
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
import org.jetbrains.kotlin.idea.framework.JSLibraryKind import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest
import org.jetbrains.kotlin.idea.stubs.createFacet import org.jetbrains.kotlin.idea.stubs.createFacet
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.impl.*
import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.TestJdkKind
import java.io.File import java.io.File
@@ -40,14 +41,18 @@ fun AbstractMultiModuleTest.setupMppProjectFromDirStructure(testRoot: File) {
infosByModuleId.entries.forEach { (id, rootInfos) -> infosByModuleId.entries.forEach { (id, rootInfos) ->
val module = modulesById[id]!! val module = modulesById[id]!!
rootInfos.flatMap { it.dependencies }.forEach { rootInfos.flatMap { it.dependencies }.forEach {
val platform = id.platform
when (it) { when (it) {
is ModuleDependency -> module.addDependency(modulesById[it.moduleId]!!) is ModuleDependency -> module.addDependency(modulesById[it.moduleId]!!)
is StdlibDependency -> when (id.platform) { is StdlibDependency -> {
is TargetPlatformKind.Common -> module.addLibrary( when {
ForTestCompileRuntime.stdlibCommonForTests(), kind = CommonLibraryKind platform.isCommon -> module.addLibrary(
) ForTestCompileRuntime.stdlibCommonForTests(), kind = CommonLibraryKind
is TargetPlatformKind.Jvm -> module.addLibrary(ForTestCompileRuntime.runtimeJarForTests()) )
is TargetPlatformKind.JavaScript -> module.addLibrary(ForTestCompileRuntime.stdlibJsForTests(), kind = JSLibraryKind) platform.isJvm -> module.addLibrary(ForTestCompileRuntime.runtimeJarForTests())
platform.isJavaScript -> module.addLibrary(ForTestCompileRuntime.stdlibJsForTests(), kind = JSLibraryKind)
else -> error("Unknown platform $this")
}
} }
is FullJdkDependency -> { is FullJdkDependency -> {
ConfigLibraryUtil.configureSdk(module, PluginTestCaseBase.addJdk(testRootDisposable) { ConfigLibraryUtil.configureSdk(module, PluginTestCaseBase.addJdk(testRootDisposable) {
@@ -55,9 +60,9 @@ fun AbstractMultiModuleTest.setupMppProjectFromDirStructure(testRoot: File) {
}) })
} }
is CoroutinesDependency -> module.enableCoroutines() is CoroutinesDependency -> module.enableCoroutines()
is KotlinTestDependency -> when (id.platform) { is KotlinTestDependency -> when {
is TargetPlatformKind.Jvm -> module.addLibrary(ForTestCompileRuntime.kotlinTestJUnitJarForTests()) platform.isJvm -> module.addLibrary(ForTestCompileRuntime.kotlinTestJUnitJarForTests())
is TargetPlatformKind.JavaScript -> module.addLibrary(ForTestCompileRuntime.kotlinTestJsJarForTests(), kind = JSLibraryKind) platform.isJavaScript -> module.addLibrary(ForTestCompileRuntime.kotlinTestJsJarForTests(), kind = JSLibraryKind)
} }
} }
} }
@@ -65,10 +70,10 @@ fun AbstractMultiModuleTest.setupMppProjectFromDirStructure(testRoot: File) {
modulesById.forEach { (nameAndPlatform, module) -> modulesById.forEach { (nameAndPlatform, module) ->
val (name, platform) = nameAndPlatform val (name, platform) = nameAndPlatform
when (platform) { when {
TargetPlatformKind.Common -> module.createFacet(TargetPlatformKind.Common, useProjectSettings = false) platform.isCommon -> module.createFacet(platform, useProjectSettings = false)
else -> { else -> {
val commonModuleId = ModuleId(name, TargetPlatformKind.Common) val commonModuleId = ModuleId(name, CommonIdePlatformKind.Platform)
module.createFacet(platform, implementedModuleName = commonModuleId.ideaModuleName()) module.createFacet(platform, implementedModuleName = commonModuleId.ideaModuleName())
module.enableMultiPlatform() module.enableMultiPlatform()
@@ -89,7 +94,7 @@ private fun AbstractMultiModuleTest.createModuleWithRoots(
for ((_, isTestRoot, moduleRoot) in infos) { for ((_, isTestRoot, moduleRoot) in infos) {
addRoot(module, moduleRoot, isTestRoot) addRoot(module, moduleRoot, isTestRoot)
if (moduleId.platform is TargetPlatformKind.JavaScript && isTestRoot) { if (moduleId.platform.isJavaScript && isTestRoot) {
setupJsTestOutput(module) setupJsTestOutput(module)
} }
} }
@@ -122,11 +127,11 @@ private fun AbstractMultiModuleTest.createModule(name: String): Module {
private val testSuffixes = setOf("test", "tests") private val testSuffixes = setOf("test", "tests")
private val platformNames = mapOf( private val platformNames = mapOf(
listOf("header", "common", "expect") to TargetPlatformKind.Common, listOf("header", "common", "expect") to CommonIdePlatformKind.Platform,
listOf("java", "jvm") to TargetPlatformKind.Jvm[JvmTarget.DEFAULT], listOf("java", "jvm") to JvmIdePlatformKind.defaultPlatform,
listOf("java8", "jvm8") to TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], listOf("java8", "jvm8") to JvmIdePlatformKind.Platform(JvmTarget.JVM_1_8),
listOf("java6", "jvm6") to TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], listOf("java6", "jvm6") to JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6),
listOf("js", "javascript") to TargetPlatformKind.JavaScript listOf("js", "javascript") to JsIdePlatformKind.Platform
) )
private fun parseDirName(dir: File): RootInfo { private fun parseDirName(dir: File): RootInfo {
@@ -155,7 +160,7 @@ private fun parseModuleId(parts: List<String>): ModuleId {
val platform = parsePlatform(parts) val platform = parsePlatform(parts)
val name = parseModuleName(parts) val name = parseModuleName(parts)
val id = parseIndex(parts) ?: 0 val id = parseIndex(parts) ?: 0
assert(id == 0 || platform !is TargetPlatformKind.Common) assert(id == 0 || !platform.isCommon)
return ModuleId(name, platform, id) return ModuleId(name, platform, id)
} }
@@ -178,7 +183,7 @@ private fun parseIndex(parts: List<String>): Int? {
private data class ModuleId( private data class ModuleId(
val groupName: String, val groupName: String,
val platform: TargetPlatformKind<*>, val platform: IdePlatform<*, *>,
val index: Int = 0 val index: Int = 0
) { ) {
fun ideaModuleName(): String { fun ideaModuleName(): String {
@@ -187,11 +192,12 @@ private data class ModuleId(
} }
} }
private val TargetPlatformKind<*>.presentableName: String private val IdePlatform<*, *>.presentableName: String
get() = when (this) { get() = when {
is TargetPlatformKind.Common -> "Common" isCommon -> "Common"
is TargetPlatformKind.Jvm -> "JVM" isJvm -> "JVM"
is TargetPlatformKind.JavaScript -> "JS" isJavaScript -> "JS"
else -> error("Unknown platform $this")
} }
private data class RootInfo( private data class RootInfo(
@@ -26,12 +26,12 @@ import com.intellij.testFramework.PsiTestUtil
import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.CompilerSettings
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.facet.getOrCreateFacet import org.jetbrains.kotlin.idea.facet.getOrCreateFacet
import org.jetbrains.kotlin.idea.facet.initializeIfNeeded import org.jetbrains.kotlin.idea.facet.initializeIfNeeded
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.test.TestJdkKind
import org.junit.Assert import org.junit.Assert
@@ -126,9 +126,9 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase() {
} }
fun Module.createFacet( fun Module.createFacet(
platformKind: TargetPlatformKind<*>? = null, platformKind: IdePlatform<*, *>? = null,
useProjectSettings: Boolean = true, useProjectSettings: Boolean = true,
implementedModuleName: String? = null implementedModuleName: String? = null
) { ) {
WriteAction.run<Throwable> { WriteAction.run<Throwable> {
val modelsProvider = IdeModifiableModelsProviderImpl(project) val modelsProvider = IdeModifiableModelsProviderImpl(project)
@@ -6,13 +6,13 @@
package org.jetbrains.kotlin.jps.build.dependeciestxt package org.jetbrains.kotlin.jps.build.dependeciestxt
import org.jetbrains.jps.model.java.JpsJavaDependencyScope import org.jetbrains.jps.model.java.JpsJavaDependencyScope
import org.jetbrains.jps.model.module.JpsModule
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.CompilerSettings
import org.jetbrains.kotlin.config.KotlinFacetSettings import org.jetbrains.kotlin.config.KotlinFacetSettings
import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.platform.impl.isJvm
import java.io.File import java.io.File
import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KMutableProperty1
import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.findAnnotation
@@ -41,16 +41,14 @@ data class DependenciesTxt(
*/ */
var kotlinFacetSettings: KotlinFacetSettings? = null var kotlinFacetSettings: KotlinFacetSettings? = null
lateinit var jpsModule: JpsModule
val dependencies = mutableListOf<Dependency>() val dependencies = mutableListOf<Dependency>()
val usages = mutableListOf<Dependency>() val usages = mutableListOf<Dependency>()
val isCommonModule val isCommonModule
get() = kotlinFacetSettings?.targetPlatformKind == TargetPlatformKind.Common get() = kotlinFacetSettings?.platform.isCommon
val isJvmModule val isJvmModule
get() = kotlinFacetSettings?.targetPlatformKind is TargetPlatformKind.Jvm get() = kotlinFacetSettings?.platform.isJvm
val expectedBy val expectedBy
get() = dependencies.filter { it.expectedBy } get() = dependencies.filter { it.expectedBy }
@@ -10,16 +10,14 @@ import org.jetbrains.jps.model.ex.JpsElementChildRoleBase
import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.jps.model.module.JpsModule import org.jetbrains.jps.model.module.JpsModule
import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.config.KotlinFacetSettings import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.config.KotlinModuleKind
import org.jetbrains.kotlin.config.TargetPlatformKind
val JpsModule.kotlinFacet: JpsKotlinFacetModuleExtension? val JpsModule.kotlinFacet: JpsKotlinFacetModuleExtension?
get() = container.getChild(JpsKotlinFacetModuleExtension.KIND) get() = container.getChild(JpsKotlinFacetModuleExtension.KIND)
val JpsModule.targetPlatform: TargetPlatformKind<*>? val JpsModule.platform: IdePlatform<*, *>?
get() = kotlinFacet?.settings?.targetPlatformKind get() = kotlinFacet?.settings?.platform
val JpsModule.kotlinKind: KotlinModuleKind val JpsModule.kotlinKind: KotlinModuleKind
get() = kotlinFacet?.settings?.kind ?: KotlinModuleKind.DEFAULT get() = kotlinFacet?.settings?.kind ?: KotlinModuleKind.DEFAULT
@@ -10,12 +10,13 @@ import org.jetbrains.jps.builders.ModuleBasedBuildTargetType
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
import org.jetbrains.jps.incremental.CompileContext import org.jetbrains.jps.incremental.CompileContext
import org.jetbrains.jps.incremental.ModuleBuildTarget import org.jetbrains.jps.incremental.ModuleBuildTarget
import org.jetbrains.jps.model.java.JpsJavaModuleType
import org.jetbrains.jps.model.library.JpsOrderRootType import org.jetbrains.jps.model.library.JpsOrderRootType
import org.jetbrains.jps.model.module.JpsModule import org.jetbrains.jps.model.module.JpsModule
import org.jetbrains.jps.util.JpsPathUtil import org.jetbrains.jps.util.JpsPathUtil
import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.jps.model.platform
import org.jetbrains.kotlin.jps.model.targetPlatform import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.*
import org.jetbrains.kotlin.utils.LibraryUtils import org.jetbrains.kotlin.utils.LibraryUtils
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@@ -25,9 +26,6 @@ fun ModuleBuildTarget(module: JpsModule, isTests: Boolean) =
val JpsModule.productionBuildTarget val JpsModule.productionBuildTarget
get() = ModuleBuildTarget(this, false) get() = ModuleBuildTarget(this, false)
val JpsModule.testBuildTarget
get() = ModuleBuildTarget(this, true)
private val kotlinBuildTargetsCompileContextKey = Key<KotlinBuildTargets>("kotlinBuildTargets") private val kotlinBuildTargetsCompileContextKey = Key<KotlinBuildTargets>("kotlinBuildTargets")
val CompileContext.kotlinBuildTargets: KotlinBuildTargets val CompileContext.kotlinBuildTargets: KotlinBuildTargets
@@ -59,10 +57,13 @@ class KotlinBuildTargets internal constructor(val compileContext: CompileContext
if (target.targetType !is ModuleBasedBuildTargetType) return null if (target.targetType !is ModuleBasedBuildTargetType) return null
return byJpsModuleBuildTarget.computeIfAbsent(target) { return byJpsModuleBuildTarget.computeIfAbsent(target) {
when (target.module.targetPlatform ?: detectTargetPlatform(target)) { val platform = target.module.platform?.kind ?: detectTargetPlatform(target)
is TargetPlatformKind.Common -> KotlinCommonModuleBuildTarget(compileContext, target)
is TargetPlatformKind.JavaScript -> KotlinJsModuleBuildTarget(compileContext, target) when {
is TargetPlatformKind.Jvm -> KotlinJvmModuleBuildTarget(compileContext, target) platform.isCommon -> KotlinCommonModuleBuildTarget(compileContext, target)
platform.isJavaScript -> KotlinJsModuleBuildTarget(compileContext, target)
platform.isJvm -> KotlinJvmModuleBuildTarget(compileContext, target)
else -> error("Invalid platform $platform")
} }
} }
} }
@@ -71,10 +72,13 @@ class KotlinBuildTargets internal constructor(val compileContext: CompileContext
* Compatibility for KT-14082 * Compatibility for KT-14082
* todo: remove when all projects migrated to facets * todo: remove when all projects migrated to facets
*/ */
private fun detectTargetPlatform(target: ModuleBuildTarget): TargetPlatformKind<*> { private fun detectTargetPlatform(target: ModuleBuildTarget): IdePlatformKind<*> {
if (hasJsStdLib(target)) return TargetPlatformKind.JavaScript if (hasJsStdLib(target)) {
return JsIdePlatformKind
}
return TargetPlatformKind.DEFAULT_PLATFORM return JvmIdePlatformKind
return DefaultIdeTargetPlatformKindProvider.defaultPlatform.kind
} }
private fun hasJsStdLib(target: ModuleBuildTarget): Boolean { private fun hasJsStdLib(target: ModuleBuildTarget): Boolean {