K2 UAST: lookup declarations mangled due to value class

^KT-65653 fixed
This commit is contained in:
Jinseong Jeon
2024-02-07 21:27:43 -08:00
committed by teamcity
parent 7e65f125cc
commit 460339870a
3 changed files with 18 additions and 4 deletions
@@ -1,2 +1,2 @@
Resolved to:
PsiMethod:getColor(): PsiType:Color
PsiMethod:getColor-ywy1UOY(): PsiType:int
@@ -1,2 +1,2 @@
Resolved to:
PsiMethod:ColorProvider(resId: PsiType:int): PsiType:ColorProvider
PsiMethod:ColorProvider-MpdQY78(color: PsiType:int): PsiType:ColorProvider
@@ -86,7 +86,11 @@ private class KotlinStaticPsiDeclarationFromBinaryModuleProvider(
// E.g., getJVM_FIELD -> JVM_FIELD
nameWithoutPrefix == id ||
// E.g., getFooBar -> FooBar -> fooBar
nameWithoutPrefix.decapitalizeSmart().endsWith(id)
nameWithoutPrefix.decapitalizeSmart().let { decapitalizedPrefix ->
decapitalizedPrefix.endsWith(id) ||
// value class mangling: getColor-hash
isValueClassMangled(decapitalizedPrefix, id)
}
}
}.toList()
}
@@ -102,12 +106,22 @@ private class KotlinStaticPsiDeclarationFromBinaryModuleProvider(
val classes = callableId.classId?.let { classId ->
getClassesByClassId(classId)
} ?: getClassesInPackage(callableId.packageName)
val id = callableId.callableName.identifier
return classes.flatMap { psiClass ->
psiClass.methods.filter { psiMethod ->
psiMethod.name == callableId.callableName.identifier
psiMethod.name == id ||
// value class mangling: functionName-hash
isValueClassMangled(psiMethod.name, id)
}
}.toList()
}
private fun isValueClassMangled(name: String, prefix: String): Boolean {
// A memory optimization for `name.startsWith("$prefix-")`, see KT-63486
return name.length > prefix.length &&
name[prefix.length] == '-' &&
name.startsWith(prefix)
}
}
class KotlinStaticPsiDeclarationProviderFactory(