mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-17 00:21:27 +00:00
Fix for KT-16801: Accessors of @PublishedApi property gets mangled
#KT-16801 Fixed
This commit is contained in:
@@ -961,7 +961,7 @@ public class KotlinTypeMapper {
|
||||
|
||||
if (!(descriptor instanceof ConstructorDescriptor) &&
|
||||
descriptor.getVisibility() == Visibilities.INTERNAL &&
|
||||
!descriptor.getAnnotations().hasAnnotation(KotlinBuiltIns.FQ_NAMES.publishedApi)) {
|
||||
!DescriptorUtilsKt.isPublishedApi(descriptor)) {
|
||||
return name + "$" + NameUtils.sanitizeAsJavaIdentifier(moduleName);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
//WITH_REFLECT
|
||||
class A {
|
||||
@PublishedApi
|
||||
internal fun published() = "OK"
|
||||
internal fun published() = "O"
|
||||
|
||||
inline fun test() = published()
|
||||
@PublishedApi
|
||||
internal var publishedProp = "K"
|
||||
|
||||
inline fun test() = published() + publishedProp
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val clazz = A::class.java
|
||||
if (clazz.getDeclaredMethod("published") == null) return "fail"
|
||||
return "OK"
|
||||
if (clazz.getDeclaredMethod("published") == null) return "fail 1"
|
||||
if (clazz.getDeclaredMethod("getPublishedProp") == null) return "fail 2"
|
||||
if (clazz.getDeclaredMethod("setPublishedProp", String::class.java) == null) return "fail 3"
|
||||
return A().test()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
@kotlin.Metadata
|
||||
public final class A {
|
||||
private @org.jetbrains.annotations.NotNull field publishedProp: java.lang.String
|
||||
public method <init>(): void
|
||||
public final @org.jetbrains.annotations.NotNull method getPublishedProp(): java.lang.String
|
||||
public final @kotlin.PublishedApi @org.jetbrains.annotations.NotNull method published(): java.lang.String
|
||||
public synthetic deprecated static @kotlin.PublishedApi method publishedProp$annotations(): void
|
||||
public final method setPublishedProp(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
|
||||
public final @org.jetbrains.annotations.NotNull method test(): java.lang.String
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.descriptors.EffectiveVisibility.*
|
||||
import org.jetbrains.kotlin.descriptors.RelationToType.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isPublishedApi
|
||||
|
||||
sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = false, val privateApi: Boolean = false) {
|
||||
|
||||
@@ -245,11 +246,6 @@ private fun Visibility.forVisibility(descriptor: DeclarationDescriptor, checkPub
|
||||
else -> throw AssertionError("Visibility $name is not allowed in forVisibility")
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.isPublishedApi(): Boolean {
|
||||
val descriptor = if (this is CallableMemberDescriptor) DescriptorUtils.getDirectMember(this) else this
|
||||
return descriptor.annotations.hasAnnotation(KotlinBuiltIns.FQ_NAMES.publishedApi)
|
||||
}
|
||||
|
||||
fun effectiveVisibility(visibility: Visibility, descriptor: DeclarationDescriptor, checkPublishedApi: Boolean = false) =
|
||||
visibility.forVisibility(descriptor, checkPublishedApi)
|
||||
|
||||
|
||||
@@ -397,3 +397,8 @@ fun ClassDescriptor.getNoArgsConstructor(): ClassConstructorDescriptor? =
|
||||
|
||||
fun ClassDescriptor.getConstructorForEmptyArgumentsList(): List<ClassConstructorDescriptor> =
|
||||
constructors.filter { it.valueParameters.all { it.hasDefaultValue() || it.varargElementType != null } }
|
||||
|
||||
fun DeclarationDescriptor.isPublishedApi(): Boolean {
|
||||
val descriptor = if (this is CallableMemberDescriptor) DescriptorUtils.getDirectMember(this) else this
|
||||
return descriptor.annotations.hasAnnotation(KotlinBuiltIns.FQ_NAMES.publishedApi)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user