diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt index 7e435a2b66..6f9142004c 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt @@ -505,15 +505,23 @@ class ResolverAAImpl( if (accessor.receiver.closestClassDeclaration()?.classKind == ClassKind.ANNOTATION_CLASS) { return accessor.receiver.simpleName.asString() } + + val symbol: KaPropertyAccessorSymbol? = when (accessor) { + is KSPropertyAccessorImpl -> accessor.ktPropertyAccessorSymbol + else -> null + } + + symbol?.explictJvmName()?.let { + return it + } + val prefix = if (accessor is KSPropertyGetter) { "get" } else { "set" } - val inlineSuffix = when (accessor) { - is KSPropertyAccessorImpl -> accessor.ktPropertyAccessorSymbol.inlineSuffix - else -> "" - } + + val inlineSuffix = symbol?.inlineSuffix ?: "" val mangledName = if (accessor.modifiers.contains(Modifier.INTERNAL)) { "\$${ktModule.name}" } else "" @@ -529,10 +537,17 @@ class ResolverAAImpl( }?.let { return it.name } - val inlineSuffix = when (declaration) { - is KSFunctionDeclarationImpl -> declaration.ktFunctionSymbol.inlineSuffix - else -> "" + + val symbol: KaFunctionSymbol? = when (declaration) { + is KSFunctionDeclarationImpl -> declaration.ktFunctionSymbol + else -> null + } + + symbol?.explictJvmName()?.let { + return it } + + val inlineSuffix = symbol?.inlineSuffix ?: "" val mangledName = if (declaration.modifiers.contains(Modifier.INTERNAL)) { "\$${ktModule.name}" } else "" diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt index 57dab5301c..44cc9867d4 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt @@ -965,7 +965,7 @@ internal val KaFunctionSymbol.inlineSuffix: String valueParameters.map { it.returnType }, returnType, analyze { - returnType.requiresMangling() && isKotlin && this@inlineSuffix.containingSymbol is KaClassSymbol + returnType.requiresMangling() && isKotlin && containingDeclaration != null } ) @@ -975,7 +975,16 @@ internal val KaPropertyAccessorSymbol.inlineSuffix: String mangleInlineSuffix( emptyList(), returnType, - returnType.requiresMangling() && isKotlin + analyze { + returnType.requiresMangling() && isKotlin && containingDeclaration?.containingDeclaration != null + } ) is KaPropertySetterSymbol -> mangleInlineSuffix(listOf(parameter.returnType), null, false) } + +private val jvmNameClassId = ClassId.fromString("kotlin/jvm/JvmName") +internal fun KaCallableSymbol.explictJvmName(): String? { + return annotations.singleOrNull() { + it.classId == jvmNameClassId + }?.arguments?.single()?.expression?.toValue() as? String +}