[kotlin] Extract facet and platform-related classes to kotlin.base.* modules (KTIJ-21699)

GitOrigin-RevId: c2cd56198d67d4a9e28315dd0c115f18d0f1dbd9
This commit is contained in:
Yan Zhulanow
2022-05-09 23:26:58 +09:00
committed by intellij-monorepo-bot
parent 30e1e6e323
commit 12c3ad80e9
150 changed files with 1291 additions and 1018 deletions

4
.idea/modules.xml generated
View File

@@ -1027,10 +1027,14 @@
<module fileurl="file://$PROJECT_DIR$/plugins/yaml/intellij.yaml.iml" filepath="$PROJECT_DIR$/plugins/yaml/intellij.yaml.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/kotlin.all-tests/kotlin.all-tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/kotlin.all-tests/kotlin.all-tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/compiler-configuration/kotlin.base.compiler-configuration.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/compiler-configuration/kotlin.base.compiler-configuration.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/compiler-configuration-ui/kotlin.base.compiler-configuration-ui.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/compiler-configuration-ui/kotlin.base.compiler-configuration-ui.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/facet/kotlin.base.facet.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/facet/kotlin.base.facet.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/fe10/analysis/kotlin.base.fe10.analysis.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/fe10/analysis/kotlin.base.fe10.analysis.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/fe10/kdoc/kotlin.base.fe10.kdoc.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/fe10/kdoc/kotlin.base.fe10.kdoc.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/fe10/obsolete-compat/kotlin.base.fe10.obsolete-compat.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/fe10/obsolete-compat/kotlin.base.fe10.obsolete-compat.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/indices/kotlin.base.indices.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/indices/kotlin.base.indices.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/jps/kotlin.base.jps.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/jps/kotlin.base.jps.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/platforms/kotlin.base.platforms.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/platforms/kotlin.base.platforms.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/plugin/kotlin.base.plugin.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/plugin/kotlin.base.plugin.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/psi/kotlin.base.psi.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/psi/kotlin.base.psi.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/base/resources/kotlin.base.resources.iml" filepath="$PROJECT_DIR$/plugins/kotlin/base/resources/kotlin.base.resources.iml" />

View File

