https://kotlinlang.org logo
#ksp
Title
# ksp
a

Adrian Witaszak

03/28/2024, 5:57 PM
Hi. I've got a multi-module project with lambda functions. Each function has a route annotated with
@Route
, in the OpenApi module i want to pickup those annotations to generate the spec. The issue is that if i apply the processor to the openApi module it sees its only module but not submodules. Is there any trick for it?
Copy code
- annotation
- processor
- open-api // here i need to generate code. Processor applied here
- function // lambda functions here
  - getHello // here i use the annotation
  - addHello // here i use the annotation
t

Ting-Yuan Huang

03/28/2024, 6:23 PM
KSP focuses on the current compilation unit:
Resolver.getSymboslWithAnnotation
returns elements from the current module only. To work it around, traversing all elements from
Resolver.getDeclarationsFromPackage
in the root module (that depend on all sub modules) and checks the annotations manually might be feasible if the project isn't too large.
a

Adrian Witaszak

03/29/2024, 10:00 AM
Thank you @Ting-Yuan Huang it works like a treat.
Copy code
val routes = resolver
            .getDeclarationsFromPackage("")
            .filterIsInstance<KSClassDeclaration>()
            .filter { classDeclaration ->
                classDeclaration.annotations.any { annotation ->
                    annotation.shortName.asString() == Route::class.simpleName
                }
            }
The new issue I have now is that newfound annotation overrides the previous one, but i will get this fixed