diff --git a/compiler/frontend/src/org/jetbrains/kotlin/extensions/AnnotationBasedExtension.kt b/compiler/frontend/src/org/jetbrains/kotlin/extensions/AnnotationBasedExtension.kt index 8b8e8a90c35..5a15b313b93 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/extensions/AnnotationBasedExtension.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/extensions/AnnotationBasedExtension.kt @@ -27,12 +27,14 @@ interface AnnotationBasedExtension { fun getAnnotationFqNames(modifierListOwner: KtModifierListOwner?): List fun DeclarationDescriptor.hasSpecialAnnotation(modifierListOwner: KtModifierListOwner?): Boolean { - if (annotations.any { it.isASpecialAnnotation(modifierListOwner) }) return true + val specialAnnotations = getAnnotationFqNames(modifierListOwner).takeIf { it.isNotEmpty() } ?: return false + + if (annotations.any { it.isASpecialAnnotation(specialAnnotations) }) return true if (this is ClassDescriptor) { for (superType in TypeUtils.getAllSupertypes(defaultType)) { val superTypeDescriptor = superType.constructor.declarationDescriptor as? ClassDescriptor ?: continue - if (superTypeDescriptor.annotations.any { it.isASpecialAnnotation(modifierListOwner) }) return true + if (superTypeDescriptor.annotations.any { it.isASpecialAnnotation(specialAnnotations) }) return true } } @@ -40,20 +42,20 @@ interface AnnotationBasedExtension { } private fun AnnotationDescriptor.isASpecialAnnotation( - modifierListOwner: KtModifierListOwner?, + specialAnnotations: List, visitedAnnotations: MutableSet = hashSetOf(), allowMetaAnnotations: Boolean = true ): Boolean { val annotationFqName = fqName?.asString() ?: return false if (annotationFqName in visitedAnnotations) return false // Prevent infinite recursion - if (annotationFqName in getAnnotationFqNames(modifierListOwner)) return true + if (annotationFqName in specialAnnotations) return true visitedAnnotations.add(annotationFqName) if (allowMetaAnnotations) { val annotationType = annotationClass ?: return false for (metaAnnotation in annotationType.annotations) { - if (metaAnnotation.isASpecialAnnotation(modifierListOwner, visitedAnnotations, allowMetaAnnotations = true)) { + if (metaAnnotation.isASpecialAnnotation(specialAnnotations, visitedAnnotations, allowMetaAnnotations = true)) { return true } }