java - Generating annotations using JavaPoet -
i writing code generator using javapoet , need put annotation on class
for example :
package some.package import org.hibernate.annotations.cacheconcurrencystrategy; import javax.persistence.entity; import javax.persistence.cache @entity @cache(usage = cacheconcurrencystrategy.nonstrict_read_write) public class someclass { }
my code looks this:
typespec spec = typespec .classbuilder("someclass") .addannotation(entity.class) .addannotation(annotationspec.builder(cache.class) .addmember("usage", "$l", cacheconcurrencystrategy.nonstrict_read_write) .build()) .build()
this code generates class resulting code missing import statement cacheconcurrencystrategy. how can generate code required code outputted?
try this:
typespec spec = typespec .classbuilder("someclass") .addannotation(entity.class) .addannotation(annotationspec.builder(cache.class) .addmember("usage", "$t.$l", cacheconcurrencystrategy.class, cacheconcurrencystrategy.nonstrict_read_write.name()) .build()) .build()
the $t
identifies enum class , $l
enum constant.
Comments
Post a Comment