jean
08/25/2022, 7:55 PMreturn (argument as Array<KClass<*>>)
.toList()
.all {
resolver.getClassDeclarationByName(it::class.java.simpleName)
?.filterAnnotations<CrossViewEvent>()
?.toList()
?.isNotEmpty() ?: false
}
is it possible to convert a KClass to a KSType without using the resolver?David Rawson
08/25/2022, 8:15 PMArray<KClass<*>> from? How are the annotations you are using in your processor defined?Ting-Yuan Huang
08/25/2022, 8:16 PMgetSymbolsWithAnnotation is about.jean
08/25/2022, 8:31 PM@CrossViewEvent
data class LoadStudents(val offset: Int, val limit: Int)
@CrossViewEvent
data class LoadTeachers(val offset: Int, val limit: Int)
--------------
@ViewEventsBuilder(
crossViewEvents = [
LoadStudents::class,
LoadTeachers::class,
]
)
sealed class SchoolViewEventsBuilder
Now I want to check that every class listed inside the crossViewEvents parameter is annotated with CrossViewEvent.
In the previous code block I shared, the code resides in a validator class that doesn’t directly have a reference to a Resolver. So I pass it from the processor to the validator and don’t know if that’s a bad practice or not. Then argument refers to crossViewEvents. I get the variable with this code:
val argumentType = (viewEventsBuilderAnnotation?.arguments?.first()?.value as? KSType)
val argument = argumentType?.declaration as? KSClassDeclarationDavid Rawson
08/25/2022, 8:51 PMresolver.getSymbolsWithAnnotation("ViewEventsBuilder")
.first() // SchoolViewEventsBuilder
.annotations
.first() // ViewEventsBuilder
.arguments
.first() // crossViewEvents
I am seeing the crossViewEvents argument of the @ViewEventsBuilder is a List<KSType> rather than an Array<KClass<*>> . Since the elements in the list are already resolved to a KSType, this would mean you wouldn’t have to resolve them againjean
08/25/2022, 9:06 PMList<KSType>, nice!