jean
01/06/2024, 2:46 PMresolverd.resolver.getSymbolsWithAnnotation
Any idea why?
Some context:
@AnnotationA
fun someFun1() = ...
@AnnotationA
fun someFun2() = ...
Those are processed to create an enumeration like
enum class FunAfunctions {
SomeFun1,
SomeFun2,
}
Later I process another annotation which uses this enum as a parameter type
@AnnotationB(FunAfunctions.SomeFun1)
fun anotherFunction() = ...
the thing is while I generate the code associated with AnnotationB
I would like to check if the AnnotationA
associated with is as parameter is a suspending function. For that I was thinking of passing down the Resolver
object to my generator class and call resolverd.resolver.getSymbolsWithAnnotation
like I do to generate the enum, but I always get a empty list as a resultJiaxiang
01/11/2024, 8:37 PMgetSymbolsWithAnnotation
the second time? Is it AnnotationB
?Jiaxiang
01/11/2024, 8:38 PMresolver
object on your own, resolver
are meant to be recreated every round to reflect new changes, old resolver object won’t be able to know what has changed across rounds, besides it also creates memory leak issues.jean
01/11/2024, 10:27 PMjean
01/11/2024, 10:36 PMresolver.getSymbolsWithAnnotation(AnnotationA::class.qualifiedName!!)
to generate an enum file. Will the resolver return anything when I call it a second time later on during the generation of code for annotation AnnotationB
? Does it has some sort of logic checking if some code was generated after resolving the annotation to not return the annotated code later?Jiaxiang
01/11/2024, 10:38 PMjean
01/11/2024, 11:04 PM// Created based on @AnnotationA
// the enum exposed to the consumer of the generated code
enum class FunAfunctions {
SomeFun1,
SomeFun2,
}
// internal enum to use when generating code for AnnotationB
internal enum class FunAfunctionsMetadata(val isSuspending: Boolean) {
SomeFun1(false),
SomeFun2(true),
}
And then when I process an AnnotationB
I should get a hold on the generated FunAfunctionsMetadata
? But is that possible since the code inside my generator probably don’t have access to generated code?jean
01/11/2024, 11:11 PMClassName(MY_PACKAGE, "FunAfunctionsMetadata")
and somehow convert the ClassName
type to the actual FunAfunctionsMetadata
type so I can access FunAfunctionsMetadata.SomeFun1.isSuspending
? Is that possible?Jiaxiang
01/12/2024, 12:03 AMFunAfunctionsMetadata
being on classpath which is not possible due to this is generated. For checking if a function is suspend function, you can check KSFunctionDeclaration.modifiers
contains SUSPEND
jean
01/12/2024, 6:31 AMKSFunctionDeclaration
I use resolver.getSymbolsWithAnnotations
but it returns nothing since I already generated the enum beforejean
01/12/2024, 6:33 AMresolver.getKClassDeclarationByName
works? It does return the class declaration of the generated code. I need to see if I can read the data inside the generated enum that way though.Jiaxiang
01/12/2024, 7:10 PMresolver.getSymbolsWithAnnotations
returned nothing part, do you have a reproduce case?jean
01/12/2024, 8:21 PMjean
01/12/2024, 8:22 PM