I'm writing an annotation processor that runs within javac.
It scans annotated classes and produces a resource file that contains class names.
These names will by used at runtime to be able to get the Class<?>
thanks to Class.forName(String)
.
How to get the class name (e.g. pgk1.pkg2.Foo$Bar) from a javax.lang.model.element.TypeElement
.
Tips: I need neither the simple name (e.g. Bar), nor the qualified name (e.g. pgk1.pkg2.Foo.Bar).
The annotation processor is initialized by the compiler and receives a ProcessingEnvironment
instance.
The method Name ProcessingEnvironment.getElementUtils().getBinaryName(TypeElement)
returns a binary name that can be used to instanciate the class later on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With