Skip to content

Commit

Permalink
Revert breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Aug 11, 2024
1 parent a40ddba commit b53c618
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions ksp/src/main/kotlin/TypeResolvers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,42 @@ import com.google.devtools.ksp.symbol.*
public inline fun <reified A : Annotation> Resolver.getSymbolsWithAnnotation(inDepth: Boolean = false): Sequence<KSAnnotated> =
getSymbolsWithAnnotation(A::class.qualifiedName!!, inDepth)

/**
* Returns all [KSAnnotations][KSAnnotation] from [A].
*
* @see getAnnotationsByType
*/
public inline fun <reified A : Annotation> KSAnnotated.getAnnotationsByType(): Sequence<KSAnnotation> {
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 <reified A : Annotation> KSAnnotated.getAnnotationOfType(): A =
getAnnotationsOfType<A>().first()

/**
* Returns all [KSAnnotations][KSAnnotation] from [A].
*
* @see getAnnotationsByType
*/
@OptIn(KspExperimental::class)
public inline fun <reified A : Annotation> KSAnnotated.getAnnotationsByType(): Sequence<A> =
public inline fun <reified A : Annotation> KSAnnotated.getAnnotationsOfType(): Sequence<A> =
getAnnotationsByType(A::class)

/**
* Returns an [KSAnnotation] from [A].
*
* @see getAnnotationsByType
*/
public inline fun <reified A : Annotation> KSAnnotated.getAnnotationByType(): A =
public inline fun <reified A : Annotation> KSAnnotated.getAnnotationByType(): KSAnnotation =
getAnnotationsByType<A>().first()

/**
Expand Down

0 comments on commit b53c618

Please sign in to comment.