Fix hasAlias check when resolving annotation in ultra-light classes
When trying to estimate if annotation entry might be resolved to a specified fqName we should track the short name from entry itself instead of the short name of desired annotation
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import kotlin.jvm.JvmStatic as JS
|
||||
|
||||
/** should load cls */
|
||||
object O {
|
||||
@JS fun foo() {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
typealias JO = JvmOverloads
|
||||
|
||||
/** should load cls */
|
||||
object O {
|
||||
@JO fun foo(a: Int = 1, b: String = "") {}
|
||||
}
|
||||
|
||||
+7
-2
@@ -92,7 +92,9 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
||||
}
|
||||
|
||||
override fun findAnnotation(owner: KtAnnotated, fqName: FqName): Pair<KtAnnotationEntry, AnnotationDescriptor>? {
|
||||
val candidates = owner.annotationEntries.filter { it.shortName == fqName.shortName() || hasAlias(owner, fqName.shortName()) }
|
||||
val candidates = owner.annotationEntries.filter {
|
||||
it.shortName == fqName.shortName() || owner.containingKtFile.hasAlias(it.shortName)
|
||||
}
|
||||
for (entry in candidates) {
|
||||
val descriptor = analyze(entry).get(BindingContext.ANNOTATION, entry)
|
||||
if (descriptor?.fqName == fqName) {
|
||||
@@ -152,7 +154,10 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
||||
} == true
|
||||
}
|
||||
|
||||
private fun hasAlias(element: KtElement, shortName: Name): Boolean = allAliases(element.containingKtFile)[shortName.asString()] == true
|
||||
private fun KtFile.hasAlias(shortName: Name?): Boolean {
|
||||
if (shortName == null) return false
|
||||
return allAliases(this)[shortName.asString()] == true
|
||||
}
|
||||
|
||||
private fun allAliases(file: KtFile): ConcurrentMap<String, Boolean> = CachedValuesManager.getCachedValue(file) {
|
||||
val importAliases = file.importDirectives.mapNotNull { it.aliasName }.toSet()
|
||||
|
||||
Reference in New Issue
Block a user