diff --git a/.idea/modules.xml b/.idea/modules.xml index f1576db4311a..e7f8af998f50 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -1027,10 +1027,14 @@ + + + + diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/kotlin/KotlinPluginBuilder.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/kotlin/KotlinPluginBuilder.groovy index 192a7e21ae93..306871aa8cb2 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/kotlin/KotlinPluginBuilder.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/kotlin/KotlinPluginBuilder.groovy @@ -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", diff --git a/plugins/kotlin/analysis/resources/messages/KotlinIdeaAnalysisBundle.properties b/plugins/kotlin/analysis/resources/messages/KotlinIdeaAnalysisBundle.properties index 1b2ba3498702..f2d44e1c9f43 100644 --- a/plugins/kotlin/analysis/resources/messages/KotlinIdeaAnalysisBundle.properties +++ b/plugins/kotlin/analysis/resources/messages/KotlinIdeaAnalysisBundle.properties @@ -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 \ No newline at end of file diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/CommonPlatformKindResolution.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/CommonPlatformKindResolution.kt index 881a52d55659..cc86f76a9e55 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/CommonPlatformKindResolution.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/CommonPlatformKindResolution.kt @@ -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 { - 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 { diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/IdePlatformKindResolution.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/IdePlatformKindResolution.kt index 04d888710f57..ca8b7a225dbe 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/IdePlatformKindResolution.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/IdePlatformKindResolution.kt @@ -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 companion object : ApplicationExtensionDescriptor( diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/JsPlatformKindResolution.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/JsPlatformKindResolution.kt index d71243168a82..1d87e4c96b16 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/JsPlatformKindResolution.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/JsPlatformKindResolution.kt @@ -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 { - 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 { diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/JvmPlatformKindResolution.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/JvmPlatformKindResolution.kt index 456d15141c07..c9ab83ee0918 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/JvmPlatformKindResolution.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/caches/resolve/JvmPlatformKindResolution.kt @@ -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 = listOf(JvmLibraryInfo(project, library)) diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt index 26f76267bd56..ad3d561cc32c 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt @@ -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 diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/LibraryInfoCache.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/LibraryInfoCache.kt index 74f3bf4e84f1..1e8b97e9fca0 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/LibraryInfoCache.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/LibraryInfoCache.kt @@ -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 } diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt index 62dbdb086a53..ae653eeb6200 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt @@ -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 = getProjectJdkTableSafe().allJdks +fun getAllProjectSdks(): Array = runReadAction { ProjectJdkTable.getInstance() }.allJdks diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/multiplatformUtil.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/multiplatformUtil.kt index eaa0d4f8fcf0..03bd7daf6a64 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/multiplatformUtil.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/caches/project/multiplatformUtil.kt @@ -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 diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/CommonLibraryType.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/CommonLibraryType.kt index cc54b54f526d..38e2040af740 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/CommonLibraryType.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/CommonLibraryType.kt @@ -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(CommonLibraryKind) { +object CommonLibraryType : LibraryType(KotlinCommonLibraryKind) { override fun createPropertiesEditor(editorComponent: LibraryEditorComponent) = null override fun getCreateActionName() = null diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/LibraryEffectiveKindProvider.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/LibraryEffectiveKindProvider.kt deleted file mode 100644 index a3cace79c1a4..000000000000 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/LibraryEffectiveKindProvider.kt +++ /dev/null @@ -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) \ No newline at end of file diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/LibraryKinds.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/LibraryKinds.kt deleted file mode 100644 index fa19fa2451e5..000000000000 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/LibraryKinds.kt +++ /dev/null @@ -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("kotlin.js"), KotlinLibraryKind { - override val compilerPlatform: TargetPlatform - get() = JsPlatforms.defaultJsPlatform - - override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!! -} - -object CommonLibraryKind : PersistentLibraryKind("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): 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, 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) -} diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/klib/utils.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/klib/utils.kt index ce206c746ad4..fd471edd7610 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/klib/utils.kt +++ b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/klib/utils.kt @@ -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 KotlinLibrary.safeRead(defaultValue: T, action: KotlinLibrary.() -> T) = try { action() diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/util/ijPlatformUtil.kt b/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/util/ijPlatformUtil.kt deleted file mode 100644 index 6a446c572484..000000000000 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/util/ijPlatformUtil.kt +++ /dev/null @@ -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() } diff --git a/plugins/kotlin/base/compiler-configuration-ui/kotlin.base.compiler-configuration-ui.iml b/plugins/kotlin/base/compiler-configuration-ui/kotlin.base.compiler-configuration-ui.iml new file mode 100644 index 000000000000..796216bb1100 --- /dev/null +++ b/plugins/kotlin/base/compiler-configuration-ui/kotlin.base.compiler-configuration-ui.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/kotlin/base/compiler-configuration-ui/resources/messages/KotlinBaseCompilerConfigurationUiBundle.properties b/plugins/kotlin/base/compiler-configuration-ui/resources/messages/KotlinBaseCompilerConfigurationUiBundle.properties new file mode 100644 index 000000000000..7e8d830ea289 --- /dev/null +++ b/plugins/kotlin/base/compiler-configuration-ui/resources/messages/KotlinBaseCompilerConfigurationUiBundle.properties @@ -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 \ No newline at end of file diff --git a/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/KotlinBaseCompilerConfigurationUiBundle.kt b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/KotlinBaseCompilerConfigurationUiBundle.kt new file mode 100644 index 000000000000..53c1fd620ab1 --- /dev/null +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/KotlinBaseCompilerConfigurationUiBundle.kt @@ -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) +} \ No newline at end of file diff --git a/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/KotlinFacetEditorProviderServiceImpl.kt b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/KotlinFacetEditorProviderServiceImpl.kt new file mode 100644 index 000000000000..83502650213b --- /dev/null +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/KotlinFacetEditorProviderServiceImpl.kt @@ -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 { + val tabs = ArrayList(2) + tabs += KotlinFacetEditorGeneralTab(configuration, editorContext, validatorsManager) + if (KotlinFacetCompilerPluginsTab.parsePluginOptions(configuration).isNotEmpty()) { + tabs += KotlinFacetCompilerPluginsTab(configuration, validatorsManager) + } + return tabs + } + + override fun getMultipleConfigurationEditor(project: Project, editors: Array): MultipleFacetSettingsEditor { + return MultipleKotlinFacetEditor(project, editors) + } +} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/JpsVersionItem.java b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/JpsVersionItem.java similarity index 81% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/JpsVersionItem.java rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/JpsVersionItem.java index 834a3a56f2f4..a7ea5bba363f 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/JpsVersionItem.java +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/JpsVersionItem.java @@ -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(); diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/KotlinCompilerConfigurableTab.form similarity index 99% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/KotlinCompilerConfigurableTab.form index 0eb5af3c5d22..4315fbd04037 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/KotlinCompilerConfigurableTab.form @@ -1,5 +1,5 @@ -
+ diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/KotlinCompilerConfigurableTab.java similarity index 93% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/KotlinCompilerConfigurableTab.java index 5c8148651859..1ffb2cde8579 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/configuration/KotlinCompilerConfigurableTab.java @@ -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(""); - 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; diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/DescriptionListCellRenderer.kt b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/DescriptionListCellRenderer.kt similarity index 91% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/DescriptionListCellRenderer.kt rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/DescriptionListCellRenderer.kt index c6b295e4b7a8..65867b410b1f 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/DescriptionListCellRenderer.kt +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/DescriptionListCellRenderer.kt @@ -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 diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetCompilerPluginsTab.kt b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetCompilerPluginsTab.kt similarity index 90% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetCompilerPluginsTab.kt rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetCompilerPluginsTab.kt index 5d6ec3901376..e4ddca87027e 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetCompilerPluginsTab.kt +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetCompilerPluginsTab.kt @@ -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("
") invalidOptions.joinTo(this, "
") { "$it" } } @@ -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()) diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetEditorGeneralTab.kt similarity index 90% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetEditorGeneralTab.kt index 333d5561bd02..fc0bf90e3089 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetEditorGeneralTab.kt @@ -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() @@ -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("
") } 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( ?: "" 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 ComboBox.selectedItemTyped: T? +private val ComboBox.selectedItemTyped: T? get() = selectedItem as T? diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetValidatorCreator.kt b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetValidatorCreator.kt similarity index 73% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetValidatorCreator.kt rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetValidatorCreator.kt index d59fff590e13..19cd4439e328 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetValidatorCreator.kt +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinFacetValidatorCreator.kt @@ -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 = - ExtensionPointName.create("org.jetbrains.kotlin.facetValidatorCreator") + ExtensionPointName.create("org.jetbrains.kotlin.facetValidatorCreator") } abstract fun create( diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProviderByModuleDependencies.kt b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinVersionInfoProviderByModuleDependencies.kt similarity index 80% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProviderByModuleDependencies.kt rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinVersionInfoProviderByModuleDependencies.kt index 75200db1290a..6bab15be083f 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProviderByModuleDependencies.kt +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/KotlinVersionInfoProviderByModuleDependencies.kt @@ -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().apply { diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/MultipleKotlinFacetEditor.kt b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/MultipleKotlinFacetEditor.kt similarity index 95% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/MultipleKotlinFacetEditor.kt rename to plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/MultipleKotlinFacetEditor.kt index 63be684dce65..cbe4d212e97e 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/MultipleKotlinFacetEditor.kt +++ b/plugins/kotlin/base/compiler-configuration-ui/src/org/jetbrains/kotlin/idea/base/compilerPreferences/facet/MultipleKotlinFacetEditor.kt @@ -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 diff --git a/plugins/kotlin/base/facet/kotlin.base.facet.iml b/plugins/kotlin/base/facet/kotlin.base.facet.iml new file mode 100644 index 000000000000..2ca8c61a3968 --- /dev/null +++ b/plugins/kotlin/base/facet/kotlin.base.facet.iml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/kotlin/base/facet/resources/messages/KotlinBaseFacetBundle.properties b/plugins/kotlin/base/facet/resources/messages/KotlinBaseFacetBundle.properties new file mode 100644 index 000000000000..1c2a7efe5896 --- /dev/null +++ b/plugins/kotlin/base/facet/resources/messages/KotlinBaseFacetBundle.properties @@ -0,0 +1 @@ +framework.name.kotlin.sdk=Kotlin SDK \ No newline at end of file diff --git a/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/base/facet/KotlinBaseFacetBundle.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/base/facet/KotlinBaseFacetBundle.kt new file mode 100644 index 000000000000..af6f2c62b1f6 --- /dev/null +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/base/facet/KotlinBaseFacetBundle.kt @@ -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) +} \ No newline at end of file diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinFacet.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacet.kt similarity index 94% rename from plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinFacet.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacet.kt index af17be949ed7..f057b0cc3702 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinFacet.kt +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacet.kt @@ -14,7 +14,7 @@ class KotlinFacet( companion object { fun get(module: Module): KotlinFacet? { if (module.isDisposed) return null - return FacetManager.getInstance(module).getFacetByType(KotlinFacetType.TYPE_ID) + return FacetManager.getInstance(module).getFacetByType(KotlinFacetType.TYPE_ID) } } } diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfiguration.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfiguration.kt similarity index 100% rename from plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfiguration.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfiguration.kt diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationExtension.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationExtension.kt similarity index 100% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationExtension.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationExtension.kt diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationImpl.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationImpl.kt similarity index 82% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationImpl.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationImpl.kt index 91b4754033a7..d688720562fb 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationImpl.kt +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetConfigurationImpl.kt @@ -30,10 +30,8 @@ class KotlinFacetConfigurationImpl : KotlinFacetConfiguration { ): Array { settings.initializeIfNeeded(editorContext.module, editorContext.rootModel) - val tabs = arrayListOf(KotlinFacetEditorGeneralTab(this, editorContext, validatorsManager)) - if (KotlinFacetCompilerPluginsTab.parsePluginOptions(this).isNotEmpty()) { - tabs += KotlinFacetCompilerPluginsTab(this, validatorsManager) - } + val tabs = arrayListOf() + tabs += KotlinFacetEditorProviderService.getInstance(editorContext.project).getEditorTabs(this, editorContext, validatorsManager) KotlinFacetConfigurationExtension.EP_NAME.extensions.flatMapTo(tabs) { it.createEditorTabs(editorContext, validatorsManager) } return tabs.toTypedArray() } diff --git a/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorProviderService.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorProviderService.kt new file mode 100644 index 000000000000..6372807fad76 --- /dev/null +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorProviderService.kt @@ -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 + + fun getMultipleConfigurationEditor(project: Project, editors: Array): MultipleFacetSettingsEditor + + companion object { + @JvmStatic + fun getInstance(project: Project): KotlinFacetEditorProviderService = project.service() + } +} \ No newline at end of file diff --git a/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetFields.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetFields.kt new file mode 100644 index 000000000000..860dd683e63b --- /dev/null +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetFields.kt @@ -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 { + 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, + hiddenFields: List +) { + val exposedFields: List = if (base != null) base.exposedFields + exposedFields else exposedFields + private val hiddenFields: List = if (base != null) base.hiddenFields + hiddenFields else hiddenFields + val allFields: List + 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 + get() = when (this) { + is K2JVMCompilerArguments -> jvmFields.allFields + is K2JSCompilerArguments -> jsFields.allFields + is K2MetadataCompilerArguments -> metadataFields.allFields + else -> commonFields.allFields + } + +internal val CommonCompilerArguments.ignoredFields: List + get() = when (this) { + is K2JVMCompilerArguments -> listOf(K2JVMCompilerArguments::noJdk.name, K2JVMCompilerArguments::jdkHome.name) + else -> emptyList() + } \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetSettingsProviderImpl.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetSettingsProviderImpl.kt similarity index 100% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetSettingsProviderImpl.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetSettingsProviderImpl.kt diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinFacetType.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetType.kt similarity index 100% rename from plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinFacetType.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetType.kt diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetTypeImpl.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetTypeImpl.kt similarity index 75% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetTypeImpl.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetTypeImpl.kt index 1a32c564c016..024841fd214a 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetTypeImpl.kt +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetTypeImpl.kt @@ -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() { - override fun createDefaultConfiguration() = KotlinFacetConfigurationImpl() override fun createFacet( @@ -18,6 +18,7 @@ class KotlinFacetTypeImpl : KotlinFacetType() { underlyingFacet: Facet<*>? ) = KotlinFacet(module, name, configuration) - override fun createMultipleConfigurationsEditor(project: Project, editors: Array) = - MultipleKotlinFacetEditor(project, editors) + override fun createMultipleConfigurationsEditor(project: Project, editors: Array): MultipleFacetSettingsEditor { + return KotlinFacetEditorProviderService.getInstance(project).getMultipleConfigurationEditor(project, editors) + } } \ No newline at end of file diff --git a/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetUtils.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetUtils.kt new file mode 100644 index 000000000000..67fd838a8d36 --- /dev/null +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinFacetUtils.kt @@ -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, + defaultArguments: List, + 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) = + 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, compilerArguments: CommonCompilerArguments): List { + val substitutedCompilerArguments = defaultSubstitutors[compilerArguments::class] + ?.filter { it.isSubstitutable(args) } + ?.flatMap { it.oldSubstitution } + return args + substitutedCompilerArguments.orEmpty() +} + +private fun joinPluginOptions(old: Array?, new: Array?): Array? { + if (old == null && new == null) { + return old + } else if (new == null) { + return old + } else if (old == null) { + return new + } + + return (old + new).distinct().toTypedArray() +} \ No newline at end of file diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt similarity index 100% rename from plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/KotlinSdkType.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/framework/KotlinSdkType.kt similarity index 90% rename from plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/KotlinSdkType.kt rename to plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/framework/KotlinSdkType.kt index fc714ae2a925..b9be35e4c936 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/KotlinSdkType.kt +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/framework/KotlinSdkType.kt @@ -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 diff --git a/plugins/kotlin/base/jps/kotlin.base.jps.iml b/plugins/kotlin/base/jps/kotlin.base.jps.iml new file mode 100644 index 000000000000..f10aea39dcf2 --- /dev/null +++ b/plugins/kotlin/base/jps/kotlin.base.jps.iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/jps/KotlinFacetListener.kt b/plugins/kotlin/base/jps/src/org/jetbrains/kotlin/idea/jps/KotlinFacetListener.kt similarity index 100% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/jps/KotlinFacetListener.kt rename to plugins/kotlin/base/jps/src/org/jetbrains/kotlin/idea/jps/KotlinFacetListener.kt diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/jps/KotlinJpsClasspathProvider.kt b/plugins/kotlin/base/jps/src/org/jetbrains/kotlin/idea/jps/KotlinJpsClasspathProvider.kt similarity index 100% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/jps/KotlinJpsClasspathProvider.kt rename to plugins/kotlin/base/jps/src/org/jetbrains/kotlin/idea/jps/KotlinJpsClasspathProvider.kt diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/jps/SetupKotlinJpsPluginBeforeCompileTask.kt b/plugins/kotlin/base/jps/src/org/jetbrains/kotlin/idea/jps/SetupKotlinJpsPluginBeforeCompileTask.kt similarity index 100% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/jps/SetupKotlinJpsPluginBeforeCompileTask.kt rename to plugins/kotlin/base/jps/src/org/jetbrains/kotlin/idea/jps/SetupKotlinJpsPluginBeforeCompileTask.kt diff --git a/plugins/kotlin/base/platforms/kotlin.base.platforms.iml b/plugins/kotlin/base/platforms/kotlin.base.platforms.iml new file mode 100644 index 000000000000..590c527f2629 --- /dev/null +++ b/plugins/kotlin/base/platforms/kotlin.base.platforms.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/IdePlatformKindProjectStructure.kt b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/IdePlatformKindProjectStructure.kt new file mode 100644 index 000000000000..746361de977c --- /dev/null +++ b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/IdePlatformKindProjectStructure.kt @@ -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, 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") + } + } + } +} + diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/JsLibraryStdDetectionUtil.kt b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/JsStdlibDetectionUtil.kt similarity index 65% rename from plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/JsLibraryStdDetectionUtil.kt rename to plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/JsStdlibDetectionUtil.kt index 4e7b9f250d77..7ec0fe894945 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/framework/JsLibraryStdDetectionUtil.kt +++ b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/JsStdlibDetectionUtil.kt @@ -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("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? { + private fun isJavaScriptLibrary(library: Library, project: Project): Boolean { + return LibraryEffectiveKindProvider.getInstance(project).getEffectiveKind(library as LibraryEx) is KotlinJavaScriptLibraryKind + } + + fun getJavaScriptStdLibJar(classesRoots: List): VirtualFile? { for (root in classesRoots) { if (root.fileSystem.protocol !== StandardFileSystems.JAR_PROTOCOL) continue diff --git a/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KLibUtils.kt b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KLibUtils.kt new file mode 100644 index 000000000000..d5cda8b22508 --- /dev/null +++ b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KLibUtils.kt @@ -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() + } \ No newline at end of file diff --git a/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KotlinLibraryKind.kt b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KotlinLibraryKind.kt new file mode 100644 index 000000000000..137ed344cff2 --- /dev/null +++ b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KotlinLibraryKind.kt @@ -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("kotlin.js"), KotlinLibraryKind { + override val compilerPlatform: TargetPlatform + get() = JsPlatforms.defaultJsPlatform + + override fun createDefaultProperties(): DummyLibraryProperties { + return DummyLibraryProperties.INSTANCE + } +} + +object KotlinCommonLibraryKind : PersistentLibraryKind("kotlin.common"), KotlinLibraryKind { + override val compilerPlatform: TargetPlatform + get() = CommonPlatforms.defaultCommonPlatform + + override fun createDefaultProperties(): DummyLibraryProperties { + return DummyLibraryProperties.INSTANCE + } +} + +object KotlinNativeLibraryKind : PersistentLibraryKind("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): 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) +} \ No newline at end of file diff --git a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinLibraryKindIndex.kt b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KotlinLibraryKindIndex.kt similarity index 95% rename from plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinLibraryKindIndex.kt rename to plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KotlinLibraryKindIndex.kt index 2205afb28699..18e1ef0e6e5d 100644 --- a/plugins/kotlin/analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinLibraryKindIndex.kt +++ b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/KotlinLibraryKindIndex.kt @@ -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 diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/framework/LibraryEffectiveKindProviderImpl.kt b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/LibraryEffectiveKindProvider.kt similarity index 66% rename from plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/framework/LibraryEffectiveKindProviderImpl.kt rename to plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/LibraryEffectiveKindProvider.kt index 19d760735710..3d86b87f1eb5 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/framework/LibraryEffectiveKindProviderImpl.kt +++ b/plugins/kotlin/base/platforms/src/org/jetbrains/kotlin/idea/base/platforms/LibraryEffectiveKindProvider.kt @@ -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?>() { 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() + } } \ No newline at end of file diff --git a/plugins/kotlin/base/plugin/src/org/jetbrains/kotlin/idea/PluginStartupApplicationService.kt b/plugins/kotlin/base/plugin/src/org/jetbrains/kotlin/idea/PluginStartupApplicationService.kt new file mode 100644 index 000000000000..074eeae48d23 --- /dev/null +++ b/plugins/kotlin/base/plugin/src/org/jetbrains/kotlin/idea/PluginStartupApplicationService.kt @@ -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() + } +} \ No newline at end of file diff --git a/plugins/kotlin/base/resources/kotlin.base.resources.iml b/plugins/kotlin/base/resources/kotlin.base.resources.iml index e665855254f9..a54344cccc7f 100644 --- a/plugins/kotlin/base/resources/kotlin.base.resources.iml +++ b/plugins/kotlin/base/resources/kotlin.base.resources.iml @@ -10,7 +10,6 @@ - diff --git a/plugins/kotlin/base/util/kotlin.base.util.iml b/plugins/kotlin/base/util/kotlin.base.util.iml index 9ef116551474..3c6fb35370b1 100644 --- a/plugins/kotlin/base/util/kotlin.base.util.iml +++ b/plugins/kotlin/base/util/kotlin.base.util.iml @@ -9,6 +9,10 @@ + + + + \ No newline at end of file diff --git a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/roots/rootUtils.kt b/plugins/kotlin/base/util/src/org/jetbrains/kotlin/base/util/ProjectStructureUtils.kt similarity index 57% rename from plugins/kotlin/core/src/org/jetbrains/kotlin/idea/roots/rootUtils.kt rename to plugins/kotlin/base/util/src/org/jetbrains/kotlin/base/util/ProjectStructureUtils.kt index d959c40d53d5..c33c7bcb2a98 100644 --- a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/roots/rootUtils.kt +++ b/plugins/kotlin/base/util/src/org/jetbrains/kotlin/base/util/ProjectStructureUtils.kt @@ -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) } \ No newline at end of file diff --git a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/util/UiUtils.kt b/plugins/kotlin/base/util/src/org/jetbrains/kotlin/base/util/UIUtils.kt similarity index 64% rename from plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/util/UiUtils.kt rename to plugins/kotlin/base/util/src/org/jetbrains/kotlin/base/util/UIUtils.kt index 6caa466b6838..4e3bf4e7e83a 100644 --- a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/util/UiUtils.kt +++ b/plugins/kotlin/base/util/src/org/jetbrains/kotlin/base/util/UIUtils.kt @@ -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 diff --git a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/util/PhysicalFileSystemUtils.kt b/plugins/kotlin/base/util/src/org/jetbrains/kotlin/idea/core/util/PhysicalFileSystemUtils.kt similarity index 100% rename from plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/util/PhysicalFileSystemUtils.kt rename to plugins/kotlin/base/util/src/org/jetbrains/kotlin/idea/core/util/PhysicalFileSystemUtils.kt diff --git a/plugins/kotlin/compiler-plugins/allopen/tests/kotlin.compiler-plugins.allopen.tests.iml b/plugins/kotlin/compiler-plugins/allopen/tests/kotlin.compiler-plugins.allopen.tests.iml index 907d45fa98ec..c6963eb8aa33 100644 --- a/plugins/kotlin/compiler-plugins/allopen/tests/kotlin.compiler-plugins.allopen.tests.iml +++ b/plugins/kotlin/compiler-plugins/allopen/tests/kotlin.compiler-plugins.allopen.tests.iml @@ -15,6 +15,7 @@ + diff --git a/plugins/kotlin/compiler-plugins/compiler-plugin-support/common/kotlin.compiler-plugins.compiler-plugin-support.common.iml b/plugins/kotlin/compiler-plugins/compiler-plugin-support/common/kotlin.compiler-plugins.compiler-plugin-support.common.iml index 89348ddacb94..1afecb2d8f8f 100644 --- a/plugins/kotlin/compiler-plugins/compiler-plugin-support/common/kotlin.compiler-plugins.compiler-plugin-support.common.iml +++ b/plugins/kotlin/compiler-plugins/compiler-plugin-support/common/kotlin.compiler-plugins.compiler-plugin-support.common.iml @@ -11,9 +11,10 @@ + + - diff --git a/plugins/kotlin/compiler-plugins/compiler-plugin-support/gradle/kotlin.compiler-plugins.compiler-plugin-support.gradle.iml b/plugins/kotlin/compiler-plugins/compiler-plugin-support/gradle/kotlin.compiler-plugins.compiler-plugin-support.gradle.iml index c45d16200f6c..e8270b0eb53d 100644 --- a/plugins/kotlin/compiler-plugins/compiler-plugin-support/gradle/kotlin.compiler-plugins.compiler-plugin-support.gradle.iml +++ b/plugins/kotlin/compiler-plugins/compiler-plugin-support/gradle/kotlin.compiler-plugins.compiler-plugin-support.gradle.iml @@ -9,6 +9,7 @@ + diff --git a/plugins/kotlin/compiler-plugins/compiler-plugin-support/maven/kotlin.compiler-plugins.compiler-plugin-support.maven.iml b/plugins/kotlin/compiler-plugins/compiler-plugin-support/maven/kotlin.compiler-plugins.compiler-plugin-support.maven.iml index 573d567a74c9..25ef390b6833 100644 --- a/plugins/kotlin/compiler-plugins/compiler-plugin-support/maven/kotlin.compiler-plugins.compiler-plugin-support.maven.iml +++ b/plugins/kotlin/compiler-plugins/compiler-plugin-support/maven/kotlin.compiler-plugins.compiler-plugin-support.maven.iml @@ -10,6 +10,7 @@ + diff --git a/plugins/kotlin/compiler-plugins/kapt/kotlin.compiler-plugins.kapt.iml b/plugins/kotlin/compiler-plugins/kapt/kotlin.compiler-plugins.kapt.iml index 7e983838b9be..d753b731771c 100644 --- a/plugins/kotlin/compiler-plugins/kapt/kotlin.compiler-plugins.kapt.iml +++ b/plugins/kotlin/compiler-plugins/kapt/kotlin.compiler-plugins.kapt.iml @@ -12,6 +12,7 @@ + diff --git a/plugins/kotlin/compiler-plugins/kotlinx-serialization/common/kotlin.compiler-plugins.kotlinx-serialization.common.iml b/plugins/kotlin/compiler-plugins/kotlinx-serialization/common/kotlin.compiler-plugins.kotlinx-serialization.common.iml index a96396405e61..a0d7bfe13ff5 100644 --- a/plugins/kotlin/compiler-plugins/kotlinx-serialization/common/kotlin.compiler-plugins.kotlinx-serialization.common.iml +++ b/plugins/kotlin/compiler-plugins/kotlinx-serialization/common/kotlin.compiler-plugins.kotlinx-serialization.common.iml @@ -19,6 +19,7 @@ + diff --git a/plugins/kotlin/compiler-plugins/kotlinx-serialization/gradle/kotlin.compiler-plugins.kotlinx-serialization.gradle.iml b/plugins/kotlin/compiler-plugins/kotlinx-serialization/gradle/kotlin.compiler-plugins.kotlinx-serialization.gradle.iml index ff959c025b5a..e4fe542e12a3 100644 --- a/plugins/kotlin/compiler-plugins/kotlinx-serialization/gradle/kotlin.compiler-plugins.kotlinx-serialization.gradle.iml +++ b/plugins/kotlin/compiler-plugins/kotlinx-serialization/gradle/kotlin.compiler-plugins.kotlinx-serialization.gradle.iml @@ -9,6 +9,7 @@ + diff --git a/plugins/kotlin/compiler-plugins/noarg/tests/kotlin.compiler-plugins.noarg.tests.iml b/plugins/kotlin/compiler-plugins/noarg/tests/kotlin.compiler-plugins.noarg.tests.iml index 254ee786aec6..dbbdd8191723 100644 --- a/plugins/kotlin/compiler-plugins/noarg/tests/kotlin.compiler-plugins.noarg.tests.iml +++ b/plugins/kotlin/compiler-plugins/noarg/tests/kotlin.compiler-plugins.noarg.tests.iml @@ -15,6 +15,7 @@ + diff --git a/plugins/kotlin/compiler-plugins/scripting/kotlin.compiler-plugins.scripting.iml b/plugins/kotlin/compiler-plugins/scripting/kotlin.compiler-plugins.scripting.iml index c71ff843cd2a..30c78e05acfb 100644 --- a/plugins/kotlin/compiler-plugins/scripting/kotlin.compiler-plugins.scripting.iml +++ b/plugins/kotlin/compiler-plugins/scripting/kotlin.compiler-plugins.scripting.iml @@ -12,6 +12,7 @@ + diff --git a/plugins/kotlin/core/kotlin.core.iml b/plugins/kotlin/core/kotlin.core.iml index 23e750239783..4614851ab8be 100644 --- a/plugins/kotlin/core/kotlin.core.iml +++ b/plugins/kotlin/core/kotlin.core.iml @@ -28,9 +28,11 @@ + + diff --git a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/artifacts/KotlinLibraryData.kt b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/artifacts/KotlinLibraryData.kt index 491d4255a87b..021525dbb661 100644 --- a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/artifacts/KotlinLibraryData.kt +++ b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/artifacts/KotlinLibraryData.kt @@ -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 ) diff --git a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/moduleUtils.kt b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/moduleUtils.kt index 68de84db1ac9..871ba367f483 100644 --- a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/moduleUtils.kt +++ b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/moduleUtils.kt @@ -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 diff --git a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/packageUtils.kt b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/packageUtils.kt index 054631b6cb0a..3f5613d294ed 100644 --- a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/packageUtils.kt +++ b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/packageUtils.kt @@ -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) } diff --git a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/script/ScriptDefinitionsManager.kt b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/script/ScriptDefinitionsManager.kt index 60db06b15fc2..4db13b7bbead 100644 --- a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/script/ScriptDefinitionsManager.kt +++ b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/script/ScriptDefinitionsManager.kt @@ -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 } diff --git a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/script/ucache/ScriptSdksBuilder.kt b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/script/ucache/ScriptSdksBuilder.kt index 1ab7b3188a55..bc5c5aa87539 100644 --- a/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/script/ucache/ScriptSdksBuilder.kt +++ b/plugins/kotlin/core/src/org/jetbrains/kotlin/idea/core/script/ucache/ScriptSdksBuilder.kt @@ -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 } diff --git a/plugins/kotlin/features-trainer/kotlin.features-trainer.iml b/plugins/kotlin/features-trainer/kotlin.features-trainer.iml index f2804142c6bb..42df6fe2d136 100644 --- a/plugins/kotlin/features-trainer/kotlin.features-trainer.iml +++ b/plugins/kotlin/features-trainer/kotlin.features-trainer.iml @@ -18,6 +18,7 @@ + diff --git a/plugins/kotlin/fir/kotlin.fir.iml b/plugins/kotlin/fir/kotlin.fir.iml index 340165ebf228..0c17bfb8acc8 100644 --- a/plugins/kotlin/fir/kotlin.fir.iml +++ b/plugins/kotlin/fir/kotlin.fir.iml @@ -20,6 +20,7 @@ + @@ -31,7 +32,6 @@ - diff --git a/plugins/kotlin/frontend-independent/resources-en/messages/KotlinBundle.properties b/plugins/kotlin/frontend-independent/resources-en/messages/KotlinBundle.properties index c7bec1f073a6..040bc53039f4 100644 --- a/plugins/kotlin/frontend-independent/resources-en/messages/KotlinBundle.properties +++ b/plugins/kotlin/frontend-independent/resources-en/messages/KotlinBundle.properties @@ -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= -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 diff --git a/plugins/kotlin/gradle/gradle-java/kotlin.gradle.gradle-java.iml b/plugins/kotlin/gradle/gradle-java/kotlin.gradle.gradle-java.iml index 3f96bd0c4302..971d125a50eb 100644 --- a/plugins/kotlin/gradle/gradle-java/kotlin.gradle.gradle-java.iml +++ b/plugins/kotlin/gradle/gradle-java/kotlin.gradle.gradle-java.iml @@ -36,6 +36,8 @@ + + diff --git a/plugins/kotlin/gradle/gradle-java/src/org/jetbrains/kotlin/idea/gradleJava/configuration/KotlinGradleModuleConfigurator.kt b/plugins/kotlin/gradle/gradle-java/src/org/jetbrains/kotlin/idea/gradleJava/configuration/KotlinGradleModuleConfigurator.kt index cff1b795a18c..054c5ad7541a 100644 --- a/plugins/kotlin/gradle/gradle-java/src/org/jetbrains/kotlin/idea/gradleJava/configuration/KotlinGradleModuleConfigurator.kt +++ b/plugins/kotlin/gradle/gradle-java/src/org/jetbrains/kotlin/idea/gradleJava/configuration/KotlinGradleModuleConfigurator.kt @@ -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 diff --git a/plugins/kotlin/gradle/gradle-java/src/org/jetbrains/kotlin/idea/gradleJava/configuration/KotlinGradleSourceSetDataService.kt b/plugins/kotlin/gradle/gradle-java/src/org/jetbrains/kotlin/idea/gradleJava/configuration/KotlinGradleSourceSetDataService.kt index 9fbe4d5619aa..62bee5301bc9 100644 --- a/plugins/kotlin/gradle/gradle-java/src/org/jetbrains/kotlin/idea/gradleJava/configuration/KotlinGradleSourceSetDataService.kt +++ b/plugins/kotlin/gradle/gradle-java/src/org/jetbrains/kotlin/idea/gradleJava/configuration/KotlinGradleSourceSetDataService.kt @@ -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 - 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> = listOf( + KotlinJavaScriptLibraryKind, + KotlinNativeLibraryKind, + KotlinCommonLibraryKind + ) + + val NON_JVM_SUFFIXES = listOf("-common", "-js", "-native", "-kjsm", "-metadata") } } diff --git a/plugins/kotlin/gradle/gradle-java/tests/kotlin.gradle.gradle-java.tests.iml b/plugins/kotlin/gradle/gradle-java/tests/kotlin.gradle.gradle-java.tests.iml index 127c43e773e3..db83ce8c2ed4 100644 --- a/plugins/kotlin/gradle/gradle-java/tests/kotlin.gradle.gradle-java.tests.iml +++ b/plugins/kotlin/gradle/gradle-java/tests/kotlin.gradle.gradle-java.tests.iml @@ -18,6 +18,8 @@ + + diff --git a/plugins/kotlin/gradle/gradle-java/tests/test/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt b/plugins/kotlin/gradle/gradle-java/tests/test/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt index 198bccba6846..fa52fc5381c1 100644 --- a/plugins/kotlin/gradle/gradle-java/tests/test/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt +++ b/plugins/kotlin/gradle/gradle-java/tests/test/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt @@ -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() 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().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().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.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.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().single().library - assertEquals(CommonLibraryKind, (stdlib as LibraryEx).kind) + assertEquals(KotlinCommonLibraryKind, (stdlib as LibraryEx).kind) assertSameKotlinSdks("project.main", "project.test") diff --git a/plugins/kotlin/gradle/gradle-native/tests/kotlin.gradle.gradle-native.tests.iml b/plugins/kotlin/gradle/gradle-native/tests/kotlin.gradle.gradle-native.tests.iml index db14caad7e4c..1ee7b2a627c1 100644 --- a/plugins/kotlin/gradle/gradle-native/tests/kotlin.gradle.gradle-native.tests.iml +++ b/plugins/kotlin/gradle/gradle-native/tests/kotlin.gradle.gradle-native.tests.iml @@ -12,6 +12,7 @@ + diff --git a/plugins/kotlin/gradle/gradle-native/tests/test/org/jetbrains/kotlin/ide/konan/gradle/GradleNativeLibrariesInIDENamingTest.kt b/plugins/kotlin/gradle/gradle-native/tests/test/org/jetbrains/kotlin/ide/konan/gradle/GradleNativeLibrariesInIDENamingTest.kt index bc3d9c221853..a74d4ee1dc64 100644 --- a/plugins/kotlin/gradle/gradle-native/tests/test/org/jetbrains/kotlin/ide/konan/gradle/GradleNativeLibrariesInIDENamingTest.kt +++ b/plugins/kotlin/gradle/gradle-native/tests/test/org/jetbrains/kotlin/ide/konan/gradle/GradleNativeLibrariesInIDENamingTest.kt @@ -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()) { diff --git a/plugins/kotlin/idea/kotlin.idea.iml b/plugins/kotlin/idea/kotlin.idea.iml index a275fa97e0e9..a9058d48038d 100644 --- a/plugins/kotlin/idea/kotlin.idea.iml +++ b/plugins/kotlin/idea/kotlin.idea.iml @@ -35,6 +35,9 @@ + + + diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/PluginStartupApplicationService.java b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/PluginStartupApplicationService.java deleted file mode 100644 index 0ab1b5cc4fda..000000000000 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/PluginStartupApplicationService.java +++ /dev/null @@ -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() { - - } -} diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/actions/generate/utils.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/actions/generate/utils.kt index 59c036616954..be6515d10387 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/actions/generate/utils.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/actions/generate/utils.kt @@ -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, diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/actions/internal/refactoringTesting/MoveRefactoringActionDialog.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/actions/internal/refactoringTesting/MoveRefactoringActionDialog.kt index 8ffe48ad01b0..200d131b3b32 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/actions/internal/refactoringTesting/MoveRefactoringActionDialog.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/actions/internal/refactoringTesting/MoveRefactoringActionDialog.kt @@ -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 diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/ClearBuildStateExtension.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/ClearBuildStateExtension.kt deleted file mode 100644 index 81b951bde161..000000000000 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/ClearBuildStateExtension.kt +++ /dev/null @@ -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 { - return EP_NAME.getExtensions() - } - - val EP_NAME: ExtensionPointName = - ExtensionPointName.create("org.jetbrains.kotlin.clearBuildState") - } - - abstract fun clearState(project: Project) -} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index 9a941698313c..70acf54cfe16 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -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("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 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 - get() = when (this) { - is K2JVMCompilerArguments -> jvmPrimaryFields - is K2JSCompilerArguments -> jsPrimaryFields - is K2MetadataCompilerArguments -> metadataPrimaryFields - else -> commonPrimaryFields - } - -private val CommonCompilerArguments.ignoredFields: List - 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, compilerArguments: CommonCompilerArguments): List = - args + defaultSubstitutors[compilerArguments::class]?.filter { it.isSubstitutable(args) }?.flatMap { it.oldSubstitution }.orEmpty() - -fun parseCompilerArgumentsToFacet( - arguments: List, - defaultArguments: List, - 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) = - 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?, new: Array?): Array? { - if (old == null && new == null) { - return old - } else if (new == null) { - return old - } else if (old == null) { - return new - } - - return (old + new).distinct().toTypedArray() -} diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/platform/IdePlatformKindTooling.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/platform/IdePlatformKindTooling.kt index be30c497bf03..a7551b55e05b 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/platform/IdePlatformKindTooling.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/platform/IdePlatformKindTooling.kt @@ -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 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, diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeModuleExperimentalFix.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeModuleExperimentalFix.kt index 3e2f6b0af493..8d26cc8d1afa 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeModuleExperimentalFix.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeModuleExperimentalFix.kt @@ -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 diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeOverriddenMemberOpenFix.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeOverriddenMemberOpenFix.kt index 5e3ea103b081..f9d8815428cc 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeOverriddenMemberOpenFix.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeOverriddenMemberOpenFix.kt @@ -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) } diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePartsFromPropertyFix.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePartsFromPropertyFix.kt index 9b776406e8ba..1f57c8a79b73 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePartsFromPropertyFix.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePartsFromPropertyFix.kt @@ -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 -> "" diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractSuperDialogBase.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractSuperDialogBase.kt index 017eab5ee080..5cd91429f234 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractSuperDialogBase.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractSuperDialogBase.kt @@ -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 diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/KotlinAwareMoveFilesOrDirectoriesDialog.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/KotlinAwareMoveFilesOrDirectoriesDialog.kt index 5abd0136878b..691fe5187240 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/KotlinAwareMoveFilesOrDirectoriesDialog.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/KotlinAwareMoveFilesOrDirectoriesDialog.kt @@ -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 diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/roots/KotlinNonJvmSourceRootConverterProvider.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/roots/KotlinNonJvmSourceRootConverterProvider.kt index 52d040fc06c6..227d33310e59 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/roots/KotlinNonJvmSourceRootConverterProvider.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/roots/KotlinNonJvmSourceRootConverterProvider.kt @@ -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 -> - JsLibraryStdDetectionUtil.getJsStdLibJar(roots.toList()) != null + JsStdlibDetectionUtil.getJavaScriptStdLibJar(roots.toList()) != null }, CommonPlatforms.defaultCommonPlatform to { roots: Array -> - getLibraryJar(roots, PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN) != null + roots.any { PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN.matcher(it.name).matches() } } ) diff --git a/plugins/kotlin/idea/tests/kotlin.idea.tests.iml b/plugins/kotlin/idea/tests/kotlin.idea.tests.iml index ec064b68ea41..49871db57ae1 100644 --- a/plugins/kotlin/idea/tests/kotlin.idea.tests.iml +++ b/plugins/kotlin/idea/tests/kotlin.idea.tests.iml @@ -28,6 +28,8 @@ + + diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfoTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfoTest.kt index 3922e9baced7..4ecc8a06cda5 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfoTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfoTest.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.Disposable import com.intellij.openapi.application.impl.NonBlockingReadActionImpl import com.intellij.openapi.module.Module import com.intellij.openapi.module.StdModuleTypes +import com.intellij.openapi.projectRoots.ProjectJdkTable import com.intellij.openapi.roots.DependencyScope import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootModificationUtil @@ -21,21 +22,21 @@ import com.intellij.util.ThrowableRunnable import com.intellij.util.ui.UIUtil import org.jetbrains.kotlin.idea.artifacts.AdditionalKotlinArtifacts import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts +import org.jetbrains.kotlin.idea.base.platforms.KotlinCommonLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.platform import org.jetbrains.kotlin.idea.caches.project.* import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo import org.jetbrains.kotlin.idea.caches.project.ModuleTestSourceInfo -import org.jetbrains.kotlin.idea.framework.CommonLibraryKind -import org.jetbrains.kotlin.idea.framework.JSLibraryKind -import org.jetbrains.kotlin.idea.framework.platform import org.jetbrains.kotlin.idea.stubs.createMultiplatformFacetM3 import org.jetbrains.kotlin.idea.test.PluginTestCaseBase.addJdk import org.jetbrains.kotlin.idea.test.runAll import org.jetbrains.kotlin.idea.util.application.runWriteAction -import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.js.JsPlatforms import org.jetbrains.kotlin.idea.test.KotlinTestUtils.allowProjectRootAccess import org.jetbrains.kotlin.idea.test.KotlinTestUtils.disposeVfsRootAccess +import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.platform.konan.NativePlatforms @@ -369,15 +370,16 @@ class IdeaModuleInfoTest8 : JavaModuleTestCase() { ProjectRootManager.getInstance(project).projectSdk = null } - val firstSDK = getProjectJdkTableSafe().allJdks.firstOrNull() ?: error("no jdks are present") + val allJdks = runReadAction { ProjectJdkTable.getInstance() }.allJdks + val firstJdk = allJdks.firstOrNull() ?: error("no jdks are present") with(createFileInProject("script.kts").moduleInfo) { UIUtil.dispatchAllInvocationEvents() NonBlockingReadActionImpl.waitForAsyncTaskCompletion() val filterIsInstance = dependencies().filterIsInstance() - filterIsInstance.singleOrNull { it.sdk == firstSDK } - ?: error("Unable to look up ${firstSDK.name} in ${filterIsInstance.map { it.name }} / allJdks: ${getProjectJdkTableSafe().allJdks}") + filterIsInstance.singleOrNull { it.sdk == firstJdk } + ?: error("Unable to look up ${firstJdk.name} in ${filterIsInstance.map { it.name }} / allJdks: $allJdks") } } @@ -781,7 +783,7 @@ class IdeaModuleInfoTest8 : JavaModuleTestCase() { private fun stdlibCommon(): LibraryEx = projectLibrary( "kotlin-stdlib-common", AdditionalKotlinArtifacts.kotlinStdlibCommon.jarRoot, - kind = CommonLibraryKind + kind = KotlinCommonLibraryKind ) private fun stdlibJvm(): LibraryEx = projectLibrary("kotlin-stdlib", KotlinArtifacts.instance.kotlinStdlib.jarRoot) @@ -789,7 +791,7 @@ class IdeaModuleInfoTest8 : JavaModuleTestCase() { private fun stdlibJs(): LibraryEx = projectLibrary( "kotlin-stdlib-js", KotlinArtifacts.instance.kotlinStdlibJs.jarRoot, - kind = JSLibraryKind + kind = KotlinJavaScriptLibraryKind ) private fun projectLibraryWithFakeRoot(name: String): LibraryEx { diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/AutoConfigureKotlinSdkOnStartupTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/AutoConfigureKotlinSdkOnStartupTest.kt index 237a44e747e8..0aefb1618bc8 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/AutoConfigureKotlinSdkOnStartupTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/AutoConfigureKotlinSdkOnStartupTest.kt @@ -2,8 +2,9 @@ package org.jetbrains.kotlin.idea.configuration +import com.intellij.openapi.projectRoots.ProjectJdkTable import org.jetbrains.kotlin.idea.framework.KotlinSdkType -import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe +import org.jetbrains.kotlin.idea.util.application.runReadAction import org.junit.Assert import org.junit.internal.runners.JUnit38ClassRunner import org.junit.runner.RunWith @@ -12,6 +13,6 @@ import org.junit.runner.RunWith @RunWith(JUnit38ClassRunner::class) class AutoConfigureKotlinSdkOnStartupTest : AbstractConfigureKotlinInTempDirTest() { fun testKotlinSdkAdded() { - Assert.assertTrue(getProjectJdkTableSafe().allJdks.any { it.sdkType is KotlinSdkType }) + Assert.assertTrue(runReadAction { ProjectJdkTable.getInstance() }.allJdks.any { it.sdkType is KotlinSdkType }) } } \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java index b42da4001d5a..574a3e840bdb 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java @@ -8,7 +8,6 @@ import com.intellij.openapi.externalSystem.service.project.ProjectDataManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.*; import com.intellij.openapi.roots.impl.libraries.LibraryEx; @@ -26,14 +25,14 @@ import org.jetbrains.kotlin.config.JvmTarget; import org.jetbrains.kotlin.config.KotlinFacetSettings; import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider; import org.jetbrains.kotlin.config.LanguageVersion; +import org.jetbrains.kotlin.idea.base.platforms.JsStdlibDetectionUtil; +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind; +import org.jetbrains.kotlin.idea.base.platforms.LibraryEffectiveKindProvider; import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion; import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder; import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayout; import org.jetbrains.kotlin.idea.facet.FacetUtilsKt; import org.jetbrains.kotlin.idea.facet.KotlinFacet; -import org.jetbrains.kotlin.idea.framework.JSLibraryKind; -import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil; -import org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderKt; import org.jetbrains.kotlin.idea.macros.KotlinBundledUsageDetector; import org.jetbrains.kotlin.idea.project.PlatformKt; import org.jetbrains.kotlin.idea.util.Java9StructureUtilKt; @@ -158,13 +157,13 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest { public void testJsLibraryVersion11() { Library jsRuntime = getFirstLibrary(myProject); - IdeKotlinVersion version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime, myProject); + IdeKotlinVersion version = JsStdlibDetectionUtil.INSTANCE.getJavaScriptLibraryStdVersion(jsRuntime, myProject); assertEquals(new KotlinVersion(1, 1, 0), version.getKotlinVersion()); } public void testJsLibraryVersion106() { Library jsRuntime = getFirstLibrary(myProject); - IdeKotlinVersion version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime, myProject); + IdeKotlinVersion version = JsStdlibDetectionUtil.INSTANCE.getJavaScriptLibraryStdVersion(jsRuntime, myProject); assertEquals(new KotlinVersion(1, 0, 6), version.getKotlinVersion()); } @@ -177,8 +176,11 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest { } return true; }); + + LibraryEffectiveKindProvider effectiveKindProvider = LibraryEffectiveKindProvider.getInstance(myProject); + assertEquals(RepositoryLibraryType.REPOSITORY_LIBRARY_KIND, jsTest.get().getKind()); - assertEquals(JSLibraryKind.INSTANCE, LibraryEffectiveKindProviderKt.effectiveKind(jsTest.get(), myProject)); + assertEquals(KotlinJavaScriptLibraryKind.INSTANCE, effectiveKindProvider.getEffectiveKind(jsTest.get())); } public void testJvmProjectWithV1FacetConfig() { diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/multiplatform/multiPlatformSetup.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/multiplatform/multiPlatformSetup.kt index 198096e26228..958b0c7913f0 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/multiplatform/multiPlatformSetup.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/multiplatform/multiPlatformSetup.kt @@ -4,15 +4,14 @@ package org.jetbrains.kotlin.idea.multiplatform import com.intellij.openapi.module.Module import com.intellij.openapi.module.StdModuleTypes -import com.intellij.openapi.roots.CompilerModuleExtension -import com.intellij.openapi.roots.ModuleRootModificationUtil +import com.intellij.openapi.projectRoots.ProjectJdkTable import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.LocalFileSystem import org.jetbrains.kotlin.checkers.utils.clearFileFromDiagnosticMarkup import org.jetbrains.kotlin.idea.artifacts.AdditionalKotlinArtifacts import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts -import org.jetbrains.kotlin.idea.framework.CommonLibraryKind -import org.jetbrains.kotlin.idea.framework.JSLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.KotlinCommonLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind import org.jetbrains.kotlin.idea.framework.KotlinSdkType import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest import org.jetbrains.kotlin.idea.stubs.createMultiplatformFacetM1 @@ -20,7 +19,6 @@ import org.jetbrains.kotlin.idea.stubs.createMultiplatformFacetM3 import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.util.application.executeWriteCommand -import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe import org.jetbrains.kotlin.idea.util.sourceRoots import org.jetbrains.kotlin.platform.CommonPlatforms import org.jetbrains.kotlin.platform.TargetPlatform @@ -33,6 +31,7 @@ import org.jetbrains.kotlin.platform.konan.NativePlatforms import org.jetbrains.kotlin.platform.konan.isNative import org.jetbrains.kotlin.projectModel.* import org.jetbrains.kotlin.idea.test.KotlinTestUtils +import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.test.TestJdkKind import org.jetbrains.kotlin.types.typeUtil.closure import java.io.File @@ -139,7 +138,8 @@ private fun AbstractMultiModuleTest.setUpSdkForModule(ideaModule: Module, sdk: R KotlinSdkType.setUpIfNeeded(testRootDisposable) ConfigLibraryUtil.configureSdk( ideaModule, - getProjectJdkTableSafe().findMostRecentSdkOfType(KotlinSdkType.INSTANCE) ?: error("Kotlin SDK wasn't created") + runReadAction { ProjectJdkTable.getInstance() }.findMostRecentSdkOfType(KotlinSdkType.INSTANCE) + ?: error("Kotlin SDK wasn't created") ) } @@ -163,9 +163,9 @@ private fun AbstractMultiModuleTest.doSetupProject(rootInfos: List) { is ModuleDependency -> module.addDependency(modulesById[it.moduleId]!!) is StdlibDependency -> { when { - platform.isCommon() -> module.addLibrary(AdditionalKotlinArtifacts.kotlinStdlibCommon, kind = CommonLibraryKind) + platform.isCommon() -> module.addLibrary(AdditionalKotlinArtifacts.kotlinStdlibCommon, kind = KotlinCommonLibraryKind) platform.isJvm() -> module.addLibrary(KotlinArtifacts.instance.kotlinStdlib) - platform.isJs() -> module.addLibrary(KotlinArtifacts.instance.kotlinStdlibJs, kind = JSLibraryKind) + platform.isJs() -> module.addLibrary(KotlinArtifacts.instance.kotlinStdlibJs, kind = KotlinJavaScriptLibraryKind) else -> error("Unknown platform $this") } } @@ -177,7 +177,7 @@ private fun AbstractMultiModuleTest.doSetupProject(rootInfos: List) { is CoroutinesDependency -> module.enableCoroutines() is KotlinTestDependency -> when { platform.isJvm() -> module.addLibrary(KotlinArtifacts.instance.kotlinTestJunit) - platform.isJs() -> module.addLibrary(KotlinArtifacts.instance.kotlinTestJs, kind = JSLibraryKind) + platform.isJs() -> module.addLibrary(KotlinArtifacts.instance.kotlinTestJs, kind = KotlinJavaScriptLibraryKind) } } } diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/script/ScriptTemplatesFromDependenciesProviderTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/script/ScriptTemplatesFromDependenciesProviderTest.kt index 2c7d966ca60d..cc3cf8bee9ba 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/script/ScriptTemplatesFromDependenciesProviderTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/script/ScriptTemplatesFromDependenciesProviderTest.kt @@ -6,8 +6,8 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.TestDataPath import com.intellij.util.ThrowableRunnable +import org.jetbrains.kotlin.base.util.invalidateProjectRoots import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManager -import org.jetbrains.kotlin.idea.roots.invalidateProjectRoots import org.jetbrains.kotlin.idea.test.runAll import org.jetbrains.kotlin.scripting.definitions.SCRIPT_DEFINITION_MARKERS_EXTENSION_WITH_DOT import org.jetbrains.kotlin.scripting.definitions.SCRIPT_DEFINITION_MARKERS_PATH diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/projectModel/Model.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/projectModel/Model.kt index 65f5a2017542..151cfcc596ca 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/projectModel/Model.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/projectModel/Model.kt @@ -6,8 +6,8 @@ import com.intellij.openapi.application.PathManager import com.intellij.openapi.roots.libraries.PersistentLibraryKind import org.jetbrains.kotlin.idea.artifacts.AdditionalKotlinArtifacts import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts -import org.jetbrains.kotlin.idea.framework.CommonLibraryKind -import org.jetbrains.kotlin.idea.framework.JSLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.KotlinCommonLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind import org.jetbrains.kotlin.idea.test.IDEA_TEST_DATA_DIR import org.jetbrains.kotlin.platform.CommonPlatforms import org.jetbrains.kotlin.platform.TargetPlatform @@ -116,7 +116,7 @@ sealed class Stdlib( "stdlib-common", AdditionalKotlinArtifacts.kotlinStdlibCommon, CommonPlatforms.defaultCommonPlatform, - CommonLibraryKind + KotlinCommonLibraryKind ) object JvmStdlib : Stdlib( @@ -130,7 +130,7 @@ sealed class Stdlib( "stdlib-js", KotlinArtifacts.instance.kotlinStdlibJs, JsPlatforms.defaultJsPlatform, - JSLibraryKind + KotlinJavaScriptLibraryKind ) } @@ -145,7 +145,7 @@ sealed class KotlinTest( "kotlin-test-js", KotlinArtifacts.instance.kotlinTestJs, JsPlatforms.defaultJsPlatform, - JSLibraryKind + KotlinJavaScriptLibraryKind ) object JvmKotlinTest : KotlinTest( diff --git a/plugins/kotlin/intellij.kotlin.plugin.community.main.iml b/plugins/kotlin/intellij.kotlin.plugin.community.main.iml index 8ce37a50641e..871c1ef26770 100644 --- a/plugins/kotlin/intellij.kotlin.plugin.community.main.iml +++ b/plugins/kotlin/intellij.kotlin.plugin.community.main.iml @@ -10,6 +10,10 @@ + + + + diff --git a/plugins/kotlin/jvm/kotlin.jvm.iml b/plugins/kotlin/jvm/kotlin.jvm.iml index c0d4b4854e6f..1a39840d7d32 100644 --- a/plugins/kotlin/jvm/kotlin.jvm.iml +++ b/plugins/kotlin/jvm/kotlin.jvm.iml @@ -17,7 +17,10 @@ + + + diff --git a/plugins/kotlin/jvm/resources/META-INF/jvm-common.xml b/plugins/kotlin/jvm/resources/META-INF/jvm-common.xml index f7b6a1d95716..b079f352690d 100644 --- a/plugins/kotlin/jvm/resources/META-INF/jvm-common.xml +++ b/plugins/kotlin/jvm/resources/META-INF/jvm-common.xml @@ -222,7 +222,6 @@ - diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/ClearBuildManagerState.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/ClearBuildManagerState.kt deleted file mode 100644 index b5c0446763b7..000000000000 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/ClearBuildManagerState.kt +++ /dev/null @@ -1,12 +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.compiler.server.BuildManager -import com.intellij.openapi.project.Project - -class ClearBuildManagerState : ClearBuildStateExtension() { - override fun clearState(project: Project) { - BuildManager.getInstance().clearState(project) - } -} \ No newline at end of file diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinBuildProcessParametersProvider.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinBuildProcessParametersProvider.kt index bfbf262db587..6033164991bd 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinBuildProcessParametersProvider.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinBuildProcessParametersProvider.kt @@ -9,7 +9,6 @@ import com.intellij.openapi.util.registry.Registry import com.intellij.util.io.isDirectory import org.jetbrains.kotlin.config.IncrementalCompilation import org.jetbrains.kotlin.idea.PluginStartupApplicationService -import org.jetbrains.kotlin.idea.jps.SetupKotlinJpsPluginBeforeCompileTask import java.nio.file.Path class KotlinBuildProcessParametersProvider(private val project: Project) : BuildProcessParametersProvider() { @@ -29,7 +28,7 @@ class KotlinBuildProcessParametersProvider(private val project: Project) : Build if (Registry.`is`("kotlin.jps.instrument.bytecode", false)) { res.add("-Dkotlin.jps.instrument.bytecode=true") } - PluginStartupApplicationService.getInstance().aliveFlagPath.let { + PluginStartupApplicationService.getInstance().getAliveFlagPath().let { if (!it.isBlank()) { // TODO: consider taking the property name from compiler/daemon/common (check whether dependency will be not too heavy) res.add("-Dkotlin.daemon.client.alive.path=\"$it\"") diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt index 37a07c48ba42..54cd144a060a 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt @@ -28,11 +28,11 @@ import com.intellij.util.indexing.DumbModeAccessType import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.KotlinJvmBundle +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.LibraryEffectiveKindProvider import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion import org.jetbrains.kotlin.idea.core.util.getKotlinJvmRuntimeMarkerClass import org.jetbrains.kotlin.idea.extensions.gradle.RepositoryDescription -import org.jetbrains.kotlin.idea.framework.JSLibraryKind -import org.jetbrains.kotlin.idea.framework.effectiveKind import org.jetbrains.kotlin.idea.quickfix.KotlinAddRequiredModuleFix import org.jetbrains.kotlin.idea.search.projectScope import org.jetbrains.kotlin.idea.util.application.isDispatchThread @@ -303,7 +303,7 @@ fun hasAnyKotlinRuntimeInScope(module: Module): Boolean { val scope = module.getModuleWithDependenciesAndLibrariesScope(true) DumbModeAccessType.RELIABLE_DATA_ONLY.ignoreDumbMode(ThrowableComputable { getKotlinJvmRuntimeMarkerClass(module.project, scope) != null || - hasKotlinJsKjsmFile(LibraryKindSearchScope(module, scope, JSLibraryKind)) || + hasKotlinJsKjsmFile(LibraryKindSearchScope(module, scope, KotlinJavaScriptLibraryKind)) || hasKotlinCommonRuntimeInScope(scope) }) } @@ -321,7 +321,7 @@ fun hasKotlinJvmRuntimeInScope(module: Module): Boolean { fun hasKotlinJsRuntimeInScope(module: Module): Boolean { return module.project.syncNonBlockingReadAction { val scope = module.getModuleWithDependenciesAndLibrariesScope(true) - hasKotlinJsKjsmFile(LibraryKindSearchScope(module, scope, JSLibraryKind)) + hasKotlinJsKjsmFile(LibraryKindSearchScope(module, scope, KotlinJavaScriptLibraryKind)) } } @@ -332,13 +332,13 @@ fun hasKotlinCommonRuntimeInScope(scope: GlobalSearchScope): Boolean { class LibraryKindSearchScope( val module: Module, baseScope: GlobalSearchScope, - val libraryKind: PersistentLibraryKind<*> + private val libraryKind: PersistentLibraryKind<*> ) : DelegatingGlobalSearchScope(baseScope) { override fun contains(file: VirtualFile): Boolean { if (!super.contains(file)) return false val orderEntry = ModuleRootManager.getInstance(module).fileIndex.getOrderEntryForFile(file) if (orderEntry is LibraryOrderEntry) { - return (orderEntry.library as LibraryEx).effectiveKind(module.project) == libraryKind + return LibraryEffectiveKindProvider.getInstance(module.project).getEffectiveKind(orderEntry.library as LibraryEx) == libraryKind } return true } diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJavaModuleConfigurator.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJavaModuleConfigurator.kt index a400c0acf2a5..fd70251eed44 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJavaModuleConfigurator.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJavaModuleConfigurator.kt @@ -17,12 +17,12 @@ import org.jetbrains.annotations.Nls import org.jetbrains.idea.maven.utils.library.RepositoryLibraryProperties import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.idea.KotlinJvmBundle +import org.jetbrains.kotlin.idea.base.platforms.JsStdlibDetectionUtil import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder import org.jetbrains.kotlin.idea.facet.getOrCreateFacet import org.jetbrains.kotlin.idea.facet.initializeIfNeeded import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription -import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.idea.util.projectStructure.sdk import org.jetbrains.kotlin.idea.util.projectStructure.version @@ -112,7 +112,7 @@ open class KotlinJavaModuleConfigurator : KotlinWithLibraryConfigurator Boolean = { library, project -> - JsLibraryStdDetectionUtil.hasJsStdlibJar(library, project) + JsStdlibDetectionUtil.hasJavaScriptStdlibJar(library, project) } override val libraryType: LibraryType get() = JSLibraryType.getInstance() @@ -66,7 +66,7 @@ open class KotlinJsModuleConfigurator : KotlinWithLibraryConfigurator(JSLibraryKind) { +class JSLibraryType : LibraryType(KotlinJavaScriptLibraryKind) { override fun createPropertiesEditor(editorComponent: LibraryEditorComponent) = null @Suppress("HardCodedStringLiteral") @@ -74,7 +76,7 @@ private fun isAcceptedForJsLibrary(extension: String?) = extension == "js" || ex // Can't import a member annotated with DEPRECATION_ERROR val org.jetbrains.kotlin.config.TargetPlatformKind<*>.libraryKind: PersistentLibraryKind<*>? get() = when (this) { - org.jetbrains.kotlin.config.TargetPlatformKind.JavaScript -> JSLibraryKind - org.jetbrains.kotlin.config.TargetPlatformKind.Common -> CommonLibraryKind + org.jetbrains.kotlin.config.TargetPlatformKind.JavaScript -> KotlinJavaScriptLibraryKind + org.jetbrains.kotlin.config.TargetPlatformKind.Common -> KotlinCommonLibraryKind else -> null } diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/CommonIdePlatformKindTooling.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/CommonIdePlatformKindTooling.kt index a98b021f9864..f92b5399d61a 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/CommonIdePlatformKindTooling.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/CommonIdePlatformKindTooling.kt @@ -4,14 +4,10 @@ package org.jetbrains.kotlin.idea.core.platform.impl import com.intellij.icons.AllIcons import com.intellij.openapi.project.Project -import com.intellij.openapi.roots.libraries.Library -import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.idea.base.platforms.KotlinCommonLibraryKind import org.jetbrains.kotlin.idea.caches.project.implementingModules -import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion -import org.jetbrains.kotlin.idea.framework.CommonLibraryKind import org.jetbrains.kotlin.idea.framework.CommonStandardLibraryDescription -import org.jetbrains.kotlin.idea.framework.getCommonRuntimeLibraryVersion import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling import org.jetbrains.kotlin.idea.platform.isCompatibleWith import org.jetbrains.kotlin.idea.platform.tooling @@ -31,20 +27,14 @@ object CommonIdePlatformKindTooling : IdePlatformKindTooling() { override val kind = CommonIdePlatformKind - override fun compilerArgumentsForProject(project: Project): CommonCompilerArguments? = null - override val mavenLibraryIds = listOf(MAVEN_COMMON_STDLIB_ID) override val gradlePluginId = "kotlin-platform-common" override val gradlePlatformIds: List get() = listOf(KotlinPlatform.COMMON) - override val libraryKind = CommonLibraryKind + override val libraryKind = KotlinCommonLibraryKind override fun getLibraryDescription(project: Project) = CommonStandardLibraryDescription(project) - override fun getLibraryVersionProvider(project: Project): (Library) -> IdeKotlinVersion? { - return ::getCommonRuntimeLibraryVersion - } - private fun getRelevantToolings(platform: TargetPlatform?): List { return getInstances() .filter { it != this } diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/JsIdePlatformKindTooling.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/JsIdePlatformKindTooling.kt index 6bb25502c160..cef747675e0c 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/JsIdePlatformKindTooling.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/JsIdePlatformKindTooling.kt @@ -10,10 +10,9 @@ import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.util.io.FileUtil import com.intellij.util.SmartList import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder -import org.jetbrains.kotlin.idea.framework.JSLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.JsStdlibDetectionUtil +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind import org.jetbrains.kotlin.idea.framework.JSLibraryStdDescription -import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil import org.jetbrains.kotlin.idea.js.KotlinJSRunConfigurationData import org.jetbrains.kotlin.idea.js.KotlinJSRunConfigurationDataProvider import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling @@ -34,19 +33,13 @@ class JsIdePlatformKindTooling : IdePlatformKindTooling() { override val kind = JsIdePlatformKind - override fun compilerArgumentsForProject(project: Project) = Kotlin2JsCompilerArgumentsHolder.getInstance(project).settings - override val mavenLibraryIds = listOf(PathUtil.JS_LIB_NAME, MAVEN_OLD_JS_STDLIB_ID) override val gradlePluginId = "kotlin-platform-js" override val gradlePlatformIds: List get() = listOf(KotlinPlatform.JS) - override val libraryKind = JSLibraryKind + override val libraryKind = KotlinJavaScriptLibraryKind override fun getLibraryDescription(project: Project) = JSLibraryStdDescription(project) - override fun getLibraryVersionProvider(project: Project) = { library: Library -> - JsLibraryStdDetectionUtil.getJsLibraryStdVersion(library, project) - } - override fun getTestIcon( declaration: KtNamedDeclaration, descriptorProvider: () -> DeclarationDescriptor?, diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/JvmIdePlatformKindTooling.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/JvmIdePlatformKindTooling.kt index 50f6007cb25d..b043a62d8d47 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/JvmIdePlatformKindTooling.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/platform/JvmIdePlatformKindTooling.kt @@ -3,28 +3,25 @@ package org.jetbrains.kotlin.idea.core.platform.impl import com.intellij.openapi.project.Project -import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.PersistentLibraryKind import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion -import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder -import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription import org.jetbrains.kotlin.idea.highlighter.KotlinTestRunLineMarkerContributor.Companion.getTestStateIcon import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling import org.jetbrains.kotlin.idea.platform.getGenericTestIcon import org.jetbrains.kotlin.idea.projectModel.KotlinPlatform -import org.jetbrains.kotlin.idea.testIntegration.framework.* +import org.jetbrains.kotlin.idea.testIntegration.framework.KotlinTestFramework import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind -import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtFunction +import org.jetbrains.kotlin.psi.KtNamedDeclaration +import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.utils.PathUtil import javax.swing.Icon class JvmIdePlatformKindTooling : IdePlatformKindTooling() { override val kind = JvmIdePlatformKind - override fun compilerArgumentsForProject(project: Project) = Kotlin2JvmCompilerArgumentsHolder.getInstance(project).settings - override val mavenLibraryIds = listOf( PathUtil.KOTLIN_JAVA_STDLIB_NAME, PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME, @@ -39,10 +36,6 @@ class JvmIdePlatformKindTooling : IdePlatformKindTooling() { override val libraryKind: PersistentLibraryKind<*>? = null override fun getLibraryDescription(project: Project) = JavaRuntimeLibraryDescription(project) - override fun getLibraryVersionProvider(project: Project): (Library) -> IdeKotlinVersion? { - return JavaRuntimeDetectionUtil::getJavaRuntimeVersion - } - private fun calculateUrls(declaration: KtNamedDeclaration, includeSlowProviders: Boolean? = null): List? { val testFramework = KotlinTestFramework.getApplicableFor(declaration, includeSlowProviders?.takeUnless { it } ) ?: return null diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/quickfix/ChangeGeneralLanguageFeatureSupportFix.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/quickfix/ChangeGeneralLanguageFeatureSupportFix.kt index 570f9c51ef59..2ec5afab16c6 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/quickfix/ChangeGeneralLanguageFeatureSupportFix.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/quickfix/ChangeGeneralLanguageFeatureSupportFix.kt @@ -10,6 +10,7 @@ import com.intellij.openapi.project.RootsChangeRescanningInfo import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.util.NlsContexts import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.base.util.invalidateProjectRoots import org.jetbrains.kotlin.cli.common.arguments.CliArgumentStringBuilder.replaceLanguageFeature import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.diagnostics.Diagnostic @@ -18,7 +19,6 @@ import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings import org.jetbrains.kotlin.idea.configuration.findApplicableConfigurator import org.jetbrains.kotlin.idea.core.isInTestSourceContentKotlinAware import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion -import org.jetbrains.kotlin.idea.roots.invalidateProjectRoots import org.jetbrains.kotlin.idea.util.module import org.jetbrains.kotlin.psi.KtFile diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/quickfix/EnableUnsupportedFeatureFix.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/quickfix/EnableUnsupportedFeatureFix.kt index b3db077eac57..cd9f5428a3f1 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/quickfix/EnableUnsupportedFeatureFix.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/quickfix/EnableUnsupportedFeatureFix.kt @@ -17,6 +17,7 @@ import com.intellij.psi.PsiElement import org.eclipse.aether.version.Version import org.jetbrains.idea.maven.aether.ArtifactKind import org.jetbrains.idea.maven.aether.ArtifactRepositoryManager +import org.jetbrains.kotlin.base.util.invalidateProjectRoots import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.LanguageFeature @@ -31,7 +32,6 @@ import org.jetbrains.kotlin.idea.configuration.getBuildSystemType import org.jetbrains.kotlin.idea.core.isInTestSourceContentKotlinAware import org.jetbrains.kotlin.idea.facet.KotlinFacet import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion -import org.jetbrains.kotlin.idea.roots.invalidateProjectRoots import org.jetbrains.kotlin.idea.util.application.isApplicationInternalMode import org.jetbrains.kotlin.idea.util.application.isUnitTestMode import org.jetbrains.kotlin.idea.util.projectStructure.allModules diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/run/multiplatform/KotlinMultiplatformRunLocationsProvider.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/run/multiplatform/KotlinMultiplatformRunLocationsProvider.kt index 824d7a73fef4..0804dc8a74e0 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/run/multiplatform/KotlinMultiplatformRunLocationsProvider.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/run/multiplatform/KotlinMultiplatformRunLocationsProvider.kt @@ -8,6 +8,7 @@ import com.intellij.execution.actions.MultipleRunLocationsProvider import com.intellij.openapi.module.Module import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.util.NlsSafe +import org.jetbrains.kotlin.base.util.isAndroidModule import org.jetbrains.kotlin.config.KotlinModuleKind import org.jetbrains.kotlin.idea.caches.project.SourceType import org.jetbrains.kotlin.idea.caches.project.implementingModules @@ -15,7 +16,6 @@ import org.jetbrains.kotlin.idea.caches.project.isNewMPPModule import org.jetbrains.kotlin.idea.caches.project.sourceType import org.jetbrains.kotlin.idea.configuration.toModuleGroup import org.jetbrains.kotlin.idea.core.getSourceType -import org.jetbrains.kotlin.idea.core.isAndroidModule import org.jetbrains.kotlin.idea.facet.KotlinFacet class KotlinMultiplatformRunLocationsProvider : MultipleRunLocationsProvider() { diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeChecker.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeChecker.kt index fd5134dad427..ea5d74416db1 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeChecker.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeChecker.kt @@ -9,8 +9,8 @@ import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.roots.libraries.Library import com.intellij.util.text.VersionComparatorUtil +import org.jetbrains.kotlin.idea.base.platforms.JsStdlibDetectionUtil import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil -import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil fun findKotlinRuntimeLibrary(module: Module, predicate: (Library, Project) -> Boolean = ::isKotlinRuntime): Library? { val orderEntries = ModuleRootManager.getInstance(module).orderEntries.filterIsInstance() @@ -25,7 +25,7 @@ private fun isKotlinJavaRuntime(library: Library) = JavaRuntimeDetectionUtil.getRuntimeJar(library.getFiles(OrderRootType.CLASSES).asList()) != null private fun isKotlinJsRuntime(library: Library, project: Project) = - JsLibraryStdDetectionUtil.hasJsStdlibJar(library, project) + JsStdlibDetectionUtil.hasJavaScriptStdlibJar(library, project) fun isRuntimeOutdated(libraryVersion: String?, runtimeVersion: String): Boolean { return libraryVersion == null || libraryVersion.startsWith("internal-") != runtimeVersion.startsWith("internal-") || diff --git a/plugins/kotlin/kotlin.all-tests/kotlin.all-tests.iml b/plugins/kotlin/kotlin.all-tests/kotlin.all-tests.iml index 47c82e5d6064..25f9536a5f1e 100644 --- a/plugins/kotlin/kotlin.all-tests/kotlin.all-tests.iml +++ b/plugins/kotlin/kotlin.all-tests/kotlin.all-tests.iml @@ -11,6 +11,10 @@ + + + + diff --git a/plugins/kotlin/maven/kotlin.maven.iml b/plugins/kotlin/maven/kotlin.maven.iml index fd92c14ef6b2..2f0c8b55d0d5 100644 --- a/plugins/kotlin/maven/kotlin.maven.iml +++ b/plugins/kotlin/maven/kotlin.maven.iml @@ -17,6 +17,8 @@ + + diff --git a/plugins/kotlin/maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt b/plugins/kotlin/maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt index f827dee4df96..983722fdda78 100644 --- a/plugins/kotlin/maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt +++ b/plugins/kotlin/maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt @@ -35,12 +35,12 @@ import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor +import org.jetbrains.kotlin.idea.base.platforms.detectLibraryKind import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion import org.jetbrains.kotlin.idea.compiler.configuration.KotlinJpsPluginSettings import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayout import org.jetbrains.kotlin.idea.facet.* import org.jetbrains.kotlin.idea.framework.KotlinSdkType -import org.jetbrains.kotlin.idea.framework.detectLibraryKind import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator import org.jetbrains.kotlin.idea.platform.tooling import org.jetbrains.kotlin.platform.IdePlatformKind diff --git a/plugins/kotlin/maven/tests/kotlin.maven.tests.iml b/plugins/kotlin/maven/tests/kotlin.maven.tests.iml index 791e6adc6b05..553ed12a5074 100644 --- a/plugins/kotlin/maven/tests/kotlin.maven.tests.iml +++ b/plugins/kotlin/maven/tests/kotlin.maven.tests.iml @@ -16,6 +16,8 @@ + + diff --git a/plugins/kotlin/maven/tests/test/org/jetbrains/kotlin/idea/maven/AbstractKotlinMavenImporterTest.kt b/plugins/kotlin/maven/tests/test/org/jetbrains/kotlin/idea/maven/AbstractKotlinMavenImporterTest.kt index ce18dc45e1e0..4181eeef2668 100644 --- a/plugins/kotlin/maven/tests/test/org/jetbrains/kotlin/idea/maven/AbstractKotlinMavenImporterTest.kt +++ b/plugins/kotlin/maven/tests/test/org/jetbrains/kotlin/idea/maven/AbstractKotlinMavenImporterTest.kt @@ -24,6 +24,8 @@ import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.config.additionalArgumentsAsList import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts +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.caches.resolve.analyzeAndGetResult @@ -34,8 +36,6 @@ import org.jetbrains.kotlin.idea.facet.KotlinFacet import org.jetbrains.kotlin.idea.formatter.KotlinObsoleteCodeStyle import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle import org.jetbrains.kotlin.idea.formatter.kotlinCodeStyleDefaults -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.macros.KOTLIN_BUNDLED import org.jetbrains.kotlin.idea.notification.asText @@ -825,7 +825,7 @@ abstract class AbstractKotlinMavenImporterTest : KotlinMavenImportingTestCase() val rootManager = ModuleRootManager.getInstance(getModule("project")) val stdlib = rootManager.orderEntries.filterIsInstance().single().library - assertEquals(JSLibraryKind, (stdlib as LibraryEx).kind) + assertEquals(KotlinJavaScriptLibraryKind, (stdlib as LibraryEx).kind) Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType) @@ -1394,8 +1394,8 @@ abstract class AbstractKotlinMavenImporterTest : KotlinMavenImportingTestCase() val rootManager = ModuleRootManager.getInstance(getModule("project")) val libraries = rootManager.orderEntries.filterIsInstance().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) assertKotlinSources("project", "src/main/kotlin") assertKotlinTestSources("project", "src/test/java") @@ -1505,7 +1505,7 @@ abstract class AbstractKotlinMavenImporterTest : KotlinMavenImportingTestCase() val rootManager = ModuleRootManager.getInstance(getModule("project")) val stdlib = rootManager.orderEntries.filterIsInstance().single().library - assertEquals(CommonLibraryKind, (stdlib as LibraryEx).kind) + assertEquals(KotlinCommonLibraryKind, (stdlib as LibraryEx).kind) Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType) diff --git a/plugins/kotlin/native/kotlin.native.iml b/plugins/kotlin/native/kotlin.native.iml index 6c7d4d96b7c1..ad38dd279b03 100644 --- a/plugins/kotlin/native/kotlin.native.iml +++ b/plugins/kotlin/native/kotlin.native.iml @@ -15,6 +15,7 @@ + diff --git a/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeModuleConfigurator.kt b/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeModuleConfigurator.kt index 284460fe54f6..b123c411a660 100644 --- a/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeModuleConfigurator.kt +++ b/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeModuleConfigurator.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.ide.konan import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project import com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.kotlin.idea.base.platforms.KotlinNativeLibraryKind import org.jetbrains.kotlin.idea.configuration.LibraryKindSearchScope import org.jetbrains.kotlin.idea.util.runReadActionInSmartMode import org.jetbrains.kotlin.idea.vfilefinder.KlibMetaFileIndex @@ -13,7 +14,7 @@ import org.jetbrains.kotlin.name.FqName fun hasKotlinNativeRuntimeInScope(module: Module): Boolean = module.project.runReadActionInSmartMode { val scope = module.getModuleWithDependenciesAndLibrariesScope(true) - hasKotlinNativeMetadataFile(module.project, LibraryKindSearchScope(module, scope, NativeLibraryKind)) + hasKotlinNativeMetadataFile(module.project, LibraryKindSearchScope(module, scope, KotlinNativeLibraryKind)) } private val KOTLIN_NATIVE_FQ_NAME = FqName("kotlin.native") diff --git a/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativeIdePlatformKindTooling.kt b/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativeIdePlatformKindTooling.kt index 57fffd0b3959..4d8418d8d359 100644 --- a/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativeIdePlatformKindTooling.kt +++ b/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativeIdePlatformKindTooling.kt @@ -4,28 +4,22 @@ package org.jetbrains.kotlin.ide.konan import com.intellij.execution.actions.RunConfigurationProducer import com.intellij.openapi.project.Project -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.roots.ui.configuration.libraries.CustomLibraryDescription import org.jetbrains.kotlin.asJava.classes.KtLightClass import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.asJava.toLightMethods -import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.idea.base.platforms.KotlinNativeLibraryKind import org.jetbrains.kotlin.idea.caches.project.isTestModule -import org.jetbrains.kotlin.idea.compiler.configuration.IdeKotlinVersion import org.jetbrains.kotlin.idea.facet.externalSystemNativeMainRunTasks -import org.jetbrains.kotlin.idea.framework.KotlinLibraryKind import org.jetbrains.kotlin.idea.highlighter.KotlinTestRunLineMarkerContributor.Companion.getTestStateIcon import org.jetbrains.kotlin.idea.isMainFunction import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling import org.jetbrains.kotlin.idea.platform.isKotlinTestDeclaration import org.jetbrains.kotlin.idea.projectModel.KotlinPlatform import org.jetbrains.kotlin.idea.util.module -import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind -import org.jetbrains.kotlin.platform.konan.NativePlatforms import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtFunction import org.jetbrains.kotlin.psi.KtNamedDeclaration @@ -37,15 +31,12 @@ class NativeIdePlatformKindTooling : IdePlatformKindTooling() { override val kind = NativeIdePlatformKind - override fun compilerArgumentsForProject(project: Project): CommonCompilerArguments? = null - override val mavenLibraryIds: List get() = emptyList() override val gradlePluginId: String get() = "" override val gradlePlatformIds: List get() = listOf(KotlinPlatform.NATIVE) - override val libraryKind: PersistentLibraryKind<*> = NativeLibraryKind + override val libraryKind: PersistentLibraryKind<*> = KotlinNativeLibraryKind override fun getLibraryDescription(project: Project): CustomLibraryDescription? = null - override fun getLibraryVersionProvider(project: Project): (Library) -> IdeKotlinVersion? = { null } override fun getTestIcon( declaration: KtNamedDeclaration, @@ -97,11 +88,4 @@ class NativeIdePlatformKindTooling : IdePlatformKindTooling() { return true } -} - -object NativeLibraryKind : PersistentLibraryKind("kotlin.native"), KotlinLibraryKind { - override val compilerPlatform: TargetPlatform - get() = NativePlatforms.unspecifiedNativePlatform - - override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!! -} +} \ No newline at end of file diff --git a/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativeLibraryType.kt b/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativeLibraryType.kt index bb7d11e26c1f..23f1bccc1a3e 100644 --- a/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativeLibraryType.kt +++ b/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativeLibraryType.kt @@ -8,12 +8,13 @@ import com.intellij.openapi.roots.libraries.LibraryType 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.klib.isKlibLibraryRootForPlatform +import org.jetbrains.kotlin.idea.base.platforms.KotlinNativeLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.isKlibLibraryRootForPlatform import org.jetbrains.kotlin.platform.konan.NativePlatforms import javax.swing.Icon import javax.swing.JComponent -object NativeLibraryType : LibraryType(NativeLibraryKind) { +object NativeLibraryType : LibraryType(KotlinNativeLibraryKind) { override fun createPropertiesEditor(editorComponent: LibraryEditorComponent): Nothing? = null override fun getCreateActionName(): Nothing? = null override fun createNewLibrary(parentComponent: JComponent, contextDirectory: VirtualFile?, project: Project): Nothing? = null diff --git a/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt b/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt index 2aa7237964bc..34452e830a66 100644 --- a/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt +++ b/plugins/kotlin/native/src/org/jetbrains/kotlin/ide/konan/NativePlatformKindResolution.kt @@ -5,8 +5,6 @@ package org.jetbrains.kotlin.ide.konan 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 @@ -27,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.konan.DeserializedKlibModuleOrigin import org.jetbrains.kotlin.descriptors.konan.KlibModuleOrigin import org.jetbrains.kotlin.ide.konan.CommonizerNativeTargetsCompat.commonizerNativeTargetsCompat import org.jetbrains.kotlin.ide.konan.analyzer.NativeResolverForModuleFactory +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 @@ -35,7 +34,6 @@ import org.jetbrains.kotlin.idea.caches.resolve.BuiltInsCacheKey import org.jetbrains.kotlin.idea.compiler.IDELanguageSettingsProvider 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.idea.klib.safeRead import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.konan.library.KONAN_STDLIB_NAME @@ -59,7 +57,7 @@ class NativePlatformKindResolution : IdePlatformKindResolution { override fun createLibraryInfo(project: Project, library: Library): List { return library.getFiles(OrderRootType.CLASSES).mapNotNull { file -> - if (!isLibraryFileForPlatform(file)) return@createLibraryInfo emptyList() + if (!file.isKlibLibraryRootForPlatform(NativePlatforms.unspecifiedNativePlatform)) return@createLibraryInfo emptyList() val path = PathUtil.getLocalPath(file) ?: return@createLibraryInfo emptyList() NativeKlibLibraryInfo(project, library, path) } @@ -82,9 +80,6 @@ class NativePlatformKindResolution : IdePlatformKindResolution { ) } - override fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean = - virtualFile.isKlibLibraryRootForPlatform(NativePlatforms.unspecifiedNativePlatform) - override fun createResolverForModuleFactory( settings: PlatformAnalysisParameters, environment: TargetEnvironment, @@ -93,9 +88,6 @@ class NativePlatformKindResolution : IdePlatformKindResolution { return NativeResolverForModuleFactory(settings, environment, platform) } - override val libraryKind: PersistentLibraryKind<*> - get() = NativeLibraryKind - override val kind get() = NativeIdePlatformKind override fun getKeyForBuiltIns(moduleInfo: ModuleInfo, sdkInfo: SdkInfo?, stdlibInfo: LibraryInfo?): BuiltInsCacheKey = NativeBuiltInsCacheKey diff --git a/plugins/kotlin/performance-tests/kotlin.performance-tests.iml b/plugins/kotlin/performance-tests/kotlin.performance-tests.iml index 83a5154b9669..e410526055b6 100644 --- a/plugins/kotlin/performance-tests/kotlin.performance-tests.iml +++ b/plugins/kotlin/performance-tests/kotlin.performance-tests.iml @@ -17,6 +17,8 @@ + + diff --git a/plugins/kotlin/performance-tests/performance-test-utils/kotlin.performance-tests.performance-test-utils.iml b/plugins/kotlin/performance-tests/performance-test-utils/kotlin.performance-tests.performance-test-utils.iml index 88a942e79d67..518092d65ab8 100644 --- a/plugins/kotlin/performance-tests/performance-test-utils/kotlin.performance-tests.performance-test-utils.iml +++ b/plugins/kotlin/performance-tests/performance-test-utils/kotlin.performance-tests.performance-test-utils.iml @@ -13,6 +13,8 @@ + + diff --git a/plugins/kotlin/performance-tests/performance-test-utils/test/org/jetbrains/kotlin/idea/performance/tests/utils/project/editorUtils.kt b/plugins/kotlin/performance-tests/performance-test-utils/test/org/jetbrains/kotlin/idea/performance/tests/utils/project/editorUtils.kt index 43703a2342cb..a7abf485e1db 100644 --- a/plugins/kotlin/performance-tests/performance-test-utils/test/org/jetbrains/kotlin/idea/performance/tests/utils/project/editorUtils.kt +++ b/plugins/kotlin/performance-tests/performance-test-utils/test/org/jetbrains/kotlin/idea/performance/tests/utils/project/editorUtils.kt @@ -14,8 +14,6 @@ import junit.framework.TestCase import org.jetbrains.kotlin.idea.core.util.toPsiFile import org.jetbrains.kotlin.idea.performance.tests.utils.projectFileByName - - fun openInEditor(project: Project, name: String): EditorFile { val psiFile = projectFileByName(project, name) return openInEditor(project, psiFile.virtualFile) diff --git a/plugins/kotlin/performance-tests/performance-test-utils/test/org/jetbrains/kotlin/idea/performance/tests/utils/project/environmentUtils.kt b/plugins/kotlin/performance-tests/performance-test-utils/test/org/jetbrains/kotlin/idea/performance/tests/utils/project/environmentUtils.kt index 36f944316810..f9efb6900af1 100644 --- a/plugins/kotlin/performance-tests/performance-test-utils/test/org/jetbrains/kotlin/idea/performance/tests/utils/project/environmentUtils.kt +++ b/plugins/kotlin/performance-tests/performance-test-utils/test/org/jetbrains/kotlin/idea/performance/tests/utils/project/environmentUtils.kt @@ -2,8 +2,10 @@ package org.jetbrains.kotlin.idea.performance.tests.utils.project import com.intellij.openapi.Disposable +import com.intellij.openapi.application.runReadAction import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.projectRoots.JavaSdk +import com.intellij.openapi.projectRoots.ProjectJdkTable import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.testFramework.TestApplicationManager @@ -11,7 +13,6 @@ import org.jetbrains.kotlin.idea.caches.project.getAllProjectSdks import org.jetbrains.kotlin.idea.framework.KotlinSdkType import org.jetbrains.kotlin.idea.performance.tests.utils.logMessage import org.jetbrains.kotlin.idea.test.GradleProcessOutputInterceptor -import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe fun initApp(rootDisposable: Disposable): TestApplicationManager { val application = TestApplicationManager.getInstance() @@ -38,7 +39,7 @@ fun initSdk(rootDisposable: Disposable): Sdk { val internal = javaSdk.createJdk("IDEA jdk", jdk11Home ?: jdk8Home ?: javaHome) val gradle = javaSdk.createJdk(GRADLE_JDK_NAME, jdk11Home ?: jdk8Home ?: javaHome) - val jdkTable = getProjectJdkTableSafe() + val jdkTable = runReadAction { ProjectJdkTable.getInstance() } arrayOf(jdk8, jdk11, internal, gradle).forEach { jdkTable.addJdk(it, rootDisposable) } KotlinSdkType.setUpIfNeeded() diff --git a/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/PerformanceNativeProjectsTest.kt b/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/PerformanceNativeProjectsTest.kt index 3494d94e463c..c60e9287f70a 100644 --- a/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/PerformanceNativeProjectsTest.kt +++ b/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/PerformanceNativeProjectsTest.kt @@ -10,10 +10,10 @@ import com.intellij.openapi.roots.LibraryOrderEntry import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.util.SystemInfoRt.* import com.intellij.openapi.util.io.FileUtil -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.caches.project.isMPPModule import org.jetbrains.kotlin.idea.facet.KotlinFacet -import org.jetbrains.kotlin.idea.framework.detectLibraryKind import org.jetbrains.kotlin.idea.gradle.configuration.klib.KotlinNativeLibraryNameUtil.parseIDELibraryName import org.jetbrains.kotlin.idea.gradle.configuration.readGradleProperty import org.jetbrains.kotlin.idea.testFramework.Stats @@ -308,7 +308,7 @@ class PerformanceNativeProjectsTest : AbstractPerformanceProjectsTest() { .asSequence() .filterIsInstance() .mapNotNull { it.library } - .filter { detectLibraryKind(it.getFiles(OrderRootType.CLASSES)) == NativeLibraryKind } + .filter { detectLibraryKind(it.getFiles(OrderRootType.CLASSES)) == KotlinNativeLibraryKind } .mapNotNull inner@{ library -> val libraryNameParts = parseIDELibraryName(library.name.orEmpty()) ?: return@inner null val (_, pureLibraryName, platformPart) = libraryNameParts diff --git a/plugins/kotlin/plugin/kotlin.plugin.iml b/plugins/kotlin/plugin/kotlin.plugin.iml index 6c6e15f1c38b..077dd8236583 100644 --- a/plugins/kotlin/plugin/kotlin.plugin.iml +++ b/plugins/kotlin/plugin/kotlin.plugin.iml @@ -13,7 +13,11 @@ - + + + + + diff --git a/plugins/kotlin/plugin/resources/META-INF/kotlin-core.xml b/plugins/kotlin/plugin/resources/META-INF/kotlin-core.xml index 74bc9539722d..2a26643a52a2 100644 --- a/plugins/kotlin/plugin/resources/META-INF/kotlin-core.xml +++ b/plugins/kotlin/plugin/resources/META-INF/kotlin-core.xml @@ -21,10 +21,7 @@ interface="org.jetbrains.kotlin.idea.actions.NewKotlinFileHook"/> - + interface="org.jetbrains.kotlin.idea.base.compilerPreferences.facet.KotlinFacetValidatorCreator"/> + - + diff --git a/plugins/kotlin/plugin/resources/META-INF/resolution.xml b/plugins/kotlin/plugin/resources/META-INF/resolution.xml index c0d6b64079e4..fdd344c400ed 100644 --- a/plugins/kotlin/plugin/resources/META-INF/resolution.xml +++ b/plugins/kotlin/plugin/resources/META-INF/resolution.xml @@ -61,9 +61,6 @@ - diff --git a/plugins/kotlin/project-wizard/idea/kotlin.project-wizard.idea.iml b/plugins/kotlin/project-wizard/idea/kotlin.project-wizard.idea.iml index dfa721fa04fa..f9eee2304cbb 100644 --- a/plugins/kotlin/project-wizard/idea/kotlin.project-wizard.idea.iml +++ b/plugins/kotlin/project-wizard/idea/kotlin.project-wizard.idea.iml @@ -18,6 +18,7 @@ + diff --git a/plugins/kotlin/resources-fir/resources/META-INF/plugin.xml b/plugins/kotlin/resources-fir/resources/META-INF/plugin.xml index 8f9f5483c7aa..73c80e4a97ee 100644 --- a/plugins/kotlin/resources-fir/resources/META-INF/plugin.xml +++ b/plugins/kotlin/resources-fir/resources/META-INF/plugin.xml @@ -155,9 +155,6 @@ The Kotlin FIR plugin provides language support in IntelliJ IDEA and Android Stu - - diff --git a/plugins/kotlin/test-framework/kotlin.test-framework.iml b/plugins/kotlin/test-framework/kotlin.test-framework.iml index f04fdad4bf6e..7969f869810c 100644 --- a/plugins/kotlin/test-framework/kotlin.test-framework.iml +++ b/plugins/kotlin/test-framework/kotlin.test-framework.iml @@ -19,6 +19,8 @@ + + diff --git a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/ConfigLibraryUtil.kt b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/ConfigLibraryUtil.kt index 7f548e7f087b..faadd4bf3eb8 100644 --- a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/ConfigLibraryUtil.kt +++ b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/ConfigLibraryUtil.kt @@ -4,6 +4,7 @@ package org.jetbrains.kotlin.idea.test import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.module.Module +import com.intellij.openapi.projectRoots.ProjectJdkTable import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.roots.LibraryOrderEntry import com.intellij.openapi.roots.ModifiableRootModel @@ -18,10 +19,10 @@ import com.intellij.util.PathUtil import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts import org.jetbrains.kotlin.idea.artifacts.AdditionalKotlinArtifacts import org.jetbrains.kotlin.idea.artifacts.KotlinLibraryData -import org.jetbrains.kotlin.idea.framework.CommonLibraryKind -import org.jetbrains.kotlin.idea.framework.JSLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.KotlinCommonLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind +import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.idea.util.application.runWriteAction -import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe import java.io.File import kotlin.test.assertNotNull @@ -47,13 +48,13 @@ object ConfigLibraryUtil { } fun configureKotlinStdlibJs(module: Module) { - addLibrary(module, LIB_NAME_KOTLIN_STDLIB_JS, JSLibraryKind) { + addLibrary(module, LIB_NAME_KOTLIN_STDLIB_JS, KotlinJavaScriptLibraryKind) { addRoot(KotlinArtifacts.instance.kotlinStdlibJs, OrderRootType.CLASSES) } } fun configureKotlinStdlibCommon(module: Module) { - addLibrary(module, LIB_NAME_KOTLIN_STDLIB_COMMON, CommonLibraryKind) { + addLibrary(module, LIB_NAME_KOTLIN_STDLIB_COMMON, KotlinCommonLibraryKind) { addRoot(AdditionalKotlinArtifacts.kotlinStdlibCommon, OrderRootType.CLASSES) } } @@ -93,7 +94,7 @@ object ConfigLibraryUtil { val rootModel = rootManager.modifiableModel assertNotNull( - getProjectJdkTableSafe().findJdk(sdk.name), + ProjectJdkTable.getInstance().findJdk(sdk.name), "Cannot find sdk in ProjectJdkTable. This may cause sdk leak.\n" + "You can use ProjectPluginTestBase.addJdk(Disposable ...) to register sdk in ProjectJdkTable.\n" + "Then sdk will be removed in tearDown" diff --git a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/KotlinSdkCreationChecker.kt b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/KotlinSdkCreationChecker.kt index 97c462745d44..e389491f6eba 100644 --- a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/KotlinSdkCreationChecker.kt +++ b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/KotlinSdkCreationChecker.kt @@ -4,26 +4,28 @@ package org.jetbrains.kotlin.idea.test import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.runWriteAction +import com.intellij.openapi.projectRoots.ProjectJdkTable import com.intellij.openapi.projectRoots.Sdk import org.jetbrains.kotlin.idea.framework.KotlinSdkType -import org.jetbrains.kotlin.idea.util.getProjectJdkTableSafe +import org.jetbrains.kotlin.idea.util.application.runReadAction class KotlinSdkCreationChecker { + private val projectJdkTable: ProjectJdkTable + get() = runReadAction { ProjectJdkTable.getInstance() } - private val sdksBefore: Array = getProjectJdkTableSafe().allJdks + private val sdksBefore: Array = projectJdkTable.allJdks - fun getKotlinSdks() = getProjectJdkTableSafe().allJdks.filter { it.sdkType is KotlinSdkType } + fun getKotlinSdks() = projectJdkTable.allJdks.filter { it.sdkType is KotlinSdkType } private fun getCreatedKotlinSdks() = - getProjectJdkTableSafe().allJdks.filter { !sdksBefore.contains(it) && it.sdkType is KotlinSdkType } + projectJdkTable.allJdks.filter { !sdksBefore.contains(it) && it.sdkType is KotlinSdkType } fun isKotlinSdkCreated() = getCreatedKotlinSdks().isNotEmpty() fun removeNewKotlinSdk() { - val jdkTable = getProjectJdkTableSafe() ApplicationManager.getApplication().invokeAndWait { runWriteAction { - getCreatedKotlinSdks().forEach { jdkTable.removeJdk(it) } + getCreatedKotlinSdks().forEach { projectJdkTable.removeJdk(it) } } } } diff --git a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/MockLibraryFacility.kt b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/MockLibraryFacility.kt index f4d8e9552db1..0d249c754e42 100644 --- a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/MockLibraryFacility.kt +++ b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/MockLibraryFacility.kt @@ -6,10 +6,9 @@ import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.roots.ModifiableRootModel import com.intellij.openapi.roots.OrderRootType import com.intellij.testFramework.IdeaTestUtil -import org.jetbrains.kotlin.idea.framework.JSLibraryKind +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind import org.jetbrains.kotlin.idea.framework.KotlinSdkType import org.jetbrains.kotlin.platform.js.JsPlatform -import org.jetbrains.kotlin.idea.test.KotlinCompilerStandalone import java.io.File data class MockLibraryFacility( @@ -43,7 +42,7 @@ data class MockLibraryFacility( classpath = classpath ).compile() - val kind = if (platform is JsPlatform) JSLibraryKind else null + val kind = if (platform is JsPlatform) KotlinJavaScriptLibraryKind else null ConfigLibraryUtil.addLibrary(module, MOCK_LIBRARY_NAME, kind) { addRoot(libraryJar, OrderRootType.CLASSES) @@ -61,7 +60,7 @@ data class MockLibraryFacility( get() = object : KotlinLightProjectDescriptor() { override fun configureModule(module: Module, model: ModifiableRootModel) = this@MockLibraryFacility.setUp(module) - override fun getSdk(): Sdk = if (this@MockLibraryFacility.platform is JsPlatform) + override fun getSdk(): Sdk = if (this@MockLibraryFacility.platform is KotlinCompilerStandalone.Platform.JavaScript) KotlinSdkType.INSTANCE.createSdkWithUniqueName(emptyList()) else IdeaTestUtil.getMockJdk18() diff --git a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/PluginTestCaseBase.java b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/PluginTestCaseBase.java index e9287c9212a8..1775f655676c 100644 --- a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/PluginTestCaseBase.java +++ b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/PluginTestCaseBase.java @@ -4,16 +4,14 @@ package org.jetbrains.kotlin.idea.test; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.pom.java.LanguageLevel; import com.intellij.testFramework.IdeaTestUtil; -import com.intellij.util.lang.JavaVersion; import kotlin.jvm.functions.Function0; import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.util.IjPlatformUtil; -import org.jetbrains.kotlin.idea.test.KotlinTestUtils; import org.jetbrains.kotlin.test.TestJdkKind; import java.io.File; @@ -24,7 +22,7 @@ public class PluginTestCaseBase { @NotNull private static Sdk getSdk(String sdkHome, String name) { - ProjectJdkTable table = IjPlatformUtil.getProjectJdkTableSafe(); + ProjectJdkTable table = ReadAction.compute(() -> ProjectJdkTable.getInstance()); Sdk existing = table.findJdk(name); if (existing != null) { return existing; @@ -42,13 +40,13 @@ public class PluginTestCaseBase { @NotNull public static Sdk addJdk(@NotNull Disposable disposable, @NotNull Function0 getJdk) { Sdk jdk = getJdk.invoke(); - Sdk[] allJdks = IjPlatformUtil.getProjectJdkTableSafe().getAllJdks(); + Sdk[] allJdks = ReadAction.compute(() -> ProjectJdkTable.getInstance()).getAllJdks(); for (Sdk existingJdk : allJdks) { if (existingJdk == jdk) { return existingJdk; } } - ApplicationManager.getApplication().runWriteAction(() -> IjPlatformUtil.getProjectJdkTableSafe().addJdk(jdk, disposable)); + ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(jdk, disposable)); return jdk; } diff --git a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/SdkAndMockLibraryProjectDescriptor.java b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/SdkAndMockLibraryProjectDescriptor.java index e5bd87cd47ce..cdc229ec7663 100644 --- a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/SdkAndMockLibraryProjectDescriptor.java +++ b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/SdkAndMockLibraryProjectDescriptor.java @@ -14,9 +14,8 @@ import com.intellij.testFramework.IdeaTestUtil; import kotlin.collections.CollectionsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts; -import org.jetbrains.kotlin.idea.framework.JSLibraryKind; +import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind; import org.jetbrains.kotlin.idea.framework.KotlinSdkType; -import org.jetbrains.kotlin.idea.test.KotlinCompilerStandalone; import java.io.File; import java.util.Collections; @@ -81,7 +80,7 @@ public class SdkAndMockLibraryProjectDescriptor extends KotlinLightProjectDescri } if (isJsLibrary && mockLibraryModel instanceof LibraryEx.ModifiableModelEx) { - ((LibraryEx.ModifiableModelEx) mockLibraryModel).setKind(JSLibraryKind.INSTANCE); + ((LibraryEx.ModifiableModelEx) mockLibraryModel).setKind(KotlinJavaScriptLibraryKind.INSTANCE); } if (withSources) {