scalastatic-analysisopal-framework

OPAL: Manually creating an annotated method


in the OPAL framework, is it possible to manually create an annotated method?

I currently have the following code:

Method(0, "signaturePolymorphicMethod",
        MethodDescriptor(ObjectType("java/lang/Object"), VoidType), Seq())

and I want to add the annotation

@java.lang.invoke.MethodHandle$PolymorphicSignature

to this method. How can I do this?


Solution

  • Annotations are generally stored using the JVM's general "Attributes" mechanism.

    In this case the annotation is a non-public inner class of MethodHandle with the "Runtime Retention Policy". Hence, to mark a method as having a "Polymorphic Signature" it is necessary to add the RuntimeVisibibleAnnotations_Attribute to the respective method's attributes table. However, given that the visibility of the annotation is limited to the java.lang.invoke package this is (in this specific case) probably rarely useful. Nevertheless, it is possible to query methods in the respective package