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() /**