Rename: Fix processing of overriding methods with mangled names

#KT-24460 Fixed
This commit is contained in:
Alexey Sedunov
2018-05-30 13:47:40 +03:00
parent eea9113d1c
commit 862dc76ed9
21 changed files with 320 additions and 25 deletions
@@ -44,4 +44,6 @@ interface KtLightMethod : PsiAnnotationMethod, KtLightMember<PsiMethod> {
val isDelegated: Boolean
get() = lightMemberOrigin?.originKind == JvmDeclarationOriginKind.DELEGATION
|| lightMemberOrigin?.originKind == JvmDeclarationOriginKind.CLASS_MEMBER_DELEGATION_TO_DEFAULT_IMPL
val isMangled: Boolean
}
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.asJava.classes.cannotModify
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.propertyNameByAccessor
import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -84,9 +85,17 @@ class KtLightMethodImpl private constructor(
}
}
override val isMangled: Boolean
get() {
val demangledName = KotlinTypeMapper.InternalNameMapper.demangleInternalName(name) ?: return false
val originalName = propertyNameByAccessor(demangledName, this) ?: demangledName
return originalName == kotlinOrigin?.name
}
override fun setName(name: String): PsiElement? {
val jvmNameAnnotation = modifierList.findAnnotation(DescriptorUtils.JVM_NAME.asString())
val newNameForOrigin = propertyNameByAccessor(name, this) ?: name
val demangledName = (if (isMangled) KotlinTypeMapper.InternalNameMapper.demangleInternalName(name) else null) ?: name
val newNameForOrigin = propertyNameByAccessor(demangledName, this) ?: demangledName
if (newNameForOrigin == kotlinOrigin?.name) {
jvmNameAnnotation?.delete()
return this