Generic Definitions on Static Methods #18
-
Thank you for creating this library. I have found it immensely helpful! One thing I haven't wrapped my head around is how to declare a generic type in a static method. For instance, I would like to generate this code:
I can successfully create the method, but
Is there a way to define
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello, Thank you for your feedback! :-) FunctionSourceGenerator.create("builder")
.addModifier(Modifier.PUBLIC | Modifier.STATIC)
.setTypeDeclaration(
TypeDeclarationSourceGenerator.create(
GenericSourceGenerator.create("X")
)
)
.setReturnType(
TypeDeclarationSourceGenerator.create("Builder").addGeneric(GenericSourceGenerator.create("X"))
) For further examples you can also visit the |
Beta Was this translation helpful? Give feedback.
-
Thank you so much! |
Beta Was this translation helpful? Give feedback.
Hello, Thank you for your feedback! :-)
To solve your problem you need to call
FunctionSourceGenerator
'ssetTypeDeclaration
method as follow:For further examples you can also visit the
UnitSourceGeneratorTest
class that contains a series of tests that together represent a complete example of what you can do with source generators.