don't analyze class repeatedly if we already found an annotated member there
#KT-8557 Fixed
This commit is contained in:
+11
-6
@@ -60,22 +60,27 @@ public class KotlinAnnotatedElementsSearcher : QueryExecutor<PsiModifierListOwne
|
|||||||
companion object {
|
companion object {
|
||||||
private val LOG = Logger.getInstance("#com.intellij.psi.impl.search.AnnotatedMembersSearcher")
|
private val LOG = Logger.getInstance("#com.intellij.psi.impl.search.AnnotatedMembersSearcher")
|
||||||
|
|
||||||
public fun processAnnotatedMembers(annClass: PsiClass, useScope: SearchScope, consumer: (KtDeclaration) -> Boolean): Boolean {
|
public fun processAnnotatedMembers(annClass: PsiClass,
|
||||||
|
useScope: SearchScope,
|
||||||
|
preFilter: (KtAnnotationEntry) -> Boolean = { true },
|
||||||
|
consumer: (KtDeclaration) -> Boolean): Boolean {
|
||||||
assert(annClass.isAnnotationType()) { "Annotation type should be passed to annotated members search" }
|
assert(annClass.isAnnotationType()) { "Annotation type should be passed to annotated members search" }
|
||||||
|
|
||||||
val annotationFQN = annClass.getQualifiedName()
|
val annotationFQN = annClass.getQualifiedName()
|
||||||
assert(annotationFQN != null)
|
assert(annotationFQN != null)
|
||||||
|
|
||||||
for (elt in getKotlinAnnotationCandidates(annClass, useScope)) {
|
val candidates = getKotlinAnnotationCandidates(annClass, useScope)
|
||||||
|
for (elt in candidates) {
|
||||||
if (notKtAnnotationEntry(elt)) continue
|
if (notKtAnnotationEntry(elt)) continue
|
||||||
|
|
||||||
val result = runReadAction(fun(): Boolean {
|
val result = runReadAction(fun(): Boolean {
|
||||||
|
if (elt !is KtAnnotationEntry) return true
|
||||||
|
if (!preFilter(elt)) return true
|
||||||
|
|
||||||
val declaration = elt.getStrictParentOfType<KtDeclaration>() ?: return true
|
val declaration = elt.getStrictParentOfType<KtDeclaration>() ?: return true
|
||||||
|
|
||||||
val annotationEntry = elt as KtAnnotationEntry
|
val context = elt.analyze(BodyResolveMode.PARTIAL)
|
||||||
|
val annotationDescriptor = context.get(BindingContext.ANNOTATION, elt) ?: return true
|
||||||
val context = annotationEntry.analyze(BodyResolveMode.PARTIAL)
|
|
||||||
val annotationDescriptor = context.get(BindingContext.ANNOTATION, annotationEntry) ?: return true
|
|
||||||
|
|
||||||
val descriptor = annotationDescriptor.getType().getConstructor().getDeclarationDescriptor() ?: return true
|
val descriptor = annotationDescriptor.getType().getConstructor().getDeclarationDescriptor() ?: return true
|
||||||
if (!(DescriptorUtils.getFqName(descriptor).asString() == annotationFQN)) return true
|
if (!(DescriptorUtils.getFqName(descriptor).asString() == annotationFQN)) return true
|
||||||
|
|||||||
+6
-4
@@ -34,10 +34,12 @@ class KotlinClassesWithAnnotatedMembersSearcher : ScopedQueryExecutor<PsiClass,
|
|||||||
|
|
||||||
override fun execute(queryParameters: ClassesWithAnnotatedMembersSearch.Parameters, consumer: Processor<PsiClass>): Boolean {
|
override fun execute(queryParameters: ClassesWithAnnotatedMembersSearch.Parameters, consumer: Processor<PsiClass>): Boolean {
|
||||||
val processed = hashSetOf<KtClassOrObject>()
|
val processed = hashSetOf<KtClassOrObject>()
|
||||||
return KotlinAnnotatedElementsSearcher.processAnnotatedMembers(queryParameters.annotationClass, queryParameters.scope) { declaration ->
|
return KotlinAnnotatedElementsSearcher.processAnnotatedMembers(queryParameters.annotationClass,
|
||||||
val jetClass = declaration.getNonStrictParentOfType<KtClassOrObject>()
|
queryParameters.scope,
|
||||||
if (jetClass != null && processed.add(jetClass)) {
|
{ it.getNonStrictParentOfType<KtClassOrObject>() !in processed}) { declaration ->
|
||||||
val lightClass = LightClassUtil.getPsiClass(jetClass)
|
val ktClass = declaration.getNonStrictParentOfType<KtClassOrObject>()
|
||||||
|
if (ktClass != null && processed.add(ktClass)) {
|
||||||
|
val lightClass = LightClassUtil.getPsiClass(ktClass)
|
||||||
if (lightClass != null) consumer.process(lightClass) else true
|
if (lightClass != null) consumer.process(lightClass) else true
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user