Hi. I've got a multi-module project with lambda fu...
# ksp
a
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
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
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