Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get type descriptor(JNI style) String from an TypeMirror object (annotation processing)

I would like to get a String like:

Ljava/lang/Class;.getName()Ljava/lang/String;

(JNI style type/method description, or called type descriptor)

from an javax.lang.model.type.TypeMirror object in an AnnotationProcessor. Is there any Convenience method or library, which parses the TypeMirror object and produces a String like above?

I would like to use the String to construct a org.objectweb.asm.Type object from the type descriptor string.

like image 215
Andreas Turban Avatar asked Nov 25 '22 16:11

Andreas Turban


1 Answers

I realize this is nearly a decade old, but I've written a library to add TypeMirror/Element support to the ASM library. See here: https://github.com/soabase/asm-mirror-descriptor - with this library you can now do:

MirrorClassReader reader = new MirrorClassReader(processingEnv, element);
reader.accept(myClassVisitor);  // standard ASM ClassVisitor

or

String signature = SignatureMirrorType.getSignature(processingEnv, element);
like image 95
Randgalt Avatar answered Dec 15 '22 22:12

Randgalt