Fix internal-visibility mangling in IDE
Collect module name properly from facets settings, using CLI arguments
which define module name ('-module-name' on JVM and Common,
'-output-file' on JS).
^KT-23668 Fixed
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor;
|
||||
import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityUtilsKt;
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.Call;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.psi.KtFunction;
|
||||
@@ -281,7 +282,13 @@ public class JvmCodegenUtil {
|
||||
|
||||
@NotNull
|
||||
public static String getModuleName(ModuleDescriptor module) {
|
||||
return StringsKt.removeSurrounding(module.getName().asString(), "<", ">");
|
||||
Name name = module.getStableName();
|
||||
if (name == null) {
|
||||
// Defensive fallback to possibly unstable name, to not fail with exception
|
||||
return StringsKt.removeSurrounding(module.getName().asString(), "<", ">");
|
||||
} else {
|
||||
return StringsKt.removeSurrounding(name.asString(), "<", ">");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -247,7 +247,11 @@ class ResolverForProjectImpl<M : ModuleInfo>(
|
||||
private fun createModuleDescriptor(module: M): ModuleData {
|
||||
val moduleDescriptor = ModuleDescriptorImpl(
|
||||
module.name,
|
||||
projectContext.storageManager, builtIns, modulePlatforms(module), module.capabilities
|
||||
projectContext.storageManager,
|
||||
builtIns,
|
||||
modulePlatforms(module),
|
||||
module.capabilities,
|
||||
module.stableName
|
||||
)
|
||||
moduleInfoByDescriptor[moduleDescriptor] = module
|
||||
setupModuleDescriptor(module, moduleDescriptor)
|
||||
@@ -274,6 +278,8 @@ interface ModuleInfo {
|
||||
fun modulesWhoseInternalsAreVisible(): Collection<ModuleInfo> = listOf()
|
||||
val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>
|
||||
get() = mapOf(Capability to this)
|
||||
val stableName: Name?
|
||||
get() = null
|
||||
|
||||
// For common modules, we add built-ins at the beginning of the dependencies list, after the SDK.
|
||||
// This is needed because if a JVM module depends on the common module, we should use JVM built-ins for resolution of both modules.
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
public final class C extends p.A {
|
||||
public int getAp$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
|
||||
public int getAp$light_idea_test_case() { /* compiled code */ }
|
||||
|
||||
public int af$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
|
||||
public int af$light_idea_test_case() { /* compiled code */ }
|
||||
|
||||
public C() { /* compiled code */ }
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
public final class C extends p.A implements p.I {
|
||||
private final int ip = 5;
|
||||
|
||||
public int getAp$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
|
||||
public int getAp$light_idea_test_case() { /* compiled code */ }
|
||||
|
||||
public int af$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
|
||||
public int af$light_idea_test_case() { /* compiled code */ }
|
||||
|
||||
public int getIp$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
|
||||
public int getIp$light_idea_test_case() { /* compiled code */ }
|
||||
|
||||
public int $$<no name provided>$production_sources_for_module_light_idea_test_case /* Real name is '<no name provided>$production_sources_for_module_light_idea_test_case' */() { /* compiled code */ }
|
||||
public int $$<no name provided>$light_idea_test_case /* Real name is '<no name provided>$light_idea_test_case' */() { /* compiled code */ }
|
||||
|
||||
public C() { /* compiled code */ }
|
||||
}
|
||||
@@ -25,6 +25,11 @@ interface ModuleDescriptor : DeclarationDescriptor {
|
||||
|
||||
val builtIns: KotlinBuiltIns
|
||||
|
||||
/**
|
||||
* Stable name of *Kotlin* module. Can be used for ABI (e.g. for mangling of declarations)
|
||||
*/
|
||||
val stableName: Name?
|
||||
|
||||
fun shouldSeeInternalsOf(targetModule: ModuleDescriptor): Boolean
|
||||
|
||||
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
|
||||
|
||||
@@ -35,7 +35,8 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
override val builtIns: KotlinBuiltIns,
|
||||
// May be null in compiler context, should be not-null in IDE context
|
||||
multiTargetPlatform: MultiTargetPlatform? = null,
|
||||
capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap()
|
||||
capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap(),
|
||||
override val stableName: Name? = null
|
||||
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor {
|
||||
init {
|
||||
if (!moduleName.isSpecial) {
|
||||
|
||||
@@ -74,6 +74,12 @@ public class ErrorUtils {
|
||||
return Name.special("<ERROR MODULE>");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Name getStableName() {
|
||||
return Name.special("<ERROR MODULE>");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PackageViewDescriptor getPackage(@NotNull FqName fqName) {
|
||||
|
||||
+2
-1
@@ -281,7 +281,8 @@ internal object IDELightClassContexts {
|
||||
private fun setupAdHocResolve(project: Project, realWorldModule: ModuleDescriptor, files: List<KtFile>): ResolveSession {
|
||||
val trace = BindingTraceContext()
|
||||
val sm = LockBasedStorageManager.NO_LOCKS
|
||||
val moduleDescriptor = ModuleDescriptorImpl(realWorldModule.name, sm, realWorldModule.builtIns)
|
||||
val moduleDescriptor =
|
||||
ModuleDescriptorImpl(realWorldModule.name, sm, realWorldModule.builtIns, stableName = realWorldModule.stableName)
|
||||
|
||||
moduleDescriptor.setDependencies(moduleDescriptor, moduleDescriptor.builtIns.builtInsModule)
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.idea.core.isInTestSourceContentKotlinAware
|
||||
import org.jetbrains.kotlin.idea.framework.getLibraryPlatform
|
||||
import org.jetbrains.kotlin.idea.project.KotlinModuleModificationTracker
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.idea.project.getStableName
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
||||
import org.jetbrains.kotlin.idea.util.isInSourceContentWithoutInjected
|
||||
import org.jetbrains.kotlin.idea.util.rootManager
|
||||
@@ -158,6 +159,8 @@ data class ModuleProductionSourceInfo internal constructor(
|
||||
|
||||
override val name = Name.special("<production sources for module ${module.name}>")
|
||||
|
||||
override val stableName: Name = module.getStableName()
|
||||
|
||||
override fun contentScope(): GlobalSearchScope = ModuleProductionSourceScope(module)
|
||||
|
||||
override fun <T> createCachedValueProvider(f: () -> CachedValueProvider.Result<T>) = CachedValueProvider { f() }
|
||||
@@ -170,6 +173,8 @@ data class ModuleTestSourceInfo internal constructor(override val module: Module
|
||||
|
||||
override val name = Name.special("<test sources for module ${module.name}>")
|
||||
|
||||
override val stableName: Name = module.getStableName()
|
||||
|
||||
override val displayedName get() = module.name + " (test)"
|
||||
|
||||
override fun contentScope(): GlobalSearchScope = ModuleTestSourceScope(module)
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.roots.ProjectFileIndex
|
||||
import com.intellij.openapi.roots.ProjectRootModificationTracker
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.util.CachedValue
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
@@ -36,11 +37,13 @@ import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgume
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||
import org.jetbrains.kotlin.idea.facet.getLibraryLanguageLevel
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.UserDataProperty
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.utils.Jsr305State
|
||||
import java.io.File
|
||||
|
||||
val KtElement.platform: TargetPlatform
|
||||
get() = TargetPlatformDetector.getPlatform(containingKtFile)
|
||||
@@ -78,6 +81,32 @@ fun Module.getAndCacheLanguageLevelByDependencies(): LanguageVersion {
|
||||
return languageLevel
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns stable binary name of module from the *Kotlin* point of view.
|
||||
* Having correct module name is critical for compiler, e.g. for 'internal'-visibility
|
||||
* mangling (see KT-23668).
|
||||
*
|
||||
* Note that build systems and IDEA have their own module systems and, potentially, their
|
||||
* names can be different from Kotlin module name (though this is the rare case).
|
||||
*/
|
||||
fun Module.getStableName(): Name {
|
||||
// Here we check ideal situation: we have a facet, and it has 'moduleName' argument.
|
||||
// This should be the case for the most environments
|
||||
val arguments = KotlinFacetSettingsProvider.getInstance(project).getInitializedSettings(this).mergedCompilerArguments
|
||||
val explicitNameFromArguments = when (arguments) {
|
||||
is K2JVMCompilerArguments -> arguments.moduleName
|
||||
is K2JSCompilerArguments -> arguments.outputFile?.let { FileUtil.getNameWithoutExtension(File(it)) }
|
||||
is K2MetadataCompilerArguments -> arguments.moduleName
|
||||
else -> null // Actually, only 'null' possible here
|
||||
}
|
||||
|
||||
// Here we handle pessimistic case: no facet is found or it declares no 'moduleName'
|
||||
// We heuristically assume that name of Module in IDEA is the same as Kotlin module (which may be not the case)
|
||||
val stableNameApproximation = explicitNameFromArguments ?: name
|
||||
|
||||
return Name.special("<$stableNameApproximation>")
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun Project.getLanguageVersionSettings(
|
||||
contextModule: Module? = null,
|
||||
|
||||
+88
@@ -28,10 +28,13 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootType
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType
|
||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
||||
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.caches.project.productionSourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.testSourceInfo
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinStatus
|
||||
import org.jetbrains.kotlin.idea.configuration.ModuleSourceRootMap
|
||||
@@ -43,6 +46,9 @@ import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.sdk
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
@@ -2150,6 +2156,88 @@ compileTestKotlin {
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStableModuleNameWhileUsingGradle_JS() {
|
||||
createProjectSubFile(
|
||||
"build.gradle", """
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin2js'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.50"
|
||||
}
|
||||
|
||||
"""
|
||||
)
|
||||
importProject()
|
||||
|
||||
checkStableModuleName("project_main", "project", JsPlatform, isProduction = true)
|
||||
// Note "_test" suffix: this is current behavior of K2JS Compiler
|
||||
checkStableModuleName("project_test", "project_test", JsPlatform, isProduction = false)
|
||||
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStableModuleNameWhileUsingGradle_JVM() {
|
||||
createProjectSubFile(
|
||||
"build.gradle", """
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.50"
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.languageVersion = "1.2"
|
||||
}
|
||||
"""
|
||||
)
|
||||
importProject()
|
||||
|
||||
checkStableModuleName("project_main", "project", JvmPlatform, isProduction = true)
|
||||
checkStableModuleName("project_test", "project", JvmPlatform, isProduction = false)
|
||||
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
private fun checkStableModuleName(projectName: String, expectedName: String, platform: TargetPlatform, isProduction: Boolean) {
|
||||
val module = getModule(projectName)
|
||||
val moduleInfo = if (isProduction) module.productionSourceInfo() else module.testSourceInfo()
|
||||
|
||||
val resolutionFacade = KotlinCacheService.getInstance(myProject).getResolutionFacadeByModuleInfo(moduleInfo!!, platform)!!
|
||||
val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||
|
||||
Assert.assertEquals("<$expectedName>", moduleDescriptor.name.asString())
|
||||
}
|
||||
|
||||
private fun assertAllModulesConfigured() {
|
||||
runReadAction {
|
||||
for (moduleGroup in ModuleSourceRootMap(myProject).groupByBaseModules(myProject.allModules())) {
|
||||
|
||||
+88
@@ -25,10 +25,13 @@ import com.intellij.openapi.roots.LibraryOrderEntry
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
||||
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.caches.project.productionSourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.testSourceInfo
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinStatus
|
||||
import org.jetbrains.kotlin.idea.configuration.ModuleSourceRootMap
|
||||
@@ -38,6 +41,10 @@ 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.util.projectStructure.allModules
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.sdk
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
@@ -1899,6 +1906,87 @@ compileTestKotlin {
|
||||
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project_test")).sdk!!.sdkType is KotlinSdkType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStableModuleNameWhileUsingGradle_JS() {
|
||||
createProjectSubFile(
|
||||
"build.gradle", """
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin2js'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.50"
|
||||
}
|
||||
|
||||
"""
|
||||
)
|
||||
importProject()
|
||||
|
||||
checkStableModuleName("project", "project", JsPlatform, isProduction = true)
|
||||
checkStableModuleName("project", "project", JsPlatform, isProduction = false)
|
||||
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStableModuleNameWhileUsingGradle_JVM() {
|
||||
createProjectSubFile(
|
||||
"build.gradle", """
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.50"
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.languageVersion = "1.2"
|
||||
}
|
||||
"""
|
||||
)
|
||||
importProject()
|
||||
|
||||
checkStableModuleName("project", "project", JvmPlatform, isProduction = true)
|
||||
checkStableModuleName("project", "project", JvmPlatform, isProduction = false)
|
||||
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
private fun checkStableModuleName(projectName: String, expectedName: String, platform: TargetPlatform, isProduction: Boolean) {
|
||||
val module = getModule(projectName)
|
||||
val moduleInfo = if (isProduction) module.productionSourceInfo() else module.testSourceInfo()
|
||||
|
||||
val resolutionFacade = KotlinCacheService.getInstance(myProject).getResolutionFacadeByModuleInfo(moduleInfo!!, platform)!!
|
||||
val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||
|
||||
Assert.assertEquals("<$expectedName>", moduleDescriptor.name.asString())
|
||||
}
|
||||
|
||||
private fun assertAllModulesConfigured() {
|
||||
runReadAction {
|
||||
for (moduleGroup in ModuleSourceRootMap(myProject).groupByBaseModules(myProject.allModules())) {
|
||||
|
||||
+88
@@ -25,10 +25,13 @@ import com.intellij.openapi.roots.LibraryOrderEntry
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
||||
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.caches.project.productionSourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.testSourceInfo
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinStatus
|
||||
import org.jetbrains.kotlin.idea.configuration.ModuleSourceRootMap
|
||||
@@ -38,6 +41,10 @@ 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.util.projectStructure.allModules
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.sdk
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
@@ -1899,6 +1906,87 @@ compileTestKotlin {
|
||||
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project_test")).sdk!!.sdkType is KotlinSdkType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStableModuleNameWhileUsingGradle_JS() {
|
||||
createProjectSubFile(
|
||||
"build.gradle", """
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin2js'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.50"
|
||||
}
|
||||
|
||||
"""
|
||||
)
|
||||
importProject()
|
||||
|
||||
checkStableModuleName("project", "project", JsPlatform, isProduction = true)
|
||||
checkStableModuleName("project", "project", JsPlatform, isProduction = false)
|
||||
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStableModuleNameWhileUsingGradle_JVM() {
|
||||
createProjectSubFile(
|
||||
"build.gradle", """
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.50")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.50"
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.languageVersion = "1.2"
|
||||
}
|
||||
"""
|
||||
)
|
||||
importProject()
|
||||
|
||||
checkStableModuleName("project", "project", JvmPlatform, isProduction = true)
|
||||
checkStableModuleName("project", "project", JvmPlatform, isProduction = false)
|
||||
|
||||
assertAllModulesConfigured()
|
||||
}
|
||||
|
||||
private fun checkStableModuleName(projectName: String, expectedName: String, platform: TargetPlatform, isProduction: Boolean) {
|
||||
val module = getModule(projectName)
|
||||
val moduleInfo = if (isProduction) module.productionSourceInfo() else module.testSourceInfo()
|
||||
|
||||
val resolutionFacade = KotlinCacheService.getInstance(myProject).getResolutionFacadeByModuleInfo(moduleInfo!!, platform)!!
|
||||
val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||
|
||||
Assert.assertEquals("<$expectedName>", moduleDescriptor.name.asString())
|
||||
}
|
||||
|
||||
private fun assertAllModulesConfigured() {
|
||||
runReadAction {
|
||||
for (moduleGroup in ModuleSourceRootMap(myProject).groupByBaseModules(myProject.allModules())) {
|
||||
|
||||
@@ -28,9 +28,12 @@ import com.intellij.util.PathUtil
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootType
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.idea.caches.project.productionSourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.testSourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
|
||||
@@ -38,7 +41,10 @@ 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.refactoring.toPsiFile
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
@@ -2774,6 +2780,127 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
fun testStableModuleNameWhileUsingMaven_JVM() {
|
||||
createProjectSubDirs("src/main/kotlin")
|
||||
|
||||
importProject(
|
||||
"""
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>$kotlinVersion</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<languageVersion>1.2</languageVersion>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
"""
|
||||
)
|
||||
|
||||
assertImporterStatePresent()
|
||||
|
||||
checkStableModuleName("project", "project", JvmPlatform, isProduction = true)
|
||||
checkStableModuleName("project", "project", JvmPlatform, isProduction = false)
|
||||
}
|
||||
|
||||
fun testStableModuleNameWhileUsngMaven_JS() {
|
||||
createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
|
||||
|
||||
importProject(
|
||||
"""
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-js</artifactId>
|
||||
<version>$kotlinVersion</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>js</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<languageVersion>1.1</languageVersion>
|
||||
<apiVersion>1.0</apiVersion>
|
||||
<multiPlatform>true</multiPlatform>
|
||||
<nowarn>true</nowarn>
|
||||
<args>
|
||||
<arg>-Xcoroutines=enable</arg>
|
||||
</args>
|
||||
<sourceMap>true</sourceMap>
|
||||
<outputFile>test.js</outputFile>
|
||||
<metaInfo>true</metaInfo>
|
||||
<moduleKind>commonjs</moduleKind>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
"""
|
||||
)
|
||||
|
||||
assertImporterStatePresent()
|
||||
|
||||
// Note that we check name induced by '-output-file' -- may be it's not the best
|
||||
// decision, but we don't have a better one
|
||||
checkStableModuleName("project", "test", JsPlatform, isProduction = true)
|
||||
checkStableModuleName("project", "test", JsPlatform, isProduction = false)
|
||||
}
|
||||
|
||||
private fun checkStableModuleName(projectName: String, expectedName: String, platform: TargetPlatform, isProduction: Boolean) {
|
||||
val module = getModule(projectName)
|
||||
val moduleInfo = if (isProduction) module.productionSourceInfo() else module.testSourceInfo()
|
||||
|
||||
val resolutionFacade = KotlinCacheService.getInstance(myProject).getResolutionFacadeByModuleInfo(moduleInfo!!, platform)!!
|
||||
val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||
|
||||
Assert.assertEquals("<$expectedName>", moduleDescriptor.name.asString())
|
||||
}
|
||||
|
||||
private fun assertImporterStatePresent() {
|
||||
assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class J extends X.Y {
|
||||
@Override
|
||||
public int newOverridableMethod$production_sources_for_module_light_idea_test_case(int x) {
|
||||
return super.newOverridableMethod$production_sources_for_module_light_idea_test_case(x);
|
||||
public int newOverridableMethod$light_idea_test_case(int x) {
|
||||
return super.newOverridableMethod$light_idea_test_case(x);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
class J extends X.Y {
|
||||
@Override
|
||||
public int overridableMethod$production_sources_for_module_light_idea_test_case(int x) {
|
||||
return super.overridableMethod$production_sources_for_module_light_idea_test_case(x);
|
||||
public int overridableMethod$light_idea_test_case(int x) {
|
||||
return super.overridableMethod$light_idea_test_case(x);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
class J extends X.Y {
|
||||
@Override
|
||||
public int getNewOverridableVar$production_sources_for_module_light_idea_test_case() {
|
||||
return super.getNewOverridableVar$production_sources_for_module_light_idea_test_case();
|
||||
public int getNewOverridableVar$light_idea_test_case() {
|
||||
return super.getNewOverridableVar$light_idea_test_case();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNewOverridableVar$production_sources_for_module_light_idea_test_case(int value) {
|
||||
super.setNewOverridableVar$production_sources_for_module_light_idea_test_case(value);
|
||||
public void setNewOverridableVar$light_idea_test_case(int value) {
|
||||
super.setNewOverridableVar$light_idea_test_case(value);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
class J extends X.Y {
|
||||
@Override
|
||||
public int getOverridableVar$production_sources_for_module_light_idea_test_case() {
|
||||
return super.getOverridableVar$production_sources_for_module_light_idea_test_case();
|
||||
public int getOverridableVar$light_idea_test_case() {
|
||||
return super.getOverridableVar$light_idea_test_case();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOverridableVar$production_sources_for_module_light_idea_test_case(int value) {
|
||||
super.setOverridableVar$production_sources_for_module_light_idea_test_case(value);
|
||||
public void setOverridableVar$light_idea_test_case(int value) {
|
||||
super.setOverridableVar$light_idea_test_case(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user