@@ -68,6 +68,10 @@ final class KotlinPluginBuilder {
"kotlin.base.compiler-configuration",
"kotlin.base.plugin",
"kotlin.base.psi",
"kotlin.base.platforms",
"kotlin.base.facet",
"kotlin.base.jps",
"kotlin.base.compiler-configuration-ui",
"kotlin.base.resources",
"kotlin.base.fe10.analysis",
"kotlin.base.fe10.kdoc",

View File

@@ -94,6 +94,4 @@ function.receiver.0=receiver: {0}
kotlin.javascript.meta.file=Kotlin JavaScript meta file
kotlin.compiler.error=Kotlin compiler error
kotlin.compiler.warning=Kotlin compiler warning
kotlin.compiler.warning.0.options=Compiler warning ''{0}'' options
framework.name.kotlin.sdk=Kotlin SDK
kotlin.compiler.warning.0.options=Compiler warning ''{0}'' options

View File

@@ -5,8 +5,6 @@ package org.jetbrains.kotlin.caches.resolve
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.PathUtil
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters
@@ -20,14 +18,13 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.idea.base.platforms.isKlibLibraryRootForPlatform
import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo
import org.jetbrains.kotlin.idea.caches.project.LibraryInfo
import org.jetbrains.kotlin.idea.caches.project.SdkInfo
import org.jetbrains.kotlin.idea.caches.resolve.BuiltInsCacheKey
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
import org.jetbrains.kotlin.idea.klib.AbstractKlibLibraryInfo
import org.jetbrains.kotlin.idea.klib.createKlibPackageFragmentProvider
import org.jetbrains.kotlin.idea.klib.isKlibLibraryRootForPlatform
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
import org.jetbrains.kotlin.library.metadata.NullFlexibleTypeDeserializer
@@ -35,19 +32,10 @@ import org.jetbrains.kotlin.platform.CommonPlatforms
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.resolve.TargetEnvironment
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment
import org.jetbrains.kotlin.serialization.konan.impl.KlibMetadataModuleDescriptorFactoryImpl
import org.jetbrains.kotlin.storage.StorageManager
class CommonPlatformKindResolution : IdePlatformKindResolution {
override fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean {
return virtualFile.extension == MetadataPackageFragment.METADATA_FILE_EXTENSION ||
virtualFile.isKlibLibraryRootForPlatform(CommonPlatforms.defaultCommonPlatform)
}
override val libraryKind: PersistentLibraryKind<*>
get() = CommonLibraryKind
override val kind get() = CommonIdePlatformKind
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo, sdkInfo: SdkInfo?, stdlibInfo: LibraryInfo?): BuiltInsCacheKey =
@@ -64,9 +52,8 @@ class CommonPlatformKindResolution : IdePlatformKindResolution {
}
override fun createLibraryInfo(project: Project, library: Library): List<LibraryInfo> {
val klibFiles = library.getFiles(OrderRootType.CLASSES).filter {
it.isKlibLibraryRootForPlatform(CommonPlatforms.defaultCommonPlatform)
}
val klibFiles = library.getFiles(OrderRootType.CLASSES)
.filter { it.isKlibLibraryRootForPlatform(CommonPlatforms.defaultCommonPlatform) }
return if (klibFiles.isNotEmpty()) {
klibFiles.mapNotNull {

View File

@@ -43,8 +43,6 @@ interface IdePlatformKindResolution {
platform: TargetPlatform
): ResolverForModuleFactory
fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean
fun createKlibPackageFragmentProvider(
moduleInfo: ModuleInfo,
storageManager: StorageManager,
@@ -52,8 +50,6 @@ interface IdePlatformKindResolution {
moduleDescriptor: ModuleDescriptor
): PackageFragmentProvider? = null
val libraryKind: PersistentLibraryKind<*>?
fun createLibraryInfo(project: Project, library: Library): List<LibraryInfo>
companion object : ApplicationExtensionDescriptor<IdePlatformKindResolution>(

View File

@@ -5,8 +5,6 @@ package org.jetbrains.kotlin.caches.resolve
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.PathUtil
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters
@@ -18,14 +16,13 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.idea.base.platforms.isKlibLibraryRootForPlatform
import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo
import org.jetbrains.kotlin.idea.caches.project.LibraryInfo
import org.jetbrains.kotlin.idea.caches.project.SdkInfo
import org.jetbrains.kotlin.idea.caches.resolve.BuiltInsCacheKey
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.idea.klib.AbstractKlibLibraryInfo
import org.jetbrains.kotlin.idea.klib.createKlibPackageFragmentProvider
import org.jetbrains.kotlin.idea.klib.isKlibLibraryRootForPlatform
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
import org.jetbrains.kotlin.platform.TargetPlatform
@@ -37,15 +34,6 @@ import org.jetbrains.kotlin.serialization.konan.impl.KlibMetadataModuleDescripto
import org.jetbrains.kotlin.storage.StorageManager
class JsPlatformKindResolution : IdePlatformKindResolution {
override fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean {
return virtualFile.extension == "js"
|| virtualFile.extension == "kjsm"
|| virtualFile.isKlibLibraryRootForPlatform(JsPlatforms.defaultJsPlatform)
}
override val libraryKind: PersistentLibraryKind<*>
get() = JSLibraryKind
override val kind get() = JsIdePlatformKind
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo, sdkInfo: SdkInfo?, stdlibInfo: LibraryInfo?): BuiltInsCacheKey {
@@ -69,9 +57,8 @@ class JsPlatformKindResolution : IdePlatformKindResolution {
): ResolverForModuleFactory = JsResolverForModuleFactory(environment)
override fun createLibraryInfo(project: Project, library: Library): List<LibraryInfo> {
val klibFiles = library.getFiles(OrderRootType.CLASSES).filter {
it.isKlibLibraryRootForPlatform(JsPlatforms.defaultJsPlatform)
}
val klibFiles = library.getFiles(OrderRootType.CLASSES)
.filter { it.isKlibLibraryRootForPlatform(JsPlatforms.defaultJsPlatform) }
return if (klibFiles.isNotEmpty()) {
klibFiles.mapNotNull {

View File

@@ -6,8 +6,6 @@ import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
@@ -33,10 +31,6 @@ import org.jetbrains.kotlin.resolve.jvm.JvmResolverForModuleFactory
private val LOG = Logger.getInstance(JvmPlatformKindResolution::class.java)
class JvmPlatformKindResolution : IdePlatformKindResolution {
override fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean {
return false // TODO: No library kind for JVM
}
override fun createResolverForModuleFactory(
settings: PlatformAnalysisParameters,
environment: TargetEnvironment,
@@ -45,9 +39,6 @@ class JvmPlatformKindResolution : IdePlatformKindResolution {
return JvmResolverForModuleFactory(settings as JvmPlatformParameters, environment, platform)
}
override val libraryKind: PersistentLibraryKind<*>?
get() = null
override fun createLibraryInfo(project: Project, library: Library): List<LibraryInfo> =
listOf(JvmLibraryInfo(project, library))

View File

@@ -26,6 +26,9 @@ import org.jetbrains.kotlin.config.SourceKotlinRootType
import org.jetbrains.kotlin.config.TestSourceKotlinRootType
import org.jetbrains.kotlin.descriptors.ModuleCapability
import org.jetbrains.kotlin.idea.KotlinIdeaAnalysisBundle
import org.jetbrains.kotlin.idea.base.platforms.IdePlatformKindProjectStructure
import org.jetbrains.kotlin.idea.base.platforms.LibraryEffectiveKindProvider
import org.jetbrains.kotlin.idea.base.platforms.platform
import org.jetbrains.kotlin.idea.caches.resolve.util.enlargedSearchScope
import org.jetbrains.kotlin.idea.caches.trackers.KotlinModuleOutOfCodeBlockModificationTracker
import org.jetbrains.kotlin.idea.framework.KotlinSdkType

View File

@@ -18,8 +18,8 @@ import com.intellij.workspaceModel.storage.VersionedStorageChange
import com.intellij.workspaceModel.storage.bridgeEntities.api.LibraryEntity
import org.jetbrains.kotlin.caches.project.cacheInvalidatingOnRootModifications
import org.jetbrains.kotlin.caches.resolve.resolution
import org.jetbrains.kotlin.idea.framework.effectiveKind
import org.jetbrains.kotlin.idea.framework.platform
import org.jetbrains.kotlin.idea.base.platforms.LibraryEffectiveKindProvider
import org.jetbrains.kotlin.idea.base.platforms.platform
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
import org.jetbrains.kotlin.platform.idePlatformKind
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -57,7 +57,7 @@ class LibraryInfoCache(private val project: Project): Disposable {
val approximatePlatform = if (library is LibraryEx && !library.isDisposed) {
// for Native returns 'unspecifiedNativePlatform', thus "approximate"
library.effectiveKind(project).platform
LibraryEffectiveKindProvider.getInstance(project).getEffectiveKind(library).platform
} else {
DefaultIdeTargetPlatformKindProvider.defaultPlatform
}

View File

@@ -6,6 +6,7 @@ import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.JdkOrderEntry
import com.intellij.openapi.roots.LibraryOrderEntry
@@ -15,7 +16,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.caches.project.cacheInvalidatingOnRootModifications
import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.isCommon
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus.checkCanceled
@@ -151,4 +152,4 @@ private fun mergePlatformModules(
return rest + platformModules
}
fun getAllProjectSdks(): Array<Sdk> = getProjectJdkTableSafe().allJdks
fun getAllProjectSdks(): Array<Sdk> = runReadAction { ProjectJdkTable.getInstance() }.allJdks

View File

@@ -11,6 +11,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.base.util.isAndroidModule
import org.jetbrains.kotlin.caches.project.cacheInvalidatingOnRootModifications
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.config.KotlinFacetSettings
@@ -20,7 +21,6 @@ import org.jetbrains.kotlin.config.isNewMPP
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.caches.project.SourceType.PRODUCTION
import org.jetbrains.kotlin.idea.caches.project.SourceType.TEST
import org.jetbrains.kotlin.idea.core.isAndroidModule
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.kotlin.idea.facet.KotlinFacetType
import org.jetbrains.kotlin.idea.facet.KotlinFacetType.Companion.ID

View File

@@ -9,9 +9,10 @@ import com.intellij.openapi.roots.libraries.NewLibraryConfiguration
import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.idea.base.platforms.KotlinCommonLibraryKind
import javax.swing.JComponent
object CommonLibraryType : LibraryType<DummyLibraryProperties>(CommonLibraryKind) {
object CommonLibraryType : LibraryType<DummyLibraryProperties>(KotlinCommonLibraryKind) {
override fun createPropertiesEditor(editorComponent: LibraryEditorComponent<DummyLibraryProperties>) = null
override fun getCreateActionName() = null

View File

@@ -1,18 +0,0 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.framework
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
interface LibraryEffectiveKindProvider {
fun getEffectiveKind(library: LibraryEx): PersistentLibraryKind<*>?
companion object {
fun getInstance(project: Project): LibraryEffectiveKindProvider = project.service()
}
}
fun LibraryEx.effectiveKind(project: Project) = LibraryEffectiveKindProvider.getInstance(project).getEffectiveKind(this)

View File

@@ -1,87 +0,0 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.framework
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.libraries.DummyLibraryProperties
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.util.io.JarUtil
import com.intellij.openapi.vfs.*
import org.jetbrains.kotlin.caches.resolve.IdePlatformKindResolution
import org.jetbrains.kotlin.caches.resolve.resolution
import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion
import org.jetbrains.kotlin.idea.vfilefinder.KnownLibraryKindForIndex
import org.jetbrains.kotlin.idea.vfilefinder.getLibraryKindForJar
import org.jetbrains.kotlin.platform.CommonPlatforms
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.idePlatformKind
import org.jetbrains.kotlin.platform.js.JsPlatforms
import org.jetbrains.kotlin.utils.PathUtil
import java.util.jar.Attributes
import java.util.regex.Pattern
interface KotlinLibraryKind {
// TODO: Drop this property. See https://youtrack.jetbrains.com/issue/KT-38233
// This property returns approximate library platform, as the real platform can be evaluated only for concrete library.
val compilerPlatform: TargetPlatform
}
object JSLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.js"), KotlinLibraryKind {
override val compilerPlatform: TargetPlatform
get() = JsPlatforms.defaultJsPlatform
override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!!
}
object CommonLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.common"), KotlinLibraryKind {
override val compilerPlatform: TargetPlatform
get() = CommonPlatforms.defaultCommonPlatform
override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!!
}
// TODO: Drop this property. See https://youtrack.jetbrains.com/issue/KT-38233
// It returns approximate library platform, as the real platform can be evaluated only for concrete library.
val PersistentLibraryKind<*>?.platform: TargetPlatform
get() = when (this) {
is KotlinLibraryKind -> this.compilerPlatform
else -> DefaultIdeTargetPlatformKindProvider.defaultPlatform
}
fun detectLibraryKind(roots: Array<VirtualFile>): PersistentLibraryKind<*>? {
val jarFile = roots.firstOrNull() ?: return null
if (jarFile.fileSystem is JarFileSystem) {
// TODO: Detect library kind for Jar file using IdePlatformKindResolution.
when (jarFile.getLibraryKindForJar()) {
KnownLibraryKindForIndex.COMMON -> return CommonLibraryKind
KnownLibraryKindForIndex.JS -> return JSLibraryKind
KnownLibraryKindForIndex.UNKNOWN -> {
/* Continue detection of library kind via IdePlatformKindResolution. */
}
}
}
val matchingResolution =
IdePlatformKindResolution
.getInstances()
.firstOrNull { it.isLibraryFileForPlatform(jarFile) }
if (matchingResolution != null) return matchingResolution.libraryKind
return DefaultIdeTargetPlatformKindProvider.defaultPlatform.idePlatformKind.resolution.libraryKind
}
fun getLibraryJar(roots: Array<VirtualFile>, jarPattern: Pattern): VirtualFile? {
return roots.firstOrNull { jarPattern.matcher(it.name).matches() }
}
fun getLibraryJarVersion(library: Library, jarPattern: Pattern): IdeKotlinVersion? {
val libraryJar = getLibraryJar(library.getFiles(OrderRootType.CLASSES), jarPattern) ?: return null
return IdeKotlinVersion.fromManifest(libraryJar)
}
fun getCommonRuntimeLibraryVersion(library: Library): IdeKotlinVersion? {
return getLibraryJarVersion(library, PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN)
}

View File

@@ -2,10 +2,7 @@
package org.jetbrains.kotlin.idea.klib
import com.intellij.ide.highlighter.ArchiveFileType
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.InvalidVirtualFileAccessException
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiFileFactory
import com.intellij.psi.SingleRootFileViewProvider
import com.intellij.psi.impl.PsiFileFactoryImpl
@@ -18,79 +15,11 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.library.*
import org.jetbrains.kotlin.library.impl.BuiltInsPlatform
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.isCommon
import org.jetbrains.kotlin.platform.js.isJs
import org.jetbrains.kotlin.platform.jvm.isJvm
import org.jetbrains.kotlin.platform.konan.isNative
import org.jetbrains.kotlin.library.KotlinLibrary
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration
import org.jetbrains.kotlin.storage.StorageManager
import java.io.IOException
import java.util.*
fun VirtualFile.isKlibLibraryRootForPlatform(targetPlatform: TargetPlatform): Boolean {
// The virtual file for a library packed in a ZIP file will have path like "/some/path/to/the/file.klib!/",
// and therefore will be recognized by VFS as a directory (isDirectory == true).
// So, first, let's check the file type and file extension.
if ((fileType == ArchiveFileType.INSTANCE && extension != KLIB_FILE_EXTENSION) || !isDirectory)
return false
// run check for library root too
// this is necessary to recognize old style KLIBs that do not have components, and report tem to user appropriately
// (relevant only for Kotlin/Native KLIBs)
val requestedBuiltInsPlatform = targetPlatform.toBuiltInsPlatform()
if (requestedBuiltInsPlatform == BuiltInsPlatform.NATIVE && checkKlibComponent(this, requestedBuiltInsPlatform)) {
return true
}
try {
return children?.any { checkKlibComponent(it, requestedBuiltInsPlatform) } == true
} catch (e: InvalidVirtualFileAccessException) {
return false
}
}
private fun checkKlibComponent(componentFile: VirtualFile, requestedBuiltInsPlatform: BuiltInsPlatform): Boolean {
val manifestFile = componentFile.findChild(KLIB_MANIFEST_FILE_NAME)?.takeIf { !it.isDirectory } ?: return false
val manifestProperties = try {
manifestFile.inputStream.use { Properties().apply { load(it) } }
} catch (_: IOException) {
return false
}
if (!manifestProperties.containsKey(KLIB_PROPERTY_UNIQUE_NAME)) return false
val builtInsPlatformProperty = manifestProperties.getProperty(KLIB_PROPERTY_BUILTINS_PLATFORM)
// No builtins_platform property => either a new common klib (we don't write builtins_platform for common) or old Native klib
?: return when (requestedBuiltInsPlatform) {
BuiltInsPlatform.NATIVE -> componentFile.isLegacyNativeKlibComponent // TODO(dsavvinov): drop additional legacy check after 1.4
BuiltInsPlatform.COMMON -> !componentFile.isLegacyNativeKlibComponent
else -> false
}
val builtInsPlatform = BuiltInsPlatform.parseFromString(builtInsPlatformProperty) ?: return false
return builtInsPlatform == requestedBuiltInsPlatform
}
private fun TargetPlatform.toBuiltInsPlatform() = when {
isCommon() -> BuiltInsPlatform.COMMON
isNative() -> BuiltInsPlatform.NATIVE
isJvm() -> BuiltInsPlatform.JVM
isJs() -> BuiltInsPlatform.JS
else -> throw IllegalArgumentException("Unknown platform $this")
}
private val VirtualFile.isLegacyNativeKlibComponent: Boolean
get() {
val irFolder = findChild(KLIB_IR_FOLDER_NAME)
return irFolder != null && irFolder.children.isNotEmpty()
}
fun <T> KotlinLibrary.safeRead(defaultValue: T, action: KotlinLibrary.() -> T) = try {
action()

View File

@@ -1,10 +0,0 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
@file:JvmName("IjPlatformUtil")
package org.jetbrains.kotlin.idea.util
import com.intellij.openapi.projectRoots.ProjectJdkTable
import org.jetbrains.kotlin.idea.util.application.runReadAction
fun getProjectJdkTableSafe(): ProjectJdkTable = runReadAction { ProjectJdkTable.getInstance() }

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-reflect" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.platforms" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.base.jps" />
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.util.ui" />
<orderEntry type="module" module-name="intellij.platform.ide.impl" />
<orderEntry type="module" module-name="intellij.java" />
<orderEntry type="module" module-name="intellij.java.ui" />
<orderEntry type="module" module-name="intellij.java.compiler.impl" />
</component>
</module>

View File

@@ -0,0 +1,58 @@
facet.name.general=General
facet.column.name.options=Options
facet.column.name.plugin=Plugin
facet.name.compiler.plugins=Compiler Plugins
facet.text.following.options.are.not.correct=Following options are not correct:
facet.label.text.target.platform=Target platform:
facet.label.text.selected.target.platforms=Selected target platforms:
facet.label.text.the.project.is.imported.from.external.build.system.and.could.not.be.edited=The project is imported from external build system and could not be edited
facet.checkbox.text.use.project.settings=Use project settings
facet.label.text.project.settings.that.are.used.for.this.facet=Project settings that are used for this facet:
facet.text.multiplatform=Multiplatform
facet.link.text.edit.project.settings=Edit project settings
facet.error.text.at.least.one.target.platform.should.be.selected=At least one target platform should be selected
facet.text.following.arguments.are.redundant=Following arguments are redundant: {0}
facet.text.following.arguments.override.facet.settings=Following arguments override facet settings: {0}
facets.editor.general.tab.label.depends.on.0=Depends on: {0}.
configuration.description.plain.put.to.global.scope=Plain (put to global scope)
configuration.description.amd=AMD
configuration.description.commonjs=CommonJS
configuration.description.umd.detect.amd.or.commonjs.if.available.fallback.to.plain=UMD (detect AMD or CommonJS if available, fallback to plain)
configuration.description.always=Always
configuration.description.never=Never
configuration.description.when.inlining.a.function.from.other.module.with.embedded.sources=When inlining a function from other module with embedded sources
configuration.title.kotlin.compiler.js.option.output.prefix.browse.title=Choose File to Prepend to Generated Code
configuration.title.kotlin.compiler.js.option.output.postfix.browse.title=Choose File to Append to Generated Code
configuration.title.choose.output.directory=Choose Output Directory
configuration.warning.text.modules.override.project.settings={0} modules override project settings
configuration.warning.text.following.modules.override.project.settings=Following modules override project settings:
configuration.text.and=and
configuration.text.other.s=other(s)
loading.available.versions.from.maven=Loading available versions from Maven...
failed.fetching.all.available.versions.from.maven=Failed fetching all available versions from Maven
configuration.name.kotlin.compiler=Kotlin Compiler
configuration.text.bundled.0.jps.version=Bundled ({0})
configuration.text.0.unsupported.jps.version={0} (Unsupported)
deprecated.jvm.version=(deprecated)
configuration.warning.text.language.version.unsupported=Language version {0} is no longer supported
configuration.warning.text.api.version.unsupported=API version {0} is no longer supported

View File

@@ -0,0 +1,16 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.compilerPreferences
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
import org.jetbrains.kotlin.util.AbstractKotlinBundle
@NonNls
private const val BUNDLE = "messages.KotlinBaseCompilerConfigurationUiBundle"
object KotlinBaseCompilerConfigurationUiBundle : AbstractKotlinBundle(BUNDLE) {
@Nls
@JvmStatic
fun message(@NonNls @PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): String = getMessage(key, *params)
}

View File

@@ -0,0 +1,29 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.compilerPreferences
import com.intellij.facet.ui.*
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.idea.base.compilerPreferences.facet.KotlinFacetCompilerPluginsTab
import org.jetbrains.kotlin.idea.base.compilerPreferences.facet.KotlinFacetEditorGeneralTab
import org.jetbrains.kotlin.idea.base.compilerPreferences.facet.MultipleKotlinFacetEditor
import org.jetbrains.kotlin.idea.facet.KotlinFacetConfiguration
import org.jetbrains.kotlin.idea.facet.KotlinFacetEditorProviderService
class KotlinFacetEditorProviderServiceImpl : KotlinFacetEditorProviderService {
override fun getEditorTabs(
configuration: KotlinFacetConfiguration,
editorContext: FacetEditorContext,
validatorsManager: FacetValidatorsManager
): List<FacetEditorTab> {
val tabs = ArrayList<FacetEditorTab>(2)
tabs += KotlinFacetEditorGeneralTab(configuration, editorContext, validatorsManager)
if (KotlinFacetCompilerPluginsTab.parsePluginOptions(configuration).isNotEmpty()) {
tabs += KotlinFacetCompilerPluginsTab(configuration, validatorsManager)
}
return tabs
}
override fun getMultipleConfigurationEditor(project: Project, editors: Array<out FacetEditor>): MultipleFacetSettingsEditor {
return MultipleKotlinFacetEditor(project, editors)
}
}

View File

@@ -1,12 +1,14 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.compiler.configuration;
package org.jetbrains.kotlin.idea.base.compilerPreferences.configuration;
import com.intellij.openapi.util.NlsSafe;
import kotlin.KotlinVersion;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.KotlinBundle;
import org.jetbrains.kotlin.idea.base.compilerPreferences.KotlinBaseCompilerConfigurationUiBundle;
import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion;
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinJpsPluginSettings;
import org.jetbrains.kotlin.utils.DescriptionAware;
import java.util.Objects;
@@ -41,13 +43,13 @@ class JpsVersionItem implements DescriptionAware {
public @NotNull String getDescription() {
if (myVersion == null) return Objects.requireNonNull(myText);
if (myVersion.equals(KotlinJpsPluginSettings.getBundledVersion())) {
return KotlinBundle.message("configuration.text.bundled.0.jps.version", myVersion);
return KotlinBaseCompilerConfigurationUiBundle.message("configuration.text.bundled.0.jps.version", myVersion);
}
KotlinVersion kotlinVersion = myVersion.getKotlinVersion();
if (kotlinVersion.compareTo(KotlinJpsPluginSettings.getJpsMinimumSupportedVersion()) < 0 ||
kotlinVersion.compareTo(KotlinJpsPluginSettings.getJpsMaximumSupportedVersion()) > 0) {
return KotlinBundle.message("configuration.text.0.unsupported.jps.version", myVersion);
return KotlinBaseCompilerConfigurationUiBundle.message("configuration.text.0.unsupported.jps.version", myVersion);
}
return myVersion.toString();

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerConfigurableTab">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.idea.base.compilerPreferences.configuration.KotlinCompilerConfigurableTab">
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="13" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>

View File

@@ -1,7 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.compiler.configuration;
package org.jetbrains.kotlin.idea.base.compilerPreferences.configuration;
import com.intellij.compiler.server.BuildManager;
import com.intellij.icons.AllIcons;
import com.intellij.jarRepository.JarRepositoryManager;
import com.intellij.openapi.Disposable;
@@ -35,14 +36,15 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.utils.library.RepositoryLibraryDescription;
import org.jetbrains.kotlin.base.util.KotlinPlatformUtils;
import org.jetbrains.kotlin.base.util.ProjectStructureUtils;
import org.jetbrains.kotlin.cli.common.arguments.*;
import org.jetbrains.kotlin.config.*;
import org.jetbrains.kotlin.idea.KotlinBundle;
import org.jetbrains.kotlin.idea.PluginStartupApplicationService;
import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts;
import org.jetbrains.kotlin.idea.facet.DescriptionListCellRenderer;
import org.jetbrains.kotlin.idea.base.compilerPreferences.KotlinBaseCompilerConfigurationUiBundle;
import org.jetbrains.kotlin.idea.base.compilerPreferences.facet.DescriptionListCellRenderer;
import org.jetbrains.kotlin.idea.compiler.configuration.*;
import org.jetbrains.kotlin.idea.facet.KotlinFacet;
import org.jetbrains.kotlin.idea.roots.RootUtilsKt;
import org.jetbrains.kotlin.idea.util.application.ApplicationUtilsKt;
import org.jetbrains.kotlin.platform.IdePlatformKind;
import org.jetbrains.kotlin.platform.PlatformUtilKt;
@@ -64,17 +66,17 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
static {
moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_PLAIN,
KotlinBundle.message("configuration.description.plain.put.to.global.scope"));
moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_AMD, KotlinBundle.message("configuration.description.amd"));
moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_COMMONJS, KotlinBundle.message("configuration.description.commonjs"));
moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_UMD, KotlinBundle.message(
KotlinBaseCompilerConfigurationUiBundle.message("configuration.description.plain.put.to.global.scope"));
moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_AMD, KotlinBaseCompilerConfigurationUiBundle.message("configuration.description.amd"));
moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_COMMONJS, KotlinBaseCompilerConfigurationUiBundle.message("configuration.description.commonjs"));
moduleKindDescriptions.put(K2JsArgumentConstants.MODULE_UMD, KotlinBaseCompilerConfigurationUiBundle.message(
"configuration.description.umd.detect.amd.or.commonjs.if.available.fallback.to.plain"));
sourceMapSourceEmbeddingDescriptions
.put(K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_NEVER, KotlinBundle.message("configuration.description.never"));
.put(K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_NEVER, KotlinBaseCompilerConfigurationUiBundle.message("configuration.description.never"));
sourceMapSourceEmbeddingDescriptions
.put(K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_ALWAYS, KotlinBundle.message("configuration.description.always"));
sourceMapSourceEmbeddingDescriptions.put(K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING, KotlinBundle.message(
.put(K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_ALWAYS, KotlinBaseCompilerConfigurationUiBundle.message("configuration.description.always"));
sourceMapSourceEmbeddingDescriptions.put(K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING, KotlinBaseCompilerConfigurationUiBundle.message(
"configuration.description.when.inlining.a.function.from.other.module.with.embedded.sources"));
}
@@ -195,13 +197,13 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
private void initializeNonCidrSettings(boolean isMultiEditor) {
setupFileChooser(labelForOutputPrefixFile, outputPrefixFile,
KotlinBundle.message("configuration.title.kotlin.compiler.js.option.output.prefix.browse.title"),
KotlinBaseCompilerConfigurationUiBundle.message("configuration.title.kotlin.compiler.js.option.output.prefix.browse.title"),
true);
setupFileChooser(labelForOutputPostfixFile, outputPostfixFile,
KotlinBundle.message("configuration.title.kotlin.compiler.js.option.output.postfix.browse.title"),
KotlinBaseCompilerConfigurationUiBundle.message("configuration.title.kotlin.compiler.js.option.output.postfix.browse.title"),
true);
setupFileChooser(labelForOutputDirectory, outputDirectory,
KotlinBundle.message("configuration.title.choose.output.directory"),
KotlinBaseCompilerConfigurationUiBundle.message("configuration.title.choose.output.directory"),
false);
fillModuleKindList();
@@ -243,12 +245,12 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
int nameCountToShow = calculateNameCountToShowInWarning(modulesOverridingProjectSettings);
int allNamesCount = modulesOverridingProjectSettings.size();
if (nameCountToShow == 0) {
return KotlinBundle.message("configuration.warning.text.modules.override.project.settings", String.valueOf(allNamesCount));
return KotlinBaseCompilerConfigurationUiBundle.message("configuration.warning.text.modules.override.project.settings", String.valueOf(allNamesCount));
}
StringBuilder builder = new StringBuilder();
builder.append("<html>");
builder.append(KotlinBundle.message("configuration.warning.text.following.modules.override.project.settings")).append(" ");
builder.append(KotlinBaseCompilerConfigurationUiBundle.message("configuration.warning.text.following.modules.override.project.settings")).append(" ");
CollectionsKt.joinTo(
modulesOverridingProjectSettings.subList(0, nameCountToShow),
builder,
@@ -265,8 +267,8 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
}
);
if (nameCountToShow < allNamesCount) {
builder.append(" ").append(KotlinBundle.message("configuration.text.and")).append(" ").append(allNamesCount - nameCountToShow)
.append(" ").append(KotlinBundle.message("configuration.text.other.s"));
builder.append(" ").append(KotlinBaseCompilerConfigurationUiBundle.message("configuration.text.and")).append(" ").append(allNamesCount - nameCountToShow)
.append(" ").append(KotlinBaseCompilerConfigurationUiBundle.message("configuration.text.other.s"));
}
return builder.toString();
}
@@ -384,7 +386,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
JvmTarget jvmTarget = PlatformUtilKt.subplatformsOfType(jvm, JdkPlatform.class).get(0).getTargetVersion();
@NlsSafe String description = jvmTarget.getDescription();
if (jvmTarget == JvmTarget.JVM_1_6) {
description += " " + KotlinBundle.message("deprecated.jvm.version");
description += " " + KotlinBaseCompilerConfigurationUiBundle.message("deprecated.jvm.version");
}
jvmVersionComboBox.addItem(description);
@@ -448,7 +450,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
jpsPluginComboBoxModel.add(0, new JpsVersionItem(bundledVersion));
}
JpsVersionItem loadingItem = JpsVersionItem.createLabel(KotlinBundle.message("loading.available.versions.from.maven"));
JpsVersionItem loadingItem = JpsVersionItem.createLabel(KotlinBaseCompilerConfigurationUiBundle.message("loading.available.versions.from.maven"));
kotlinJpsPluginVersionComboBox.addItem(loadingItem);
PopupMenuListenerAdapter popupListener = new PopupMenuListenerAdapter() {
@Override
@@ -460,7 +462,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
if (availableVersions == null) {
kotlinJpsPluginVersionComboBox.addItem(
JpsVersionItem.createLabel(
KotlinBundle.message("failed.fetching.all.available.versions.from.maven")
KotlinBaseCompilerConfigurationUiBundle.message("failed.fetching.all.available.versions.from.maven")
)
);
} else {
@@ -631,7 +633,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
new Function0<>() {
@Override
public Object invoke() {
RootUtilsKt.invalidateProjectRoots(project, RootsChangeRescanningInfo.NO_RESCAN_NEEDED);
ProjectStructureUtils.invalidateProjectRoots(project, RootsChangeRescanningInfo.NO_RESCAN_NEEDED);
return null;
}
}
@@ -688,9 +690,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
KotlinCompilerSettings.getInstance(project).setSettings(compilerSettings);
}
for (ClearBuildStateExtension extension : ClearBuildStateExtension.getExtensions()) {
extension.clearState(project);
}
BuildManager.getInstance().clearState(project);
}
@Override
@@ -749,7 +749,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
@Nls
@Override
public String getDisplayName() {
return KotlinBundle.message("configuration.name.kotlin.compiler");
return KotlinBaseCompilerConfigurationUiBundle.message("configuration.name.kotlin.compiler");
}
@Nullable
@@ -896,7 +896,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Di
LanguageOrApiVersion version = selectedItem.getVersion();
if (version.isUnsupported()) {
return new ValidationInfo(KotlinBundle.message(messageKey, version.getVersionString()), component);
return new ValidationInfo(KotlinBaseCompilerConfigurationUiBundle.message(messageKey, version.getVersionString()), component);
}
return null;

View File

@@ -1,6 +1,6 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.facet
package org.jetbrains.kotlin.idea.base.compilerPreferences.facet
import org.jetbrains.kotlin.utils.DescriptionAware
import java.awt.Component

View File

@@ -1,6 +1,6 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.facet
package org.jetbrains.kotlin.idea.base.compilerPreferences.facet
import com.intellij.facet.ui.FacetEditorTab
import com.intellij.facet.ui.FacetEditorValidator
@@ -11,7 +11,8 @@ import com.intellij.ui.ScrollPaneFactory
import com.intellij.ui.table.JBTable
import org.jetbrains.kotlin.compiler.plugin.CliOptionValue
import org.jetbrains.kotlin.compiler.plugin.parsePluginOption
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.base.compilerPreferences.KotlinBaseCompilerConfigurationUiBundle
import org.jetbrains.kotlin.idea.facet.KotlinFacetConfiguration
import java.awt.BorderLayout
import java.awt.Component
import javax.swing.*
@@ -61,8 +62,8 @@ class KotlinFacetCompilerPluginsTab(
override fun getColumnCount() = 2
override fun getColumnName(column: Int) = when (column) {
0 -> KotlinBundle.message("facet.column.name.plugin")
else -> KotlinBundle.message("facet.column.name.options")
0 -> KotlinBaseCompilerConfigurationUiBundle.message("facet.column.name.plugin")
else -> KotlinBaseCompilerConfigurationUiBundle.message("facet.column.name.options")
}
override fun getColumnClass(columnIndex: Int) = String::class.java
@@ -118,7 +119,7 @@ class KotlinFacetCompilerPluginsTab(
if (invalidOptions.isNotEmpty()) {
@NlsSafe
val message = buildString {
append(KotlinBundle.message("facet.text.following.options.are.not.correct"))
append(KotlinBaseCompilerConfigurationUiBundle.message("facet.text.following.options.are.not.correct"))
append(" <br/>")
invalidOptions.joinTo(this, "<br/>") { "<strong>$it</strong>" }
}
@@ -141,7 +142,7 @@ class KotlinFacetCompilerPluginsTab(
validatorsManager.registerValidator(OptionValidator())
}
override fun getDisplayName() = KotlinBundle.message("facet.name.compiler.plugins")
override fun getDisplayName() = KotlinBaseCompilerConfigurationUiBundle.message("facet.name.compiler.plugins")
override fun createComponent(): JComponent {
val panel = JPanel(BorderLayout())

View File

@@ -1,6 +1,6 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.facet
package org.jetbrains.kotlin.idea.base.compilerPreferences.facet
import com.intellij.facet.ui.*
import com.intellij.icons.AllIcons
@@ -12,12 +12,15 @@ import com.intellij.openapi.util.NlsSafe
import com.intellij.ui.HoverHyperlinkLabel
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.ThreeStateCheckBox
import org.jetbrains.kotlin.base.util.invalidateProjectRoots
import org.jetbrains.kotlin.base.util.onTextChange
import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.base.compilerPreferences.KotlinBaseCompilerConfigurationUiBundle
import org.jetbrains.kotlin.idea.base.compilerPreferences.configuration.KotlinCompilerConfigurableTab
import org.jetbrains.kotlin.idea.compiler.configuration.*
import org.jetbrains.kotlin.idea.core.util.onTextChange
import org.jetbrains.kotlin.idea.roots.invalidateProjectRoots
import org.jetbrains.kotlin.idea.facet.KotlinFacetConfiguration
import org.jetbrains.kotlin.idea.facet.getExposedFacetFields
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.platform.*
import org.jetbrains.kotlin.platform.js.isJs
@@ -87,12 +90,12 @@ class KotlinFacetEditorGeneralTab(
private var isInTargetPlatformChangeAction = false
private fun FormBuilder.addTargetPlatformComponents(): FormBuilder {
targetPlatformFacetLabel = JLabel(KotlinBundle.message("facet.label.text.target.platform"))
targetPlatformFacetLabel = JLabel(KotlinBaseCompilerConfigurationUiBundle.message("facet.label.text.target.platform"))
return if (configuration?.settings?.mppVersion?.isHmpp == true) {
targetPlatformLabel.toolTipText =
KotlinBundle.message("facet.label.text.the.project.is.imported.from.external.build.system.and.could.not.be.edited")
KotlinBaseCompilerConfigurationUiBundle.message("facet.label.text.the.project.is.imported.from.external.build.system.and.could.not.be.edited")
addLabeledComponent(
KotlinBundle.message("facet.label.text.selected.target.platforms"), targetPlatformLabel
KotlinBaseCompilerConfigurationUiBundle.message("facet.label.text.selected.target.platforms"), targetPlatformLabel
)
} else {
addLabeledComponent(
@@ -143,12 +146,12 @@ class KotlinFacetEditorGeneralTab(
isMultiEditor
)
useProjectSettingsCheckBox = ThreeStateCheckBox(KotlinBundle.message("facet.checkbox.text.use.project.settings")).apply {
useProjectSettingsCheckBox = ThreeStateCheckBox(KotlinBaseCompilerConfigurationUiBundle.message("facet.checkbox.text.use.project.settings")).apply {
isThirdStateEnabled = isMultiEditor
}
useProjectSettingsWarningLabel = JLabel().apply {
icon = AllIcons.General.WarningDialog
text = KotlinBundle.message("facet.label.text.project.settings.that.are.used.for.this.facet")
text = KotlinBaseCompilerConfigurationUiBundle.message("facet.label.text.project.settings.that.are.used.for.this.facet")
iconTextGap = 5
isVisible = false
}
@@ -169,10 +172,10 @@ class KotlinFacetEditorGeneralTab(
): Component {
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus).apply {
val specificPlatform = (value as? TargetPlatformWrapper)?.targetPlatform?.componentPlatforms?.singleOrNull()
text = specificPlatform?.oldFashionedDescription ?: KotlinBundle.message("facet.text.multiplatform")
text = specificPlatform?.oldFashionedDescription ?: KotlinBaseCompilerConfigurationUiBundle.message("facet.text.multiplatform")
if (specificPlatform is JdkPlatform && specificPlatform.targetVersion == JvmTarget.JVM_1_6) {
text += " " + KotlinBundle.message("deprecated.jvm.version")
text += " " + KotlinBaseCompilerConfigurationUiBundle.message("deprecated.jvm.version")
}
}
}
@@ -180,7 +183,7 @@ class KotlinFacetEditorGeneralTab(
}
targetPlatformSelectSingleCombobox.maximumRowCount =
targetPlatformsComboboxRowsCount(targetPlatformWrappers.size)
projectSettingsLink = HoverHyperlinkLabel(KotlinBundle.message("facet.link.text.edit.project.settings")).apply {
projectSettingsLink = HoverHyperlinkLabel(KotlinBaseCompilerConfigurationUiBundle.message("facet.link.text.edit.project.settings")).apply {
addHyperlinkListener {
ShowSettingsUtilImpl.showSettingsDialog(project, compilerConfigurable.id, "")
if (useProjectSettingsCheckBox.isSelected) {
@@ -274,7 +277,7 @@ class KotlinFacetEditorGeneralTab(
inner class ArgumentConsistencyValidator : FacetEditorValidator() {
override fun check(): ValidationResult {
val platform = editor.getChosenPlatform() ?: return ValidationResult(
KotlinBundle.message("facet.error.text.at.least.one.target.platform.should.be.selected")
KotlinBaseCompilerConfigurationUiBundle.message("facet.error.text.at.least.one.target.platform.should.be.selected")
)
val primaryArguments = platform.createArguments {
editor.compilerConfigurable.applyTo(
@@ -290,12 +293,7 @@ class KotlinFacetEditorGeneralTab(
validateArguments(errors)?.let { message -> return ValidationResult(message) }
}
val emptyArguments = argumentClass.newInstance()
val fieldNamesToCheck = when {
platform.isJvm() -> jvmUIExposedFields
platform.isJs() -> jsUIExposedFields
platform.isCommon() -> metadataUIExposedFields
else -> commonUIExposedFields
}
val fieldNamesToCheck = getExposedFacetFields(platform.idePlatformKind)
val propertiesToCheck = collectProperties(argumentClass.kotlin, false).filter { it.name in fieldNamesToCheck }
val overridingArguments = ArrayList<String>()
@@ -313,7 +311,7 @@ class KotlinFacetEditorGeneralTab(
val message = buildString {
if (overridingArguments.isNotEmpty()) {
append(
KotlinBundle.message(
KotlinBaseCompilerConfigurationUiBundle.message(
"facet.text.following.arguments.override.facet.settings",
overridingArguments.joinToString()
)
@@ -324,7 +322,10 @@ class KotlinFacetEditorGeneralTab(
append("<br/>")
}
append(
KotlinBundle.message("facet.text.following.arguments.are.redundant", redundantArguments.joinToString())
KotlinBaseCompilerConfigurationUiBundle.message(
"facet.text.following.arguments.are.redundant",
redundantArguments.joinToString()
)
)
}
}
@@ -441,7 +442,7 @@ class KotlinFacetEditorGeneralTab(
?: "<none>"
editor.dependsOnLabel.isVisible = configuration.settings.dependsOnModuleNames.isNotEmpty()
editor.dependsOnLabel.text =
KotlinBundle.message(
KotlinBaseCompilerConfigurationUiBundle.message(
"facets.editor.general.tab.label.depends.on.0",
configuration.settings.dependsOnModuleNames.joinToString()
)
@@ -491,7 +492,7 @@ class KotlinFacetEditorGeneralTab(
}
}
override fun getDisplayName() = KotlinBundle.message("facet.name.general")
override fun getDisplayName() = KotlinBaseCompilerConfigurationUiBundle.message("facet.name.general")
override fun createComponent(): JComponent {
return editor
@@ -505,5 +506,5 @@ class KotlinFacetEditorGeneralTab(
}
@Suppress("UNCHECKED_CAST")
val <T> ComboBox<T>.selectedItemTyped: T?
private val <T> ComboBox<T>.selectedItemTyped: T?
get() = selectedItem as T?

View File

@@ -1,17 +1,17 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.facet
package org.jetbrains.kotlin.idea.base.compilerPreferences.facet
import com.intellij.facet.ui.FacetEditorContext
import com.intellij.facet.ui.FacetEditorValidator
import com.intellij.facet.ui.FacetValidatorsManager
import com.intellij.openapi.extensions.ExtensionPointName
import org.jetbrains.kotlin.idea.facet.KotlinFacetEditorGeneralTab.EditorComponent
import org.jetbrains.kotlin.idea.base.compilerPreferences.facet.KotlinFacetEditorGeneralTab.EditorComponent
abstract class KotlinFacetValidatorCreator {
companion object {
val EP_NAME: ExtensionPointName<KotlinFacetValidatorCreator> =
ExtensionPointName.create<KotlinFacetValidatorCreator>("org.jetbrains.kotlin.facetValidatorCreator")
ExtensionPointName.create("org.jetbrains.kotlin.facetValidatorCreator")
}
abstract fun create(

View File

@@ -1,14 +1,15 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.facet
package org.jetbrains.kotlin.idea.base.compilerPreferences.facet
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.LibraryOrderEntry
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ModuleRootModel
import org.jetbrains.kotlin.idea.base.platforms.IdePlatformKindProjectStructure
import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayout
import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.facet.KotlinVersionInfoProvider
import org.jetbrains.kotlin.platform.IdePlatformKind
class KotlinVersionInfoProviderByModuleDependencies : KotlinVersionInfoProvider {
@@ -23,7 +24,7 @@ class KotlinVersionInfoProviderByModuleDependencies : KotlinVersionInfoProvider
return emptyList()
}
val versionProvider = platformKind.tooling.getLibraryVersionProvider(module.project)
val versionProvider = IdePlatformKindProjectStructure.getInstance(module.project).getLibraryVersionProvider(platformKind)
val orderEntries = (rootModel ?: ModuleRootManager.getInstance(module)).orderEntries
return mutableListOf<IdeKotlinVersion>().apply {

View File

@@ -1,12 +1,12 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.facet
package org.jetbrains.kotlin.idea.base.compilerPreferences.facet
import com.intellij.facet.ui.FacetEditor
import com.intellij.facet.ui.FacetEditorsFactory
import com.intellij.facet.ui.MultipleFacetSettingsEditor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerConfigurableTab
import org.jetbrains.kotlin.idea.base.compilerPreferences.configuration.KotlinCompilerConfigurableTab
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
import javax.swing.JComponent

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.platforms" />
<orderEntry type="module" module-name="kotlin.base.resources" />
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="module" module-name="intellij.platform.lang.core" />
<orderEntry type="module" module-name="intellij.platform.projectModel" />
<orderEntry type="module" module-name="intellij.platform.externalSystem" />
<orderEntry type="module" module-name="intellij.java" />
<orderEntry type="module" module-name="intellij.java.impl" />
</component>
</module>

View File

@@ -0,0 +1 @@
framework.name.kotlin.sdk=Kotlin SDK

View File

@@ -0,0 +1,16 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.facet
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
import org.jetbrains.kotlin.util.AbstractKotlinBundle
@NonNls
private const val BUNDLE = "messages.KotlinBaseFacetBundle"
object KotlinBaseFacetBundle : AbstractKotlinBundle(BUNDLE) {
@Nls
@JvmStatic
fun message(@NonNls @PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): String = getMessage(key, *params)
}

View File

@@ -14,7 +14,7 @@ class KotlinFacet(
companion object {
fun get(module: Module): KotlinFacet? {
if (module.isDisposed) return null
return FacetManager.getInstance(module).getFacetByType<KotlinFacet>(KotlinFacetType.TYPE_ID)
return FacetManager.getInstance(module).getFacetByType(KotlinFacetType.TYPE_ID)
}
}
}

View File

@@ -30,10 +30,8 @@ class KotlinFacetConfigurationImpl : KotlinFacetConfiguration {
): Array<FacetEditorTab> {
settings.initializeIfNeeded(editorContext.module, editorContext.rootModel)
val tabs = arrayListOf<FacetEditorTab>(KotlinFacetEditorGeneralTab(this, editorContext, validatorsManager))
if (KotlinFacetCompilerPluginsTab.parsePluginOptions(this).isNotEmpty()) {
tabs += KotlinFacetCompilerPluginsTab(this, validatorsManager)
}
val tabs = arrayListOf<FacetEditorTab>()
tabs += KotlinFacetEditorProviderService.getInstance(editorContext.project).getEditorTabs(this, editorContext, validatorsManager)
KotlinFacetConfigurationExtension.EP_NAME.extensions.flatMapTo(tabs) { it.createEditorTabs(editorContext, validatorsManager) }
return tabs.toTypedArray()
}

View File

@@ -0,0 +1,21 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.facet
import com.intellij.facet.ui.*
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
interface KotlinFacetEditorProviderService {
fun getEditorTabs(
configuration: KotlinFacetConfiguration,
editorContext: FacetEditorContext,
validatorsManager: FacetValidatorsManager
): List<FacetEditorTab>
fun getMultipleConfigurationEditor(project: Project, editors: Array<out FacetEditor>): MultipleFacetSettingsEditor
companion object {
@JvmStatic
fun getInstance(project: Project): KotlinFacetEditorProviderService = project.service()
}
}

View File

@@ -0,0 +1,94 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:JvmName("KotlinFacetFieldsUtils")
package org.jetbrains.kotlin.idea.facet
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
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
fun getExposedFacetFields(platformKind: IdePlatformKind): List<String> {
val fields = when (platformKind) {
is JvmIdePlatformKind -> jvmFields
is JsIdePlatformKind -> jsFields
is CommonIdePlatformKind -> metadataFields
else -> commonFields
}
return fields.exposedFields
}
internal class KotlinFacetFields(
base: KotlinFacetFields? = null,
exposedFields: List<String>,
hiddenFields: List<String>
) {
val exposedFields: List<String> = if (base != null) base.exposedFields + exposedFields else exposedFields
private val hiddenFields: List<String> = if (base != null) base.hiddenFields + hiddenFields else hiddenFields
val allFields: List<String>
get() = exposedFields + hiddenFields
}
internal val commonFields = KotlinFacetFields(
exposedFields = listOf(
CommonCompilerArguments::languageVersion.name,
CommonCompilerArguments::apiVersion.name,
CommonCompilerArguments::suppressWarnings.name
),
hiddenFields = listOf(
CommonCompilerArguments::pluginClasspaths.name,
CommonCompilerArguments::pluginOptions.name,
CommonCompilerArguments::multiPlatform.name
)
)
internal val jvmFields = KotlinFacetFields(
base = commonFields,
exposedFields = listOf(
K2JVMCompilerArguments::jvmTarget.name,
K2JVMCompilerArguments::destination.name,
K2JVMCompilerArguments::classpath.name
),
hiddenFields = listOf(
K2JVMCompilerArguments::friendPaths.name
)
)
internal val jsFields = KotlinFacetFields(
base = commonFields,
exposedFields = listOf(
K2JSCompilerArguments::sourceMap.name,
K2JSCompilerArguments::sourceMapPrefix.name,
K2JSCompilerArguments::sourceMapEmbedSources.name,
K2JSCompilerArguments::outputPrefix.name,
K2JSCompilerArguments::outputPostfix.name,
K2JSCompilerArguments::moduleKind.name
),
hiddenFields = emptyList()
)
internal val metadataFields = KotlinFacetFields(
base = commonFields,
exposedFields = listOf(
K2MetadataCompilerArguments::destination.name,
K2MetadataCompilerArguments::classpath.name
),
hiddenFields = emptyList()
)
internal val CommonCompilerArguments.primaryFields: List<String>
get() = when (this) {
is K2JVMCompilerArguments -> jvmFields.allFields
is K2JSCompilerArguments -> jsFields.allFields
is K2MetadataCompilerArguments -> metadataFields.allFields
else -> commonFields.allFields
}
internal val CommonCompilerArguments.ignoredFields: List<String>
get() = when (this) {
is K2JVMCompilerArguments -> listOf(K2JVMCompilerArguments::noJdk.name, K2JVMCompilerArguments::jdkHome.name)
else -> emptyList()
}

View File

@@ -4,11 +4,11 @@ package org.jetbrains.kotlin.idea.facet
import com.intellij.facet.Facet
import com.intellij.facet.ui.FacetEditor
import com.intellij.facet.ui.MultipleFacetSettingsEditor
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
class KotlinFacetTypeImpl : KotlinFacetType<KotlinFacetConfiguration>() {
override fun createDefaultConfiguration() = KotlinFacetConfigurationImpl()
override fun createFacet(
@@ -18,6 +18,7 @@ class KotlinFacetTypeImpl : KotlinFacetType<KotlinFacetConfiguration>() {
underlyingFacet: Facet<*>?
) = KotlinFacet(module, name, configuration)
override fun createMultipleConfigurationsEditor(project: Project, editors: Array<out FacetEditor>) =
MultipleKotlinFacetEditor(project, editors)
override fun createMultipleConfigurationsEditor(project: Project, editors: Array<out FacetEditor>): MultipleFacetSettingsEditor {
return KotlinFacetEditorProviderService.getInstance(project).getMultipleConfigurationEditor(project, editors)
}
}

View File

@@ -0,0 +1,254 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:JvmName("KotlinFacetUtils")
package org.jetbrains.kotlin.idea.facet
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
import com.intellij.openapi.module.Module
import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.projectRoots.JavaSdkVersion
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ModuleRootModel
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.base.util.isAndroidModule
import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.idea.base.platforms.IdePlatformKindProjectStructure
import org.jetbrains.kotlin.idea.compiler.configuration.*
import org.jetbrains.kotlin.idea.defaultSubstitutors
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.idePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
import kotlin.reflect.KProperty1
var Module.hasExternalSdkConfiguration: Boolean by NotNullableUserDataProperty(Key.create("HAS_EXTERNAL_SDK_CONFIGURATION"), false)
fun KotlinFacetSettings.initializeIfNeeded(
module: Module,
rootModel: ModuleRootModel?,
platform: TargetPlatform? = null, // if null, detect by module dependencies
compilerVersion: IdeKotlinVersion? = null
) {
val project = module.project
val shouldInferLanguageLevel = languageLevel == null
val shouldInferAPILevel = apiLevel == null
if (compilerSettings == null) {
compilerSettings = KotlinCompilerSettings.getInstance(project).settings
}
val commonArguments = KotlinCommonCompilerArgumentsHolder.getInstance(module.project).settings
if (compilerArguments == null) {
val targetPlatform = platform ?: getDefaultTargetPlatform(module, rootModel)
compilerArguments = targetPlatform.createArguments {
val argumentsForPlatform = IdePlatformKindProjectStructure.getInstance(project)
.getCompilerArguments(targetPlatform.idePlatformKind)
if (argumentsForPlatform != null) {
mergeBeans(argumentsForPlatform, this)
}
mergeBeans(commonArguments, this)
}
this.targetPlatform = targetPlatform
}
if (shouldInferLanguageLevel) {
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
?: getDefaultLanguageLevel(module, compilerVersion, coerceRuntimeLibraryVersionToReleased = compilerVersion == null)
}
if (shouldInferAPILevel) {
apiLevel = if (useProjectSettings) {
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
} else {
val maximumValue = getLibraryVersion(
module,
rootModel,
this.targetPlatform?.idePlatformKind,
coerceRuntimeLibraryVersionToReleased = compilerVersion == null
)
languageLevel?.coerceAtMostVersion(maximumValue)
}
}
}
private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?): TargetPlatform {
val platformKind = IdePlatformKind.ALL_KINDS.firstOrNull {
getRuntimeLibraryVersions(module, rootModel, it).isNotEmpty()
} ?: DefaultIdeTargetPlatformKindProvider.defaultPlatform.idePlatformKind
if (platformKind == JvmIdePlatformKind) {
var jvmTarget = Kotlin2JvmCompilerArgumentsHolder.getInstance(module.project).settings.jvmTarget?.let { JvmTarget.fromString(it) }
if (jvmTarget == null) {
val sdk = ((rootModel ?: ModuleRootManager.getInstance(module))).sdk
val sdkVersion = (sdk?.sdkType as? JavaSdk)?.getVersion(sdk)
if (sdkVersion == null || sdkVersion >= JavaSdkVersion.JDK_1_8) {
jvmTarget = JvmTarget.JVM_1_8
}
}
return if (jvmTarget != null) JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget) else JvmPlatforms.defaultJvmPlatform
}
return platformKind.defaultPlatform
}
private fun LanguageVersion.coerceAtMostVersion(version: IdeKotlinVersion): LanguageVersion {
fun isUpToNextMinor(major: Int, minor: Int, patch: Int): Boolean {
return version.kotlinVersion.isAtLeast(major, minor, patch) && !version.kotlinVersion.isAtLeast(major, minor + 1)
}
// 1.4.30+ and 1.5.30+ have full support of next language version
val languageVersion = when {
isUpToNextMinor(1, 4, 30) -> LanguageVersion.KOTLIN_1_5
isUpToNextMinor(1, 5, 30) -> LanguageVersion.KOTLIN_1_6
else -> version.languageVersion
}
return this.coerceAtMost(languageVersion)
}
fun parseCompilerArgumentsToFacet(
arguments: List<String>,
defaultArguments: List<String>,
kotlinFacet: KotlinFacet,
modelsProvider: IdeModifiableModelsProvider?
) {
val compilerArgumentsClass = kotlinFacet.configuration.settings.compilerArguments?.javaClass ?: return
val currentArgumentsBean = compilerArgumentsClass.newInstance()
val defaultArgumentsBean = compilerArgumentsClass.newInstance()
val defaultArgumentWithDefaults = substituteDefaults(defaultArguments, defaultArgumentsBean)
val currentArgumentWithDefaults = substituteDefaults(arguments, currentArgumentsBean)
parseCommandLineArguments(defaultArgumentWithDefaults, defaultArgumentsBean)
parseCommandLineArguments(currentArgumentWithDefaults, currentArgumentsBean)
applyCompilerArgumentsToFacet(currentArgumentsBean, defaultArgumentsBean, kotlinFacet, modelsProvider)
}
fun applyCompilerArgumentsToFacet(
arguments: CommonCompilerArguments,
defaultArguments: CommonCompilerArguments?,
kotlinFacet: KotlinFacet,
modelsProvider: IdeModifiableModelsProvider?
) {
with(kotlinFacet.configuration.settings) {
val compilerArguments = this.compilerArguments ?: return
val defaultCompilerArguments = defaultArguments?.let { copyBean(it) } ?: compilerArguments::class.java.newInstance()
defaultCompilerArguments.convertPathsToSystemIndependent()
val oldPluginOptions = compilerArguments.pluginOptions
val emptyArgs = compilerArguments::class.java.newInstance()
// Ad-hoc work-around for android compilations: middle source sets could be actualized up to
// Android target, meanwhile compiler arguments are of type K2Metadata
// TODO(auskov): merge classpath once compiler arguments are removed from KotlinFacetSettings
if (arguments.javaClass == compilerArguments.javaClass) {
copyBeanTo(arguments, compilerArguments) { property, value -> value != property.get(emptyArgs) }
}
compilerArguments.pluginOptions = joinPluginOptions(oldPluginOptions, arguments.pluginOptions)
compilerArguments.convertPathsToSystemIndependent()
// Retain only fields exposed (and not explicitly ignored) in facet configuration editor.
// The rest is combined into string and stored in CompilerSettings.additionalArguments
if (modelsProvider != null)
kotlinFacet.module.configureSdkIfPossible(compilerArguments, modelsProvider)
val primaryFields = compilerArguments.primaryFields
val ignoredFields = compilerArguments.ignoredFields
fun exposeAsAdditionalArgument(property: KProperty1<CommonCompilerArguments, Any?>) =
property.name !in primaryFields && property.get(compilerArguments) != property.get(defaultCompilerArguments)
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
ArgumentUtils.convertArgumentsToStringListNoDefaults(this).joinToString(separator = " ") {
if (StringUtil.containsWhitespaces(it) || it.startsWith('"')) {
StringUtil.wrapWithDoubleQuote(StringUtil.escapeQuotes(it))
} else it
}
}
compilerSettings?.additionalArguments =
if (additionalArgumentsString.isNotEmpty()) additionalArgumentsString else CompilerSettings.DEFAULT_ADDITIONAL_ARGUMENTS
with(compilerArguments::class.java.newInstance()) {
copyFieldsSatisfying(this, compilerArguments) { exposeAsAdditionalArgument(it) || it.name in ignoredFields }
}
val languageLevel = languageLevel
val apiLevel = apiLevel
if (languageLevel != null && apiLevel != null && apiLevel > languageLevel) {
this.apiLevel = languageLevel
}
updateMergedArguments()
}
}
private fun Module.configureSdkIfPossible(compilerArguments: CommonCompilerArguments, modelsProvider: IdeModifiableModelsProvider) {
// SDK for Android module is already configured by Android plugin at this point
if (isAndroidModule(modelsProvider) || hasNonOverriddenExternalSdkConfiguration(compilerArguments)) return
val projectSdk = ProjectRootManager.getInstance(project).projectSdk
KotlinSdkType.setUpIfNeeded()
val allSdks = runReadAction { ProjectJdkTable.getInstance() }.allJdks
val sdk = if (compilerArguments is K2JVMCompilerArguments) {
val jdkHome = compilerArguments.jdkHome
when {
jdkHome != null -> allSdks.firstOrNull { it.sdkType is JavaSdk && FileUtil.comparePaths(it.homePath, jdkHome) == 0 }
projectSdk != null && projectSdk.sdkType is JavaSdk -> projectSdk
else -> allSdks.firstOrNull { it.sdkType is JavaSdk }
}
} else {
allSdks.firstOrNull { it.sdkType is KotlinSdkType }
?: modelsProvider
.modifiableModuleModel
.modules
.asSequence()
.mapNotNull { modelsProvider.getModifiableRootModel(it).sdk }
.firstOrNull { it.sdkType is KotlinSdkType }
}
val rootModel = modelsProvider.getModifiableRootModel(this)
if (sdk == null || sdk == projectSdk) {
rootModel.inheritSdk()
} else {
rootModel.sdk = sdk
}
}
private fun Module.hasNonOverriddenExternalSdkConfiguration(compilerArguments: CommonCompilerArguments): Boolean =
hasExternalSdkConfiguration && (compilerArguments !is K2JVMCompilerArguments || compilerArguments.jdkHome == null)
private fun substituteDefaults(args: List<String>, compilerArguments: CommonCompilerArguments): List<String> {
val substitutedCompilerArguments = defaultSubstitutors[compilerArguments::class]
?.filter { it.isSubstitutable(args) }
?.flatMap { it.oldSubstitution }
return args + substitutedCompilerArguments.orEmpty()
}
private fun joinPluginOptions(old: Array<String>?, new: Array<String>?): Array<String>? {
if (old == null && new == null) {
return old
} else if (new == null) {
return old
} else if (old == null) {
return new
}
return (old + new).distinct().toTypedArray()
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.framework
@@ -10,7 +10,7 @@ import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil
import com.intellij.util.Consumer
import org.jdom.Element
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.idea.KotlinIdeaAnalysisBundle
import org.jetbrains.kotlin.idea.base.facet.KotlinBaseFacetBundle
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayout
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import javax.swing.JComponent
@@ -43,7 +43,7 @@ class KotlinSdkType : SdkType("KotlinSDK") {
}
}
override fun getPresentableName() = KotlinIdeaAnalysisBundle.message("framework.name.kotlin.sdk")
override fun getPresentableName() = KotlinBaseFacetBundle.message("framework.name.kotlin.sdk")
override fun getIcon() = KotlinIcons.SMALL_LOGO

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="module" module-name="intellij.platform.lang" />
<orderEntry type="module" module-name="intellij.platform.projectModel.impl" />
<orderEntry type="module" module-name="intellij.java.compiler.impl" />
</component>
</module>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="module" module-name="intellij.platform.projectModel.impl" />
<orderEntry type="module" module-name="intellij.platform.analysis" />
<orderEntry type="module" module-name="intellij.platform.ide.core" />
</component>
</module>

View File

@@ -0,0 +1,95 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.platforms
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
import org.jetbrains.kotlin.platform.CommonPlatforms
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.NativeIdePlatformKind
import org.jetbrains.kotlin.platform.js.JsPlatforms
import org.jetbrains.kotlin.platform.konan.NativePlatforms
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment
import org.jetbrains.kotlin.utils.PathUtil
import java.util.regex.Pattern
@Service(Service.Level.PROJECT)
class IdePlatformKindProjectStructure(private val project: Project) {
fun getCompilerArguments(platformKind: IdePlatformKind): CommonCompilerArguments? {
return when (platformKind) {
is CommonIdePlatformKind -> null
is JvmIdePlatformKind -> Kotlin2JvmCompilerArgumentsHolder.getInstance(project).settings
is JsIdePlatformKind -> Kotlin2JsCompilerArgumentsHolder.getInstance(project).settings
is NativeIdePlatformKind -> null
else -> error("Unsupported platform kind: $platformKind")
}
}
fun getLibraryVersionProvider(platformKind: IdePlatformKind): (Library) -> IdeKotlinVersion? {
return when (platformKind) {
is CommonIdePlatformKind -> { library ->
getLibraryJarVersion(library, PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN)
}
is JvmIdePlatformKind -> { library ->
getLibraryJarVersion(library, PathUtil.KOTLIN_RUNTIME_JAR_PATTERN)
}
is JsIdePlatformKind -> { library ->
JsStdlibDetectionUtil.getJavaScriptLibraryStdVersion(library, project)
}
is NativeIdePlatformKind -> { _ -> null }
else -> error("Unsupported platform kind: $platformKind")
}
}
private fun getLibraryJar(roots: Array<VirtualFile>, jarPattern: Pattern): VirtualFile? {
return roots.firstOrNull { jarPattern.matcher(it.name).matches() }
}
private fun getLibraryJarVersion(library: Library, jarPattern: Pattern): IdeKotlinVersion? {
val libraryJar = getLibraryJar(library.getFiles(OrderRootType.CLASSES), jarPattern) ?: return null
return IdeKotlinVersion.fromManifest(libraryJar)
}
companion object {
@JvmStatic
fun getInstance(project: Project): IdePlatformKindProjectStructure = project.service()
private val PLATFORM_EXTENSIONS = mapOf(
MetadataPackageFragment.METADATA_FILE_EXTENSION to CommonIdePlatformKind,
"js" to JsIdePlatformKind,
"kjsm" to JsIdePlatformKind
)
fun getLibraryPlatformKind(file: VirtualFile): IdePlatformKind? {
PLATFORM_EXTENSIONS[file.extension]?.let { return it }
return when {
file.isKlibLibraryRootForPlatform(CommonPlatforms.defaultCommonPlatform) -> CommonIdePlatformKind
file.isKlibLibraryRootForPlatform(JsPlatforms.defaultJsPlatform) -> JsIdePlatformKind
file.isKlibLibraryRootForPlatform(NativePlatforms.unspecifiedNativePlatform) -> NativeIdePlatformKind
else -> null
}
}
fun getLibraryKind(platformKind: IdePlatformKind): PersistentLibraryKind<*>? {
return when (platformKind) {
is CommonIdePlatformKind -> KotlinCommonLibraryKind
is JvmIdePlatformKind -> null
is JsIdePlatformKind -> KotlinJavaScriptLibraryKind
is NativeIdePlatformKind -> KotlinNativeLibraryKind
else -> error("Unsupported platform kind: $platformKind")
}
}
}
}

View File

@@ -1,13 +1,12 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.framework
package org.jetbrains.kotlin.idea.base.platforms
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.JarUtil
import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
@@ -16,26 +15,29 @@ import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion
import org.jetbrains.kotlin.utils.LibraryUtils
import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
import java.util.jar.Attributes
object JsLibraryStdDetectionUtil {
object JsStdlibDetectionUtil {
private val IS_JS_LIBRARY_STD_LIB = Key.create<Boolean>("IS_JS_LIBRARY_STD_LIB")
fun hasJsStdlibJar(library: Library, project: Project, ignoreKind: Boolean = false): Boolean {
fun hasJavaScriptStdlibJar(library: Library, project: Project, ignoreKind: Boolean = false): Boolean {
if (library !is LibraryEx || library.isDisposed) return false
if (!ignoreKind && library.effectiveKind(project) !is JSLibraryKind) return false
if (!ignoreKind && !isJavaScriptLibrary(library, project)) return false
val classes = listOf(*library.getFiles(OrderRootType.CLASSES))
return getJsStdLibJar(classes) != null
return getJavaScriptStdLibJar(classes) != null
}
fun getJsLibraryStdVersion(library: Library, project: Project): IdeKotlinVersion? {
if ((library as LibraryEx).effectiveKind(project) !is JSLibraryKind) return null
val jar = getJsStdLibJar(library.getFiles(OrderRootType.CLASSES).toList()) ?: return null
fun getJavaScriptLibraryStdVersion(library: Library, project: Project): IdeKotlinVersion? {
if (!isJavaScriptLibrary(library, project)) return null
val jar = getJavaScriptStdLibJar(library.getFiles(OrderRootType.CLASSES).toList()) ?: return null
return IdeKotlinVersion.fromManifest(jar)
}
fun getJsStdLibJar(classesRoots: List<VirtualFile>): VirtualFile? {
private fun isJavaScriptLibrary(library: Library, project: Project): Boolean {
return LibraryEffectiveKindProvider.getInstance(project).getEffectiveKind(library as LibraryEx) is KotlinJavaScriptLibraryKind
}
fun getJavaScriptStdLibJar(classesRoots: List<VirtualFile>): VirtualFile? {
for (root in classesRoots) {
if (root.fileSystem.protocol !== StandardFileSystems.JAR_PROTOCOL) continue

View File

@@ -0,0 +1,76 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:JvmName("KLibUtils")
package org.jetbrains.kotlin.idea.base.platforms
import com.intellij.ide.highlighter.ArchiveFileType
import com.intellij.openapi.vfs.InvalidVirtualFileAccessException
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.library.*
import org.jetbrains.kotlin.library.impl.BuiltInsPlatform
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.isCommon
import org.jetbrains.kotlin.platform.js.isJs
import org.jetbrains.kotlin.platform.jvm.isJvm
import org.jetbrains.kotlin.platform.konan.isNative
import java.io.IOException
import java.util.*
fun VirtualFile.isKlibLibraryRootForPlatform(targetPlatform: TargetPlatform): Boolean {
// The virtual file for a library packed in a ZIP file will have path like "/some/path/to/the/file.klib!/",
// and therefore will be recognized by VFS as a directory (isDirectory == true).
// So, first, let's check the file type and file extension.
if ((fileType == ArchiveFileType.INSTANCE && extension != KLIB_FILE_EXTENSION) || !isDirectory)
return false
// run check for library root too
// this is necessary to recognize old style KLIBs that do not have components, and report tem to user appropriately
// (relevant only for Kotlin/Native KLIBs)
val requestedBuiltInsPlatform = targetPlatform.toBuiltInsPlatform()
if (requestedBuiltInsPlatform == BuiltInsPlatform.NATIVE && checkKlibComponent(this, requestedBuiltInsPlatform)) {
return true
}
try {
return children?.any { checkKlibComponent(it, requestedBuiltInsPlatform) } == true
} catch (e: InvalidVirtualFileAccessException) {
return false
}
}
private fun checkKlibComponent(componentFile: VirtualFile, requestedBuiltInsPlatform: BuiltInsPlatform): Boolean {
val manifestFile = componentFile.findChild(KLIB_MANIFEST_FILE_NAME)?.takeIf { !it.isDirectory } ?: return false
val manifestProperties = try {
manifestFile.inputStream.use { Properties().apply { load(it) } }
} catch (_: IOException) {
return false
}
if (!manifestProperties.containsKey(KLIB_PROPERTY_UNIQUE_NAME)) return false
val builtInsPlatformProperty = manifestProperties.getProperty(KLIB_PROPERTY_BUILTINS_PLATFORM)
// No builtins_platform property => either a new common klib (we don't write builtins_platform for common) or old Native klib
?: return when (requestedBuiltInsPlatform) {
BuiltInsPlatform.NATIVE -> componentFile.isLegacyNativeKlibComponent // TODO(dsavvinov): drop additional legacy check after 1.4
BuiltInsPlatform.COMMON -> !componentFile.isLegacyNativeKlibComponent
else -> false
}
val builtInsPlatform = BuiltInsPlatform.parseFromString(builtInsPlatformProperty) ?: return false
return builtInsPlatform == requestedBuiltInsPlatform
}
private fun TargetPlatform.toBuiltInsPlatform() = when {
isCommon() -> BuiltInsPlatform.COMMON
isNative() -> BuiltInsPlatform.NATIVE
isJvm() -> BuiltInsPlatform.JVM
isJs() -> BuiltInsPlatform.JS
else -> throw IllegalArgumentException("Unknown platform $this")
}
private val VirtualFile.isLegacyNativeKlibComponent: Boolean
get() {
val irFolder = findChild(KLIB_IR_FOLDER_NAME)
return irFolder != null && irFolder.children.isNotEmpty()
}

View File

@@ -0,0 +1,73 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.platforms
import com.intellij.openapi.roots.libraries.DummyLibraryProperties
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.vfs.JarFileSystem
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.platform.CommonPlatforms
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.idePlatformKind
import org.jetbrains.kotlin.platform.js.JsPlatforms
import org.jetbrains.kotlin.platform.konan.NativePlatforms
sealed interface KotlinLibraryKind {
// TODO: Drop this property. See https://youtrack.jetbrains.com/issue/KT-38233
// This property returns approximate library platform, as the real platform can be evaluated only for concrete library.
val compilerPlatform: TargetPlatform
}
object KotlinJavaScriptLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.js"), KotlinLibraryKind {
override val compilerPlatform: TargetPlatform
get() = JsPlatforms.defaultJsPlatform
override fun createDefaultProperties(): DummyLibraryProperties {
return DummyLibraryProperties.INSTANCE
}
}
object KotlinCommonLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.common"), KotlinLibraryKind {
override val compilerPlatform: TargetPlatform
get() = CommonPlatforms.defaultCommonPlatform
override fun createDefaultProperties(): DummyLibraryProperties {
return DummyLibraryProperties.INSTANCE
}
}
object KotlinNativeLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.native"), KotlinLibraryKind {
override val compilerPlatform: TargetPlatform
get() = NativePlatforms.unspecifiedNativePlatform
override fun createDefaultProperties(): DummyLibraryProperties {
return DummyLibraryProperties.INSTANCE
}
}
// TODO: Drop this property. See https://youtrack.jetbrains.com/issue/KT-38233
// It returns approximate library platform, as the real platform can be evaluated only for concrete library.
val PersistentLibraryKind<*>?.platform: TargetPlatform
get() = when (this) {
is KotlinLibraryKind -> this.compilerPlatform
else -> DefaultIdeTargetPlatformKindProvider.defaultPlatform
}
fun detectLibraryKind(roots: Array<VirtualFile>): PersistentLibraryKind<*>? {
val jarFile = roots.firstOrNull() ?: return null
if (jarFile.fileSystem is JarFileSystem) {
// TODO: Detect library kind for Jar file using IdePlatformKindResolution.
when (jarFile.getLibraryKindForJar()) {
KnownLibraryKindForIndex.COMMON -> return KotlinCommonLibraryKind
KnownLibraryKindForIndex.JS -> return KotlinJavaScriptLibraryKind
KnownLibraryKindForIndex.UNKNOWN -> {
/* Continue detection of library kind via IdePlatformKindResolution. */
}
}
}
val matchingPlatformKind = IdePlatformKindProjectStructure.getLibraryPlatformKind(jarFile)
?: DefaultIdeTargetPlatformKindProvider.defaultPlatform.idePlatformKind
return IdePlatformKindProjectStructure.getLibraryKind(matchingPlatformKind)
}

View File

@@ -1,8 +1,7 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.vfilefinder
package org.jetbrains.kotlin.idea.base.platforms
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.components.serviceOrNull
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile

View File

@@ -1,8 +1,9 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.framework
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.base.platforms
import com.intellij.ProjectTopics
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ModuleRootEvent
import com.intellij.openapi.roots.ModuleRootListener
@@ -11,7 +12,8 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.util.containers.SoftFactoryMap
class LibraryEffectiveKindProviderImpl(project: Project) : LibraryEffectiveKindProvider {
@Service(Service.Level.PROJECT)
class LibraryEffectiveKindProvider(project: Project) {
private val effectiveKindMap = object : SoftFactoryMap<LibraryEx, PersistentLibraryKind<*>?>() {
override fun create(key: LibraryEx) = detectLibraryKind(key.getFiles(OrderRootType.CLASSES))
}
@@ -27,7 +29,7 @@ class LibraryEffectiveKindProviderImpl(project: Project) : LibraryEffectiveKindP
)
}
override fun getEffectiveKind(library: LibraryEx): PersistentLibraryKind<*>? {
fun getEffectiveKind(library: LibraryEx): PersistentLibraryKind<*>? {
if (library.isDisposed) {
return null
}
@@ -37,4 +39,9 @@ class LibraryEffectiveKindProviderImpl(project: Project) : LibraryEffectiveKindP
else -> effectiveKindMap.get(library)
}
}
companion object {
@JvmStatic
fun getInstance(project: Project): LibraryEffectiveKindProvider = project.service()
}
}

View File

@@ -0,0 +1,47 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.service
import com.intellij.openapi.util.Disposer
import com.intellij.util.io.isFile
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
class PluginStartupApplicationService : Disposable {
private var aliveFlagPath: String? = null
@Synchronized
fun getAliveFlagPath(): String {
if (aliveFlagPath == null) {
try {
val flagFile = Files.createTempFile("kotlin-idea-", "-is-running")
val file = flagFile.toFile()
Disposer.register(this) { file.delete() }
aliveFlagPath = flagFile.toAbsolutePath().toString()
} catch (e: IOException) {
aliveFlagPath = ""
}
}
return aliveFlagPath!!
}
@Synchronized
fun resetAliveFlag() {
val flagFile = aliveFlagPath?.let(Path::of) ?: return
try {
if (flagFile.isFile() && Files.deleteIfExists(flagFile)) {
this.aliveFlagPath = null
}
} catch (ignored: IOException) {}
}
override fun dispose() {}
companion object {
@JvmStatic
fun getInstance(): PluginStartupApplicationService = service()
}
}

View File

@@ -10,7 +10,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="module" module-name="kotlin.base.light-classes" />
<orderEntry type="module" module-name="intellij.platform.util" />
<orderEntry type="module" module-name="intellij.platform.util.ex" />
<orderEntry type="module" module-name="intellij.platform.util.ui" />

View File

@@ -9,6 +9,10 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="intellij.platform.ide.impl" />
<orderEntry type="module" module-name="intellij.platform.externalSystem" />
<orderEntry type="module" module-name="intellij.platform.lang.core" />
</component>
</module>

View File

@@ -1,20 +1,32 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:JvmName("ProjectStructureUtils")
package org.jetbrains.kotlin.base.util
package org.jetbrains.kotlin.idea.roots
import com.intellij.facet.FacetManager
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.RootsChangeRescanningInfo
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
import com.intellij.openapi.util.EmptyRunnable
import org.jetbrains.annotations.ApiStatus
fun Module.isAndroidModule(modelsProvider: IdeModifiableModelsProvider? = null): Boolean {
val facetModel = modelsProvider?.getModifiableFacetModel(this) ?: FacetManager.getInstance(this)
val facets = facetModel.allFacets
return facets.any { it.javaClass.simpleName == "AndroidFacet" }
}
/**
* This method is equivalent to {@sample invalidateProjectRoots(RootsChangeRescanningInfo.TOTAL_RESCAN)}
* Consider using optimised instance of [com.intellij.util.indexing.BuildableRootsChangeRescanningInfo]
*/
@ApiStatus.Internal
fun Project.invalidateProjectRoots() {
ProjectRootManagerEx.getInstanceEx(this).makeRootsChange(EmptyRunnable.INSTANCE, false, true)
}
@ApiStatus.Internal
fun Project.invalidateProjectRoots(info: RootsChangeRescanningInfo) {
ProjectRootManagerEx.getInstanceEx(this).makeRootsChange(EmptyRunnable.INSTANCE, info)
}

View File

@@ -1,6 +1,6 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.core.util
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:JvmName("UiUtils")
package org.jetbrains.kotlin.base.util
import com.intellij.ui.DocumentAdapter
import javax.swing.event.DocumentEvent

View File

@@ -15,6 +15,7 @@
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="kotlin.plugin" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.common" />
<orderEntry type="module" module-name="kotlin.compiler-plugins.compiler-plugin-support.common" />

View File

@@ -11,9 +11,10 @@
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.idea" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="intellij.platform.lang" />
<orderEntry type="module" module-name="intellij.platform.externalSystem" />
</component>

View File

@@ -9,6 +9,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.gradle.gradle-tooling" />
<orderEntry type="module" module-name="kotlin.gradle.gradle-java" />

View File

@@ -10,6 +10,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.maven" />
<orderEntry type="module" module-name="kotlin.compiler-plugins.compiler-plugin-support.common" />

View File

@@ -12,6 +12,7 @@
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.idea" />
<orderEntry type="module" module-name="kotlin.gradle.gradle-java" />

View File

@@ -19,6 +19,7 @@
<orderEntry type="library" scope="TEST" name="kotlinc.kotlin-compiler-tests" level="project" />
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.base.fe10.analysis" />
<orderEntry type="module" module-name="kotlin.compiler-plugins.compiler-plugin-support.common" />
<orderEntry type="module" module-name="kotlin.core" />

View File

@@ -9,6 +9,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlinc.kotlin-stdlib" level="project" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.gradle.gradle-java" />
<orderEntry type="module" module-name="kotlin.compiler-plugins.kotlinx-serialization.common" />

View File

@@ -15,6 +15,7 @@
<orderEntry type="library" name="JUnit4" level="project" />
<orderEntry type="module" module-name="kotlin.plugin" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.common" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.compiler-plugins.compiler-plugin-support.common" />

View File

@@ -12,6 +12,7 @@
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-jps-common" level="project" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.gradle.gradle-java" />
<orderEntry type="module" module-name="intellij.platform.lang" />

View File

@@ -28,9 +28,11 @@
<orderEntry type="library" name="kotlinc.kotlin-script-runtime" level="project" />
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.platforms" />
<orderEntry type="module" module-name="kotlin.base.indices" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
<orderEntry type="module" module-name="kotlin.base.psi" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.base.resources" />
<orderEntry type="module" module-name="kotlin.base.fe10.analysis" />
<orderEntry type="module" module-name="kotlin.base.fe10.kdoc" />

View File

@@ -1,9 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.artifacts
import com.intellij.openapi.roots.libraries.LibraryKind
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind
import java.io.File
enum class KotlinLibraryData(val libraryName: String, val kind: PersistentLibraryKind<*>?, val classesRoot: File, val sourcesRoot: File) {
@@ -27,7 +26,7 @@ enum class KotlinLibraryData(val libraryName: String, val kind: PersistentLibrar
),
KOTLIN_STDLIB_JS(
libraryName = "kotlin-stdlib-js",
kind = JSLibraryKind,
kind = KotlinJavaScriptLibraryKind,
classesRoot = KotlinArtifacts.instance.kotlinStdlibJs,
sourcesRoot = KotlinArtifacts.instance.kotlinStdlibSources
)

View File

@@ -2,19 +2,10 @@
package org.jetbrains.kotlin.idea.core
import com.intellij.facet.FacetManager
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
import com.intellij.openapi.module.Module
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.idea.caches.project.ModuleSourceInfo
import org.jetbrains.kotlin.idea.caches.project.PlatformModuleInfo
fun Module.isAndroidModule(modelsProvider: IdeModifiableModelsProvider? = null): Boolean {
val facetModel = modelsProvider?.getModifiableFacetModel(this) ?: FacetManager.getInstance(this)
val facets = facetModel.allFacets
return facets.any { it.javaClass.simpleName == "AndroidFacet" }
}
fun ModuleInfo.unwrapModuleSourceInfo(): ModuleSourceInfo? {
return when (this) {
is ModuleSourceInfo -> this

View File

@@ -26,6 +26,8 @@ import com.intellij.util.Query
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes
import org.jetbrains.jps.model.java.JavaSourceRootProperties
import org.jetbrains.jps.model.module.JpsModuleSourceRootType
import org.jetbrains.kotlin.base.util.invalidateProjectRoots
import org.jetbrains.kotlin.base.util.isAndroidModule
import org.jetbrains.kotlin.config.SourceKotlinRootType
import org.jetbrains.kotlin.config.TestSourceKotlinRootType
import org.jetbrains.kotlin.idea.caches.PerModulePackageCacheService
@@ -34,7 +36,6 @@ import org.jetbrains.kotlin.idea.caches.project.sourceType
import org.jetbrains.kotlin.idea.core.util.toPsiDirectory
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.roots.invalidateProjectRoots
import org.jetbrains.kotlin.idea.util.rootManager
import org.jetbrains.kotlin.idea.util.sourceRoot
import org.jetbrains.kotlin.name.FqName
@@ -121,7 +122,8 @@ private class PureKotlinSourceFoldersHolder {
*/
fun hasPurePrefixInPath(module: Module, path: String): Boolean {
val pureFolders = moduleMap.getOrPut(module) {
KotlinFacet.get(module)?.configuration?.settings?.pureKotlinSourceFolders?.takeIf { it.isNotEmpty() && !module.isAndroidModule() }
KotlinFacet.get(module)?.configuration?.settings?.pureKotlinSourceFolders
?.takeIf { it.isNotEmpty() && !module.isAndroidModule() }
} ?: return true
return pureFolders.any { path.startsWith(it, ignoreCase = true) }

View File

@@ -16,6 +16,7 @@ import com.intellij.openapi.extensions.ProjectExtensionPointName
import com.intellij.openapi.fileTypes.FileTypeManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.projectRoots.ex.PathUtilEx
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.startup.StartupActivity
@@ -33,7 +34,7 @@ import org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings
import org.jetbrains.kotlin.idea.core.util.CheckCanceledLock
import org.jetbrains.kotlin.idea.core.util.writeWithCheckCanceled
import org.jetbrains.kotlin.idea.util.application.isUnitTestMode
import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.script.ScriptTemplatesProvider
import org.jetbrains.kotlin.scripting.definitions.*
import org.jetbrains.kotlin.scripting.resolve.VirtualFileScriptSource
@@ -53,7 +54,6 @@ import kotlin.script.experimental.host.configurationDependencies
import kotlin.script.experimental.host.toScriptSource
import kotlin.script.experimental.jvm.JvmDependency
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
import kotlin.script.experimental.jvm.util.ClasspathExtractionException
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContextOrStdlib
import kotlin.script.templates.standard.ScriptTemplateWithArgs
@@ -484,7 +484,8 @@ class BundledKotlinScriptDependenciesResolver(private val project: Project) : De
}
val jdk = ProjectRootManager.getInstance(project).projectSdk
?: getProjectJdkTableSafe().allJdks.firstOrNull { sdk -> sdk.sdkType is JavaSdk }
?: runReadAction { ProjectJdkTable.getInstance() }.allJdks
.firstOrNull { sdk -> sdk.sdkType is JavaSdk }
?: PathUtilEx.getAnyJdk(project)
return jdk?.homePath
}

View File

@@ -6,6 +6,7 @@ import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.JavaSdkType
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.OrderRootType
@@ -16,7 +17,6 @@ import org.jetbrains.kotlin.idea.caches.project.getAllProjectSdks
import org.jetbrains.kotlin.idea.core.script.configuration.utils.ScriptClassRootsStorage
import org.jetbrains.kotlin.idea.core.script.scriptingWarnLog
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe
import java.nio.file.Path
class ScriptSdksBuilder(
@@ -79,7 +79,8 @@ class ScriptSdksBuilder(
null
} ?: return null
return getProjectJdkTableSafe().allJdks.find { it.homeDirectory == javaHomeVF }
return runReadAction { ProjectJdkTable.getInstance() }.allJdks
.find { it.homeDirectory == javaHomeVF }
?.takeIf { it.canBeUsedForScript() }
}
@@ -87,10 +88,12 @@ class ScriptSdksBuilder(
sdks.getOrPut(SdkId.default) { defaultSdk }
fun addSdkByName(sdkName: String) {
val sdk = getProjectJdkTableSafe().allJdks
val sdk = runReadAction { ProjectJdkTable.getInstance() }.allJdks
.find { it.name == sdkName }
?.takeIf { it.canBeUsedForScript() }
?: defaultSdk ?: return
?: defaultSdk
?: return
val homePath = sdk.homePath ?: return
sdks[SdkId(homePath)] = sdk
}

View File

@@ -18,6 +18,7 @@
<orderEntry type="module" module-name="intellij.platform.ide.impl" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.formatter" />
<orderEntry type="module" module-name="kotlin.jvm" />

View File

@@ -20,6 +20,7 @@
<orderEntry type="module" module-name="kotlin.resources-fir" />
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.resources" />
<orderEntry type="module" module-name="kotlin.common" />
<orderEntry type="module" module-name="kotlin.core" />
<orderEntry type="module" module-name="kotlin.fir.frontend-independent" exported="" />
@@ -31,7 +32,6 @@
<orderEntry type="library" exported="" scope="TEST" name="kotlinc.high-level-api-fir-tests" level="project" />
<orderEntry type="library" exported="" name="kotlinc.low-level-api-fir" level="project" />
<orderEntry type="module" module-name="kotlin.base.indices" />
<orderEntry type="module" module-name="kotlin.base.resources" />
<orderEntry type="module" module-name="kotlin.idea" />
<orderEntry type="module" module-name="kotlin.compiler-plugins.sam-with-receiver.common" />
<orderEntry type="module" module-name="kotlin.tests-common" scope="TEST" />

View File

@@ -512,22 +512,6 @@ editor.checkbox.title.convert.pasted.java.code.to.kotlin=Convert pasted Java cod
editor.checkbox.title.don.t.show.java.to.kotlin.conversion.dialog.on.paste=Don't show Java to Kotlin conversion dialog on paste
editor.title.kotlin=Kotlin
facet.checkbox.text.use.project.settings=Use project settings
facet.column.name.options=Options
facet.column.name.plugin=Plugin
facet.error.text.at.least.one.target.platform.should.be.selected=At least one target platform should be selected
facet.label.text.project.settings.that.are.used.for.this.facet=Project settings that are used for this facet:
facet.label.text.selected.target.platforms=Selected target platforms:
facet.label.text.target.platform=Target platform:
facet.label.text.the.project.is.imported.from.external.build.system.and.could.not.be.edited=The project is imported from external build system and could not be edited
facet.link.text.edit.project.settings=Edit project settings
facet.name.compiler.plugins=Compiler Plugins
facet.name.general=General
facet.text.following.arguments.are.redundant=Following arguments are redundant: {0}
facet.text.following.arguments.override.facet.settings=Following arguments override facet settings: {0}
facet.text.following.options.are.not.correct=Following options are not correct:
facet.text.multiplatform=Multiplatform
find.usages.progress.text.declaration.superMethods=Resolving super methods\u2026
formatter.button.text.use.import.with.when.at.least=Use import with '*' when at least
@@ -708,13 +692,6 @@ reporter.message.text.you.re.running.kotlin.plugin.version=You''re running Kotli
reporter.text.can.t.report.exception.from.patched.plugin=Can't report exception from patched plugin
reporter.title.update.kotlin.plugin=Update Kotlin Plugin
configuration.description.always=Always
configuration.description.amd=AMD
configuration.description.commonjs=CommonJS
configuration.description.never=Never
configuration.description.plain.put.to.global.scope=Plain (put to global scope)
configuration.description.umd.detect.amd.or.commonjs.if.available.fallback.to.plain=UMD (detect AMD or CommonJS if available, fallback to plain)
configuration.description.when.inlining.a.function.from.other.module.with.embedded.sources=When inlining a function from other module with embedded sources
configuration.error.text.shouldn.t.add.null.urls.to.custom.repositories=Shouldn't add null urls to custom repositories
configuration.feature.text.new.java.to.kotlin.converter=New Java to Kotlin Converter
configuration.message.enter.fully.qualified.method.name=Enter fully-qualified method name:
@@ -736,27 +713,15 @@ kotlin.eap.survey.notification.title=Kotlin Early Access Program
kotlin.eap.survey.notification.text=We want to know more about you and how we can make the EAP experience more convenient!
kotlin.eap.survey.notification.action=Take EAP survey
kotlin.eap.survey.notification.link=https://surveys.jetbrains.com/s3/kotlin-eaps-survey
configuration.name.kotlin.compiler=Kotlin Compiler
configuration.text.bundled.0.jps.version=Bundled ({0})
configuration.text.0.unsupported.jps.version={0} (Unsupported)
configuration.name.kotlin=Kotlin
configuration.name.method=Method
configuration.status.text.installation.failed=Installation failed
configuration.status.text.installing=Installing\u2026
configuration.title.add.exclusion=Add Exclusion
configuration.text.and=and
configuration.text.other.s=other(s)
configuration.text.patched.original={0} (Patched! Original: {1})
configuration.title.choose.output.directory=Choose Output Directory
configuration.title.early.access.preview.version=Early Access Preview
configuration.title.edit.exclusion=Edit Exclusion
configuration.title.kotlin.compiler.js.option.output.postfix.browse.title=Choose File to Append to Generated Code
configuration.title.kotlin.compiler.js.option.output.prefix.browse.title=Choose File to Prepend to Generated Code
configuration.title.stable=Stable
configuration.warning.text.following.modules.override.project.settings=Following modules override project settings:
configuration.warning.text.modules.override.project.settings={0} modules override project settings
configuration.warning.text.language.version.unsupported=Language version {0} is no longer supported
configuration.warning.text.api.version.unsupported=API version {0} is no longer supported
configuration.kotlin.code.style=Kotlin code style
configuration.kotlin.code.style.group.name=Kotlin official code style available
configuration.notification.update.code.style.to.official=Do you want to update your Kotlin code style settings to the recommended ones?
@@ -770,7 +735,6 @@ configuration.update.is.resolve.module.per.source.set=The IDE is currently confi
configuration.apply.is.resolve.module.per.source.set=Fix and re-import project
configuration.do.not.suggest.update.is.resolve.module.per.source.set=Don\u2019t show again
#Refactoring
0.1.is.never.used={0} ''{1}'' is never used
0.has.detected.1.code.fragments.in.2.that.can.be.replaced.with.3={0} has detected {1} code {1,choice,1#fragment|2#fragments} in {2} that can be replaced with {3}. Would you like to review and replace {1,choice,1#it|2#them}?
@@ -1969,7 +1933,6 @@ enable.incremental.compilation=Enable incremental compilation
keep.compiler.process.alive.between.invocations=Keep compiler process alive between invocations
module.kind=Module &kind:
target.jvm.version=Target &JVM version
deprecated.jvm.version=(deprecated)
additional.command.line.parameters=Additional command line parameters
mnemonic.install=&Install
status=(status)
@@ -2492,7 +2455,6 @@ import.text.all.other.imports=all other imports
import.text.import=import
import.text.all.alias.imports=all alias imports
extract.new.parameter.name.receiver=<receiver>
facets.editor.general.tab.label.depends.on.0=Depends on: {0}.
kotlin.compiler.configurable=Kotlin Compiler
kotlin.language.configurable=Kotlin
kotlin.scripting.configurable=Kotlin Scripting
@@ -2511,8 +2473,6 @@ project.wizard.new.project.kotlin.comment=To create a complex project, use the <
add.empty.argument.list=Add empty argument list
loading.available.versions.from.maven=Loading available versions from Maven...
failed.fetching.all.available.versions.from.maven=Failed fetching all available versions from Maven
progress.text.detect.test.framework=Detect Test framework
find.declaration.implementing.methods.checkbox=&Implementing functions

View File

@@ -36,6 +36,8 @@
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.base.platforms" />
<orderEntry type="module" module-name="kotlin.base.resources" />
<orderEntry type="module" module-name="kotlin.common" />
<orderEntry type="module" module-name="kotlin.core" />

View File

@@ -6,12 +6,12 @@ import com.intellij.openapi.module.Module
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.psi.PsiFile
import org.jetbrains.annotations.NonNls
import org.jetbrains.kotlin.base.util.isAndroidModule
import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion
import org.jetbrains.kotlin.idea.configuration.NotificationMessageCollector
import org.jetbrains.kotlin.idea.configuration.addStdlibToJavaModuleInfo
import org.jetbrains.kotlin.idea.configuration.allModules
import org.jetbrains.kotlin.idea.configuration.getWholeModuleGroup
import org.jetbrains.kotlin.idea.core.isAndroidModule
import org.jetbrains.kotlin.idea.gradle.KotlinIdeaGradleBundle
import org.jetbrains.kotlin.idea.versions.getDefaultJvmTarget
import org.jetbrains.kotlin.platform.TargetPlatform

View File

@@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
@@ -27,7 +28,7 @@ import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.KotlinFacetSettings
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.ide.konan.NativeLibraryKind
import org.jetbrains.kotlin.idea.base.platforms.*
import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinJpsPluginSettings
@@ -35,9 +36,6 @@ import org.jetbrains.kotlin.idea.configuration.KOTLIN_GROUP_ID
import org.jetbrains.kotlin.idea.configuration.externalCompilerVersion
import org.jetbrains.kotlin.idea.facet.*
import org.jetbrains.kotlin.idea.formatter.ProjectCodeStyleImporter
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.gradle.configuration.*
import org.jetbrains.kotlin.idea.gradle.configuration.GradlePropertiesFileFacade.Companion.KOTLIN_CODE_STYLE_GRADLE_SETTING
import org.jetbrains.kotlin.idea.gradle.configuration.klib.KotlinNativeLibraryNameUtil.KOTLIN_NATIVE_LIBRARY_PREFIX
@@ -175,10 +173,7 @@ class KotlinGradleLibraryDataService : AbstractProjectDataService<LibraryData, V
val modifiableModel = modelsProvider.getModifiableLibraryModel(ideLibrary) as LibraryEx.ModifiableModelEx
if (anyNonJvmModules || ideLibrary.looksAsNonJvmLibrary()) {
detectLibraryKind(modifiableModel.getFiles(OrderRootType.CLASSES))?.let { modifiableModel.kind = it }
} else if (
ideLibrary is LibraryEx &&
(ideLibrary.kind === JSLibraryKind || ideLibrary.kind === NativeLibraryKind || ideLibrary.kind === CommonLibraryKind)
) {
} else if (ideLibrary is LibraryEx && ideLibrary.kind in NON_JVM_LIBRARY_KINDS) {
modifiableModel.forgetKind()
}
}
@@ -186,7 +181,7 @@ class KotlinGradleLibraryDataService : AbstractProjectDataService<LibraryData, V
private fun Library.looksAsNonJvmLibrary(): Boolean {
name?.let { name ->
if (nonJvmSuffixes.any { it in name } || name.startsWith(KOTLIN_NATIVE_LIBRARY_PREFIX))
if (NON_JVM_SUFFIXES.any { it in name } || name.startsWith(KOTLIN_NATIVE_LIBRARY_PREFIX))
return true
}
@@ -196,7 +191,13 @@ class KotlinGradleLibraryDataService : AbstractProjectDataService<LibraryData, V
companion object {
val LOG = Logger.getInstance(KotlinGradleLibraryDataService::class.java)
val nonJvmSuffixes = listOf("-common", "-js", "-native", "-kjsm", "-metadata")
val NON_JVM_LIBRARY_KINDS: List<PersistentLibraryKind<*>> = listOf(
KotlinJavaScriptLibraryKind,
KotlinNativeLibraryKind,
KotlinCommonLibraryKind
)
val NON_JVM_SUFFIXES = listOf("-common", "-js", "-native", "-kjsm", "-metadata")
}
}

View File

@@ -18,6 +18,8 @@
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.base.platforms" />
<orderEntry type="module" module-name="kotlin.base.fe10.analysis" />
<orderEntry type="module" module-name="kotlin.common" />
<orderEntry type="module" module-name="kotlin.core" />

View File

@@ -8,6 +8,7 @@ import com.intellij.openapi.application.runWriteActionAndWait
import com.intellij.openapi.externalSystem.importing.ImportSpec
import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder
import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.projectRoots.ProjectJdkTable
import com.intellij.openapi.roots.LibraryOrderEntry
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.OrderRootType
@@ -21,6 +22,8 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.idea.base.platforms.KotlinCommonLibraryKind
import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind
import org.jetbrains.kotlin.idea.caches.project.productionSourceInfo
import org.jetbrains.kotlin.idea.caches.project.testSourceInfo
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
@@ -29,11 +32,8 @@ import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinStatus
import org.jetbrains.kotlin.idea.configuration.ModuleSourceRootMap
import org.jetbrains.kotlin.idea.configuration.allConfigurators
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.idea.util.projectStructure.sdk
import org.jetbrains.kotlin.platform.TargetPlatform
@@ -236,7 +236,7 @@ class GradleFacetImportTest8 : KotlinGradleImportingTestCase() {
val libraryEntries = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>()
val stdlib = libraryEntries.single { it.libraryName?.contains("js") ?: false }.library
assertEquals(JSLibraryKind, (stdlib as LibraryEx).kind)
assertEquals(KotlinJavaScriptLibraryKind, (stdlib as LibraryEx).kind)
assertTrue(stdlib.getFiles(OrderRootType.CLASSES).isNotEmpty())
assertSameKotlinSdks("project.main", "project.test")
@@ -277,7 +277,7 @@ class GradleFacetImportTest8 : KotlinGradleImportingTestCase() {
.map { it.library as LibraryEx }
.first { "kotlin-stdlib-js" in it.name!! }
assertEquals(JSLibraryKind, stdlib.kind)
assertEquals(KotlinJavaScriptLibraryKind, stdlib.kind)
assertAllModulesConfigured()
@@ -399,8 +399,8 @@ class GradleFacetImportTest8 : KotlinGradleImportingTestCase() {
val rootManager = ModuleRootManager.getInstance(getModule("project.main"))
val libraries = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().map { it.library as LibraryEx }
assertEquals(JSLibraryKind, libraries.single { it.name?.contains("kotlin-stdlib-js") == true }.kind)
assertEquals(CommonLibraryKind, libraries.single { it.name?.contains("kotlin-stdlib-common") == true }.kind)
assertEquals(KotlinJavaScriptLibraryKind, libraries.single { it.name?.contains("kotlin-stdlib-js") == true }.kind)
assertEquals(KotlinCommonLibraryKind, libraries.single { it.name?.contains("kotlin-stdlib-common") == true }.kind)
assertEquals(
listOf(
@@ -434,7 +434,7 @@ class GradleFacetImportTest8 : KotlinGradleImportingTestCase() {
val rootManager = ModuleRootManager.getInstance(getModule("project.main"))
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().single().library
assertEquals(CommonLibraryKind, (stdlib as LibraryEx).kind)
assertEquals(KotlinCommonLibraryKind, (stdlib as LibraryEx).kind)
assertEquals(
listOf(
@@ -593,7 +593,7 @@ class GradleFacetImportTest8 : KotlinGradleImportingTestCase() {
.library!!
assertTrue(stdlib.getFiles(OrderRootType.CLASSES).isNotEmpty())
assertEquals(JSLibraryKind, (stdlib as LibraryEx).kind)
assertEquals(KotlinJavaScriptLibraryKind, (stdlib as LibraryEx).kind)
}
@Test
@@ -643,9 +643,9 @@ class GradleFacetImportTest8 : KotlinGradleImportingTestCase() {
fun testJDKImport() {
val mockJdkPath = "${PathManager.getHomePath()}/community/java/mockJDK-1.8"
runWriteActionAndWait {
val jdk = JavaSdk.getInstance().createJdk("myJDK", mockJdkPath)
getProjectJdkTableSafe().addJdk(jdk)
ProjectRootManager.getInstance(myProject).projectSdk = jdk
val jdk = JavaSdk.getInstance().createJdk("myJDK", mockJdkPath)
runReadAction<ProjectJdkTable> { ProjectJdkTable.getInstance() }.addJdk(jdk)
ProjectRootManager.getInstance(myProject).projectSdk = jdk
}
try {
@@ -658,9 +658,9 @@ class GradleFacetImportTest8 : KotlinGradleImportingTestCase() {
assertEquals(mockJdkPath, moduleSDK.homePath)
} finally {
runWriteActionAndWait {
val jdkTable = getProjectJdkTableSafe()
jdkTable.removeJdk(jdkTable.findJdk("myJDK")!!)
ProjectRootManager.getInstance(myProject).projectSdk = null
val jdkTable = runReadAction<ProjectJdkTable> { ProjectJdkTable.getInstance() }
jdkTable.removeJdk(jdkTable.findJdk("myJDK")!!)
ProjectRootManager.getInstance(myProject).projectSdk = null
}
}
}
@@ -749,7 +749,7 @@ class GradleFacetImportTest8 : KotlinGradleImportingTestCase() {
val rootManager = ModuleRootManager.getInstance(getModule("project.main"))
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().single().library
assertEquals(CommonLibraryKind, (stdlib as LibraryEx).kind)
assertEquals(KotlinCommonLibraryKind, (stdlib as LibraryEx).kind)
assertSameKotlinSdks("project.main", "project.test")

View File

@@ -12,6 +12,7 @@
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
<orderEntry type="library" name="kotlinc.kotlin-compiler-fe10" level="project" />
<orderEntry type="module" module-name="kotlin.base.platforms" />
<orderEntry type="module" module-name="kotlin.plugin" scope="TEST" />
<orderEntry type="module" module-name="kotlin.common" />
<orderEntry type="module" module-name="kotlin.core" />

View File

@@ -8,9 +8,9 @@ import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.vfs.VfsUtilCore.urlToPath
import org.jetbrains.kotlin.ide.konan.NativeLibraryKind
import org.jetbrains.kotlin.idea.base.platforms.KotlinNativeLibraryKind
import org.jetbrains.kotlin.idea.base.platforms.detectLibraryKind
import org.jetbrains.kotlin.idea.configuration.externalCompilerVersion
import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.project.platform
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.konan.library.konanCommonLibraryPath
@@ -69,7 +69,7 @@ private val Module.libraries
private fun assertValidModule(module: Module, projectRoot: String) {
val (nativeLibraries, otherLibraries) = module.libraries.partition { library ->
detectLibraryKind(library.getFiles(OrderRootType.CLASSES)) == NativeLibraryKind
detectLibraryKind(library.getFiles(OrderRootType.CLASSES)) == KotlinNativeLibraryKind
}
if (module.platform.isNative()) {

View File

@@ -35,6 +35,9 @@
<orderEntry type="module" module-name="kotlin.base.indices" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
<orderEntry type="module" module-name="kotlin.base.psi" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration-ui" />
<orderEntry type="module" module-name="kotlin.base.platforms" />
<orderEntry type="module" module-name="kotlin.base.resources" />
<orderEntry type="module" module-name="kotlin.base.fe10.analysis" />
<orderEntry type="module" module-name="kotlin.base.fe10.kdoc" />

View File

@@ -1,61 +0,0 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Disposer;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static com.intellij.util.io.PathKt.exists;
import static com.intellij.util.io.PathKt.isFile;
import static java.nio.file.Files.deleteIfExists;
public class PluginStartupApplicationService implements Disposable {
public static PluginStartupApplicationService getInstance() {
return ApplicationManager.getApplication().getService(PluginStartupApplicationService.class);
}
private String aliveFlagPath;
public synchronized String getAliveFlagPath() {
if (this.aliveFlagPath == null) {
try {
Path flagFile = Files.createTempFile("kotlin-idea-", "-is-running");
File file = flagFile.toFile();
Disposer.register(this, new Disposable() {
@Override
public void dispose() {
file.delete();
}
});
this.aliveFlagPath = flagFile.toAbsolutePath().toString();
} catch (IOException e) {
this.aliveFlagPath = "";
}
}
return this.aliveFlagPath;
}
public synchronized void resetAliveFlag() {
if (aliveFlagPath != null && !aliveFlagPath.isEmpty()) {
Path flagFile = Path.of(aliveFlagPath);
try {
if (isFile(flagFile) && exists(flagFile) && deleteIfExists(flagFile)) {
this.aliveFlagPath = null;
}
} catch (IOException ignored) {
}
}
}
@Override
public void dispose() {
}
}

View File

@@ -6,6 +6,7 @@ import com.intellij.java.JavaBundle
import com.intellij.openapi.ui.Messages
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.base.compilerPreferences.KotlinBaseCompilerConfigurationUiBundle
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.core.overrideImplement.BodyType
import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideMemberChooserObject
@@ -56,7 +57,7 @@ fun confirmMemberRewrite(targetClass: KtClass, vararg descriptors: FunctionDescr
if (isUnitTestMode()) return true
val functionsText =
descriptors.joinToString(separator = " ${KotlinBundle.message("configuration.text.and")} ") { "'${MEMBER_RENDERER.render(it)}'" }
descriptors.joinToString(separator = " ${KotlinBaseCompilerConfigurationUiBundle.message("configuration.text.and")} ") { "'${MEMBER_RENDERER.render(it)}'" }
val message = KotlinBundle.message("action.generate.functions.already.defined", functionsText, targetClass.name.toString())
return Messages.showYesNoDialog(
targetClass.project, message,

View File

@@ -13,8 +13,8 @@ import com.intellij.ui.components.JBLabelDecorator
import com.intellij.ui.components.JBTextField
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.UIUtil
import org.jetbrains.kotlin.base.util.onTextChange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.util.onTextChange
import javax.swing.InputVerifier
import javax.swing.JComponent
import kotlin.io.path.Path

View File

@@ -1,20 +0,0 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.idea.compiler.configuration
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.project.Project
abstract class ClearBuildStateExtension {
companion object {
@JvmStatic
fun getExtensions(): Array<out ClearBuildStateExtension> {
return EP_NAME.getExtensions()
}
val EP_NAME: ExtensionPointName<ClearBuildStateExtension> =
ExtensionPointName.create<ClearBuildStateExtension>("org.jetbrains.kotlin.clearBuildState")
}
abstract fun clearState(project: Project)
}

View File

@@ -5,116 +5,14 @@ package org.jetbrains.kotlin.idea.facet
import com.intellij.facet.FacetManager
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider
import com.intellij.openapi.module.Module
import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.projectRoots.JavaSdkVersion
import com.intellij.openapi.roots.ExternalProjectSystemRegistry
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ModuleRootModel
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.idea.compiler.configuration.*
import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion
import org.jetbrains.kotlin.idea.configuration.externalCompilerVersion
import org.jetbrains.kotlin.idea.core.isAndroidModule
import org.jetbrains.kotlin.idea.defaultSubstitutors
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.getProjectJdkTableSafe
import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.idePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
import kotlin.reflect.KProperty1
var Module.hasExternalSdkConfiguration: Boolean
by NotNullableUserDataProperty(Key.create<Boolean>("HAS_EXTERNAL_SDK_CONFIGURATION"), false)
private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?): TargetPlatform {
val platformKind = IdePlatformKind.ALL_KINDS.firstOrNull {
getRuntimeLibraryVersions(module, rootModel, it).isNotEmpty()
} ?: DefaultIdeTargetPlatformKindProvider.defaultPlatform.idePlatformKind
if (platformKind == JvmIdePlatformKind) {
var jvmTarget = Kotlin2JvmCompilerArgumentsHolder.getInstance(module.project).settings.jvmTarget?.let { JvmTarget.fromString(it) }
if (jvmTarget == null) {
val sdk = ((rootModel ?: ModuleRootManager.getInstance(module))).sdk
val sdkVersion = (sdk?.sdkType as? JavaSdk)?.getVersion(sdk)
if (sdkVersion == null || sdkVersion >= JavaSdkVersion.JDK_1_8) {
jvmTarget = JvmTarget.JVM_1_8
}
}
return if (jvmTarget != null) JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget) else JvmPlatforms.defaultJvmPlatform
}
return platformKind.defaultPlatform
}
fun KotlinFacetSettings.initializeIfNeeded(
module: Module,
rootModel: ModuleRootModel?,
platform: TargetPlatform? = null, // if null, detect by module dependencies
compilerVersion: IdeKotlinVersion? = null
) {
val project = module.project
val shouldInferLanguageLevel = languageLevel == null
val shouldInferAPILevel = apiLevel == null
if (compilerSettings == null) {
compilerSettings = KotlinCompilerSettings.getInstance(project).settings
}
val commonArguments = KotlinCommonCompilerArgumentsHolder.getInstance(module.project).settings
if (compilerArguments == null) {
val targetPlatform = platform ?: getDefaultTargetPlatform(module, rootModel)
compilerArguments = targetPlatform.createArguments {
targetPlatform.idePlatformKind.tooling.compilerArgumentsForProject(module.project)?.let { mergeBeans(it, this) }
mergeBeans(commonArguments, this)
}
this.targetPlatform = targetPlatform
}
if (shouldInferLanguageLevel) {
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
?: getDefaultLanguageLevel(module, compilerVersion, coerceRuntimeLibraryVersionToReleased = compilerVersion == null)
}
if (shouldInferAPILevel) {
apiLevel = if (useProjectSettings) {
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
} else {
val maximumValue = getLibraryVersion(
module,
rootModel,
this.targetPlatform?.idePlatformKind,
coerceRuntimeLibraryVersionToReleased = compilerVersion == null
)
languageLevel?.coerceAtMostVersion(maximumValue)
}
}
}
private fun LanguageVersion.coerceAtMostVersion(version: IdeKotlinVersion): LanguageVersion {
fun isUpToNextMinor(major: Int, minor: Int, patch: Int): Boolean {
return version.kotlinVersion.isAtLeast(major, minor, patch) && !version.kotlinVersion.isAtLeast(major, minor + 1)
}
// 1.4.30+ and 1.5.30+ have full support of next language version
val languageVersion = when {
isUpToNextMinor(1, 4, 30) -> LanguageVersion.KOTLIN_1_5
isUpToNextMinor(1, 5, 30) -> LanguageVersion.KOTLIN_1_6
else -> version.languageVersion
}
return this.coerceAtMost(languageVersion)
}
val mavenLibraryIdToPlatform: Map<String, IdePlatformKind> by lazy {
IdePlatformKind.ALL_KINDS
@@ -241,189 +139,3 @@ fun KotlinFacet.noVersionAutoAdvance() {
it.autoAdvanceApiVersion = false
}
}
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
// Update these lists when facet/project settings UI changes
val commonUIExposedFields = listOf(
CommonCompilerArguments::languageVersion.name,
CommonCompilerArguments::apiVersion.name,
CommonCompilerArguments::suppressWarnings.name
)
private val commonUIHiddenFields = listOf(
CommonCompilerArguments::pluginClasspaths.name,
CommonCompilerArguments::pluginOptions.name,
CommonCompilerArguments::multiPlatform.name
)
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
private val jvmSpecificUIExposedFields = listOf(
K2JVMCompilerArguments::jvmTarget.name,
K2JVMCompilerArguments::destination.name,
K2JVMCompilerArguments::classpath.name
)
private val jvmSpecificUIHiddenFields = listOf(
K2JVMCompilerArguments::friendPaths.name
)
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields + jvmSpecificUIHiddenFields
private val jsSpecificUIExposedFields = listOf(
K2JSCompilerArguments::sourceMap.name,
K2JSCompilerArguments::sourceMapPrefix.name,
K2JSCompilerArguments::sourceMapEmbedSources.name,
K2JSCompilerArguments::outputPrefix.name,
K2JSCompilerArguments::outputPostfix.name,
K2JSCompilerArguments::moduleKind.name
)
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
private val metadataSpecificUIExposedFields = listOf(
K2MetadataCompilerArguments::destination.name,
K2MetadataCompilerArguments::classpath.name
)
val metadataUIExposedFields = commonUIExposedFields + metadataSpecificUIExposedFields
private val metadataPrimaryFields = commonPrimaryFields + metadataSpecificUIExposedFields
private val CommonCompilerArguments.primaryFields: List<String>
get() = when (this) {
is K2JVMCompilerArguments -> jvmPrimaryFields
is K2JSCompilerArguments -> jsPrimaryFields
is K2MetadataCompilerArguments -> metadataPrimaryFields
else -> commonPrimaryFields
}
private val CommonCompilerArguments.ignoredFields: List<String>
get() = when (this) {
is K2JVMCompilerArguments -> listOf(K2JVMCompilerArguments::noJdk.name, K2JVMCompilerArguments::jdkHome.name)
else -> emptyList()
}
private fun Module.configureSdkIfPossible(compilerArguments: CommonCompilerArguments, modelsProvider: IdeModifiableModelsProvider) {
// SDK for Android module is already configured by Android plugin at this point
if (isAndroidModule(modelsProvider) || hasNonOverriddenExternalSdkConfiguration(compilerArguments)) return
val projectSdk = ProjectRootManager.getInstance(project).projectSdk
KotlinSdkType.setUpIfNeeded()
val allSdks = getProjectJdkTableSafe().allJdks
val sdk = if (compilerArguments is K2JVMCompilerArguments) {
val jdkHome = compilerArguments.jdkHome
when {
jdkHome != null -> allSdks.firstOrNull { it.sdkType is JavaSdk && FileUtil.comparePaths(it.homePath, jdkHome) == 0 }
projectSdk != null && projectSdk.sdkType is JavaSdk -> projectSdk
else -> allSdks.firstOrNull { it.sdkType is JavaSdk }
}
} else {
allSdks.firstOrNull { it.sdkType is KotlinSdkType }
?: modelsProvider
.modifiableModuleModel
.modules
.asSequence()
.mapNotNull { modelsProvider.getModifiableRootModel(it).sdk }
.firstOrNull { it.sdkType is KotlinSdkType }
}
val rootModel = modelsProvider.getModifiableRootModel(this)
if (sdk == null || sdk == projectSdk) {
rootModel.inheritSdk()
} else {
rootModel.sdk = sdk
}
}
private fun Module.hasNonOverriddenExternalSdkConfiguration(compilerArguments: CommonCompilerArguments): Boolean =
hasExternalSdkConfiguration && (compilerArguments !is K2JVMCompilerArguments || compilerArguments.jdkHome == null)
fun substituteDefaults(args: List<String>, compilerArguments: CommonCompilerArguments): List<String> =
args + defaultSubstitutors[compilerArguments::class]?.filter { it.isSubstitutable(args) }?.flatMap { it.oldSubstitution }.orEmpty()
fun parseCompilerArgumentsToFacet(
arguments: List<String>,
defaultArguments: List<String>,
kotlinFacet: KotlinFacet,
modelsProvider: IdeModifiableModelsProvider?
) {
val compilerArgumentsClass = kotlinFacet.configuration.settings.compilerArguments?.javaClass ?: return
val currentArgumentsBean = compilerArgumentsClass.newInstance()
val defaultArgumentsBean = compilerArgumentsClass.newInstance()
val defaultArgumentWithDefaults = substituteDefaults(defaultArguments, defaultArgumentsBean)
val currentArgumentWithDefaults = substituteDefaults(arguments, currentArgumentsBean)
parseCommandLineArguments(defaultArgumentWithDefaults, defaultArgumentsBean)
parseCommandLineArguments(currentArgumentWithDefaults, currentArgumentsBean)
applyCompilerArgumentsToFacet(currentArgumentsBean, defaultArgumentsBean, kotlinFacet, modelsProvider)
}
fun applyCompilerArgumentsToFacet(
arguments: CommonCompilerArguments,
defaultArguments: CommonCompilerArguments?,
kotlinFacet: KotlinFacet,
modelsProvider: IdeModifiableModelsProvider?
) {
with(kotlinFacet.configuration.settings) {
val compilerArguments = this.compilerArguments ?: return
val defaultCompilerArguments = defaultArguments?.let { copyBean(it) } ?: compilerArguments::class.java.newInstance()
defaultCompilerArguments.convertPathsToSystemIndependent()
val oldPluginOptions = compilerArguments.pluginOptions
val emptyArgs = compilerArguments::class.java.newInstance()
// Ad-hoc work-around for android compilations: middle source sets could be actualized up to
// Android target, meanwhile compiler arguments are of type K2Metadata
// TODO(auskov): merge classpath once compiler arguments are removed from KotlinFacetSettings
if (arguments.javaClass == compilerArguments.javaClass) {
copyBeanTo(arguments, compilerArguments) { property, value -> value != property.get(emptyArgs) }
}
compilerArguments.pluginOptions = joinPluginOptions(oldPluginOptions, arguments.pluginOptions)
compilerArguments.convertPathsToSystemIndependent()
// Retain only fields exposed (and not explicitly ignored) in facet configuration editor.
// The rest is combined into string and stored in CompilerSettings.additionalArguments
if (modelsProvider != null)
kotlinFacet.module.configureSdkIfPossible(compilerArguments, modelsProvider)
val primaryFields = compilerArguments.primaryFields
val ignoredFields = compilerArguments.ignoredFields
fun exposeAsAdditionalArgument(property: KProperty1<CommonCompilerArguments, Any?>) =
property.name !in primaryFields && property.get(compilerArguments) != property.get(defaultCompilerArguments)
val additionalArgumentsString = with(compilerArguments::class.java.newInstance()) {
copyFieldsSatisfying(compilerArguments, this) { exposeAsAdditionalArgument(it) && it.name !in ignoredFields }
ArgumentUtils.convertArgumentsToStringListNoDefaults(this).joinToString(separator = " ") {
if (StringUtil.containsWhitespaces(it) || it.startsWith('"')) {
StringUtil.wrapWithDoubleQuote(StringUtil.escapeQuotes(it))
} else it
}
}
compilerSettings?.additionalArguments =
if (additionalArgumentsString.isNotEmpty()) additionalArgumentsString else CompilerSettings.DEFAULT_ADDITIONAL_ARGUMENTS
with(compilerArguments::class.java.newInstance()) {
copyFieldsSatisfying(this, compilerArguments) { exposeAsAdditionalArgument(it) || it.name in ignoredFields }
}
val languageLevel = languageLevel
val apiLevel = apiLevel
if (languageLevel != null && apiLevel != null && apiLevel > languageLevel) {
this.apiLevel = languageLevel
}
updateMergedArguments()
}
}
private fun joinPluginOptions(old: Array<String>?, new: Array<String>?): Array<String>? {
if (old == null && new == null) {
return old
} else if (new == null) {
return old
} else if (old == null) {
return new
}
return (old + new).distinct().toTypedArray()
}

View File

@@ -6,7 +6,6 @@ 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.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion
@@ -19,8 +18,6 @@ import javax.swing.Icon
abstract class IdePlatformKindTooling {
abstract val kind: IdePlatformKind
abstract fun compilerArgumentsForProject(project: Project): CommonCompilerArguments?
abstract val mavenLibraryIds: List<String>
abstract val gradlePluginId: String
@@ -28,7 +25,6 @@ abstract class IdePlatformKindTooling {
abstract val libraryKind: PersistentLibraryKind<*>?
abstract fun getLibraryDescription(project: Project): CustomLibraryDescription?
abstract fun getLibraryVersionProvider(project: Project): (Library) -> IdeKotlinVersion?
abstract fun getTestIcon(
declaration: KtNamedDeclaration,

View File

@@ -7,6 +7,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.externalSystem.service.project.ProjectDataManager
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.base.util.invalidateProjectRoots
import com.intellij.openapi.project.RootsChangeRescanningInfo
import org.jetbrains.kotlin.config.CompilerSettings
import org.jetbrains.kotlin.diagnostics.Diagnostic
@@ -17,7 +18,6 @@ import org.jetbrains.kotlin.idea.configuration.BuildSystemType
import org.jetbrains.kotlin.idea.configuration.getBuildSystemType
import org.jetbrains.kotlin.idea.facet.getOrCreateConfiguredFacet
import org.jetbrains.kotlin.idea.quickfix.ExperimentalFixesFactory.annotationExists
import org.jetbrains.kotlin.idea.roots.invalidateProjectRoots
import org.jetbrains.kotlin.idea.util.projectStructure.module
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtFile

View File

@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.isOverridable
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.base.compilerPreferences.KotlinBaseCompilerConfigurationUiBundle
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.core.util.CachedValue
import org.jetbrains.kotlin.idea.core.util.getValue
@@ -88,7 +89,7 @@ class MakeOverriddenMemberOpenFix(declaration: KtDeclaration) : KotlinQuickFixAc
}
val sortedDeclarationNames = containingDeclarationsNames.sorted()
val declarations = sortedDeclarationNames.subList(0, sortedDeclarationNames.size - 1).joinToString(", ") +
" ${KotlinBundle.message("configuration.text.and")} " +
" ${KotlinBaseCompilerConfigurationUiBundle.message("configuration.text.and")} " +
sortedDeclarationNames.last()
return KotlinBundle.message("make.0.in.1.open", element.name.toString(), declarations)
}

View File

@@ -8,6 +8,7 @@ import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.base.compilerPreferences.KotlinBaseCompilerConfigurationUiBundle
import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtProperty
@@ -25,7 +26,9 @@ open class RemovePartsFromPropertyFix(
if (removeInitializer) add(KotlinBundle.message("text.initializer"))
}
fun concat(head: String, tail: String) = head + " " + KotlinBundle.message("configuration.text.and") + " " + tail
fun concat(head: String, tail: String): String {
return head + " " + KotlinBaseCompilerConfigurationUiBundle.message("configuration.text.and") + " " + tail
}
val partsText = when (chunks.size) {
0 -> ""

View File

@@ -15,10 +15,10 @@ import com.intellij.util.ui.FormBuilder
import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.base.util.onTextChange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.core.unquote
import org.jetbrains.kotlin.idea.core.util.onTextChange
import org.jetbrains.kotlin.idea.refactoring.introduce.extractClass.ExtractSuperInfo
import org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberInfo
import org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberSelectionPanel

View File

@@ -29,9 +29,9 @@ import com.intellij.ui.TextFieldWithHistoryWithBrowseButton
import com.intellij.ui.components.JBLabelDecorator
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.UIUtil
import org.jetbrains.kotlin.base.util.onTextChange
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.packageMatchesDirectoryOrImplicit
import org.jetbrains.kotlin.idea.core.util.onTextChange
import org.jetbrains.kotlin.idea.refactoring.isInKotlinAwareSourceRoot
import org.jetbrains.kotlin.idea.refactoring.move.logFusForMoveRefactoring
import org.jetbrains.kotlin.idea.util.application.executeCommand

View File

@@ -24,10 +24,9 @@ import org.jetbrains.jps.model.serialization.facet.JpsFacetSerializer
import org.jetbrains.jps.model.serialization.module.JpsModuleRootModelSerializer.*
import org.jetbrains.kotlin.config.getFacetPlatformByConfigurationElement
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.base.platforms.JsStdlibDetectionUtil
import org.jetbrains.kotlin.idea.facet.KotlinFacetType
import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil
import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil
import org.jetbrains.kotlin.idea.framework.getLibraryJar
import org.jetbrains.kotlin.platform.CommonPlatforms
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.isCommon
@@ -50,10 +49,10 @@ private val PLATFORM_TO_STDLIB_DETECTORS: Map<TargetPlatform, (Array<VirtualFile
JavaRuntimeDetectionUtil.getRuntimeJar(roots.toList()) != null
},
JsPlatforms.defaultJsPlatform to { roots: Array<VirtualFile> ->
JsLibraryStdDetectionUtil.getJsStdLibJar(roots.toList()) != null
JsStdlibDetectionUtil.getJavaScriptStdLibJar(roots.toList()) != null
},
CommonPlatforms.defaultCommonPlatform to { roots: Array<VirtualFile> ->
getLibraryJar(roots, PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN) != null
roots.any { PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN.matcher(it.name).matches() }
}
)

View File

@@ -28,6 +28,8 @@
<orderEntry type="module" module-name="kotlin.base.indices" scope="TEST" />
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" scope="TEST" />
<orderEntry type="module" module-name="kotlin.base.psi" />
<orderEntry type="module" module-name="kotlin.base.platforms" />
<orderEntry type="module" module-name="kotlin.base.facet" />
<orderEntry type="module" module-name="kotlin.base.fe10.analysis" />
<orderEntry type="module" module-name="kotlin.base.fe10.kdoc" />
<orderEntry type="module" module-name="kotlin.jvm" scope="TEST" />

Some files were not shown because too many files have changed in this diff Show More