[Analysis API FIR] Use stable module name when mangling internal name

^KTIJ-25046
This commit is contained in:
aleksandrina-streltsova
2023-04-26 12:30:25 +03:00
committed by teamcity
parent a7396d8c10
commit c956b4aeae
4 changed files with 13 additions and 3 deletions
@@ -10,6 +10,7 @@ dependencies {
api(project(":compiler:frontend.common.jvm"))
api(project(":compiler:resolution.common.jvm"))
api(project(":core:compiler.common.jvm"))
implementation(project(":analysis:project-structure"))
compileOnly(intellijCore())
compileOnly(commonDependency("org.jetbrains.intellij.deps:trove4j"))
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.asJava
import com.intellij.lang.jvm.JvmModifier
import com.intellij.psi.*
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
import org.jetbrains.kotlin.asJava.classes.KtFakeLightClass
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.elements.*
@@ -194,7 +195,8 @@ fun demangleInternalName(name: String): String? {
return if (indexOfDollar >= 0) name.substring(0, indexOfDollar) else null
}
fun mangleInternalName(name: String, moduleName: String): String {
fun mangleInternalName(name: String, module: KtSourceModule): String {
val moduleName = (module.stableModuleName ?: module.moduleName).removeSurrounding("<", ">")
return name + "$" + NameUtils.sanitizeAsJavaIdentifier(moduleName)
}
@@ -92,6 +92,13 @@ public sealed interface KtModule {
public interface KtSourceModule : KtModule {
public val moduleName: String
/**
* A stable binary name of module from the *Kotlin* point of view.
* Having correct module name is critical for `internal`-visibility mangling. See [org.jetbrains.kotlin.asJava.mangleInternalName]
*/
public val stableModuleName: String?
get() = null
override val moduleDescription: String
get() = "Sources of $moduleName"
@@ -117,8 +117,8 @@ internal abstract class SymbolLightMethodBase(
if (containingClass is KtLightClassForFacade) return defaultName
if (hasPublishedApiAnnotation(annotationUseSiteTarget.toFilter())) return defaultName
val moduleName = (ktModule as? KtSourceModule)?.moduleName ?: return defaultName
return mangleInternalName(defaultName, moduleName)
val sourceModule = ktModule as? KtSourceModule ?: return defaultName
return mangleInternalName(defaultName, sourceModule)
}
abstract fun isOverride(): Boolean