KT-2752: add hash-based suffix to private members of open/abstract public classes
This commit is contained in:
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject
|
import org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEnumValueOfMethod
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isEnumValueOfMethod
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -184,12 +185,17 @@ class NameSuggestion {
|
|||||||
if (nativeName != null) return Pair(nativeName, true)
|
if (nativeName != null) return Pair(nativeName, true)
|
||||||
|
|
||||||
val stable = shouldBeStable(descriptor)
|
val stable = shouldBeStable(descriptor)
|
||||||
val finalName = if (overriddenDescriptor is CallableDescriptor && stable) {
|
val finalName = when {
|
||||||
getStableMangledName(baseName, getArgumentTypesAsString(overriddenDescriptor))
|
overriddenDescriptor is CallableDescriptor && stable -> {
|
||||||
}
|
getStableMangledName(baseName, getArgumentTypesAsString(overriddenDescriptor))
|
||||||
else {
|
}
|
||||||
baseName
|
shouldMangleUnstable(overriddenDescriptor) -> {
|
||||||
|
val ownerName = descriptor.containingDeclaration!!.fqNameUnsafe.asString()
|
||||||
|
getStableMangledName(baseName, ownerName + ":" + getArgumentTypesAsString(overriddenDescriptor as CallableDescriptor))
|
||||||
|
}
|
||||||
|
else -> baseName
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pair(finalName, stable)
|
return Pair(finalName, stable)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +212,20 @@ class NameSuggestion {
|
|||||||
return argTypes.toString()
|
return argTypes.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sometimes private members of a class can clash with public members of subclasses, therefore we must
|
||||||
|
// mangle them
|
||||||
|
private fun shouldMangleUnstable(descriptor: DeclarationDescriptor): Boolean {
|
||||||
|
if (descriptor is ClassDescriptor) return false
|
||||||
|
if (DescriptorUtils.isDescriptorWithLocalVisibility(descriptor)) return false
|
||||||
|
|
||||||
|
val containingClass = DescriptorUtils.getContainingClass(descriptor)
|
||||||
|
if (containingClass != null && descriptor is CallableMemberDescriptor && !descriptor.isOverridable) {
|
||||||
|
return containingClass.visibility.isPublicAPI
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun getStableMangledName(suggestedName: String, forCalculateId: String): String {
|
fun getStableMangledName(suggestedName: String, forCalculateId: String): String {
|
||||||
val suffix = if (forCalculateId.isEmpty()) "" else "_${mangledId(forCalculateId)}\$"
|
val suffix = if (forCalculateId.isEmpty()) "" else "_${mangledId(forCalculateId)}\$"
|
||||||
return suggestedName + suffix
|
return suggestedName + suffix
|
||||||
|
|||||||
Reference in New Issue
Block a user