Search code examples
javajava-native-interfaceannotation-processingtypedescriptor

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.


Solution

  • 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);