From b53c618559b7ecc6f366ab504d2490af578a6be0 Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Sun, 11 Aug 2024 18:52:10 +0200 Subject: [PATCH] Revert breaking change --- ksp/src/main/kotlin/TypeResolvers.kt | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ksp/src/main/kotlin/TypeResolvers.kt b/ksp/src/main/kotlin/TypeResolvers.kt index 4b24b97..e50a161 100644 --- a/ksp/src/main/kotlin/TypeResolvers.kt +++ b/ksp/src/main/kotlin/TypeResolvers.kt @@ -19,13 +19,34 @@ import com.google.devtools.ksp.symbol.* public inline fun Resolver.getSymbolsWithAnnotation(inDepth: Boolean = false): Sequence = getSymbolsWithAnnotation(A::class.qualifiedName!!, inDepth) +/** + * Returns all [KSAnnotations][KSAnnotation] from [A]. + * + * @see getAnnotationsByType + */ +public inline fun KSAnnotated.getAnnotationsByType(): Sequence { + val annotationKClass = A::class + return this.annotations.filter { + it.shortName.getShortName() == annotationKClass.simpleName && it.annotationType.resolve().declaration + .qualifiedName?.asString() == annotationKClass.qualifiedName + } +} + +/** + * Returns an [KSAnnotation] from [A]. + * + * @see getAnnotationsByType + */ +public inline fun KSAnnotated.getAnnotationOfType(): A = + getAnnotationsOfType().first() + /** * Returns all [KSAnnotations][KSAnnotation] from [A]. * * @see getAnnotationsByType */ @OptIn(KspExperimental::class) -public inline fun KSAnnotated.getAnnotationsByType(): Sequence = +public inline fun KSAnnotated.getAnnotationsOfType(): Sequence = getAnnotationsByType(A::class) /** @@ -33,7 +54,7 @@ public inline fun KSAnnotated.getAnnotationsByType(): S * * @see getAnnotationsByType */ -public inline fun KSAnnotated.getAnnotationByType(): A = +public inline fun KSAnnotated.getAnnotationByType(): KSAnnotation = getAnnotationsByType().first() /**