Package org.spongepowered.asm.util

## Class Annotations

- java.lang.Object
- - org.spongepowered.asm.util.Annotations

-     public final class Annotations
      extends java.lang.Object

  Utility class for working with ASM annotations

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `Annotations.Handle` | Wrapper for `AnnotationNode` to support access via common interface

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static org.objectweb.asm.tree.AnnotationNode` | `get​(java.util.List<org.objectweb.asm.tree.AnnotationNode> annotations, java.lang.String annotationType)` | Search for and return an annotation node matching the specified type within the supplied collection of annotation nodes
    `static java.lang.String` | `getDesc​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)` | Returns the bytecode descriptor of an annotation
    `static org.objectweb.asm.tree.AnnotationNode` | `getInvisible​(org.objectweb.asm.tree.ClassNode classNode, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)` | Get an invisible annotation of the specified class from the supplied class node
    `static org.objectweb.asm.tree.AnnotationNode` | `getInvisible​(org.objectweb.asm.tree.FieldNode field, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)` | Get an invisible annotation of the specified class from the supplied field node
    `static org.objectweb.asm.tree.AnnotationNode` | `getInvisible​(org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)` | Get an invisible annotation of the specified class from the supplied method node
    `static org.objectweb.asm.tree.AnnotationNode` | `getInvisibleParameter​(org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, int paramIndex)` | Get an invisible parameter annotation of the specified class from the supplied method node
    `static org.objectweb.asm.tree.AnnotationNode` | `getParameter​(java.util.List<org.objectweb.asm.tree.AnnotationNode>[] parameterAnnotations, java.lang.String annotationType, int paramIndex)` | Get a parameter annotation of the specified class from the supplied method node
    `static java.lang.String` | `getSimpleName​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)` | Returns the simple name of an annotation, mainly used for printing annotation names in error messages/user-facing strings
    `static java.lang.String` | `getSimpleName​(org.objectweb.asm.tree.AnnotationNode annotation)` | Returns the simple name of an annotation, mainly used for printing annotation names in error messages/user-facing strings
    `static org.objectweb.asm.tree.AnnotationNode` | `getSingleInvisible​(org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation>... annotationClasses)` | Get an invisible annotation of the specified class from the supplied method node
    `static org.objectweb.asm.tree.AnnotationNode` | `getSingleVisible​(org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation>... annotationClasses)` | Get a runtime-visible annotation of the specified class from the supplied method node
    `static <T> T` | `getValue​(org.objectweb.asm.tree.AnnotationNode annotation)` | Duck type the "value" entry (if any) of the specified annotation node
    `static <T> T` | `getValue​(org.objectweb.asm.tree.AnnotationNode annotation, java.lang.String key)` | Get the value of an annotation node and do pseudo-duck-typing via Java's crappy generics
    `static <T> java.util.List<T>` | `getValue​(org.objectweb.asm.tree.AnnotationNode annotation, java.lang.String key, boolean notNull)` | Return the specified annotation node value as a list of nodes
    `static <T extends java.lang.Enum<T>> java.util.List<T>` | `getValue​(org.objectweb.asm.tree.AnnotationNode annotation, java.lang.String key, boolean notNull, java.lang.Class<T> enumClass)` | Return the specified annotation node value as a list of enums
    `static <T> T` | `getValue​(org.objectweb.asm.tree.AnnotationNode annotation, java.lang.String key, java.lang.Class<?> annotationClass)` | Gets an annotation value or returns the default value of the annotation if the annotation value is not present
    `static <T extends java.lang.Enum<T>> T` | `getValue​(org.objectweb.asm.tree.AnnotationNode annotation, java.lang.String key, java.lang.Class<T> enumClass, T defaultValue)` | Get the value of an annotation node as the specified enum, returns defaultValue if the annotation value is not set
    `static <T> T` | `getValue​(org.objectweb.asm.tree.AnnotationNode annotation, java.lang.String key, T defaultValue)` | Get the value of an annotation node and do pseudo-duck-typing via Java's crappy generics
    `static org.objectweb.asm.tree.AnnotationNode` | `getVisible​(org.objectweb.asm.tree.ClassNode classNode, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)` | Get a runtime-visible annotation of the specified class from the supplied class node
    `static org.objectweb.asm.tree.AnnotationNode` | `getVisible​(org.objectweb.asm.tree.FieldNode field, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)` | Get a runtime-visible annotation of the specified class from the supplied field node
    `static org.objectweb.asm.tree.AnnotationNode` | `getVisible​(org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)` | Get a runtime-visible annotation of the specified class from the supplied method node
    `static org.objectweb.asm.tree.AnnotationNode` | `getVisibleParameter​(org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, int paramIndex)` | Get a runtime-visible parameter annotation of the specified class from the supplied method node
    `static IAnnotationHandle` | `handleOf​(java.lang.Object annotation)` | Get the supplied annotation object as an annotation handle
    `static void` | `merge​(org.objectweb.asm.tree.ClassNode from, org.objectweb.asm.tree.ClassNode to)` | Merge annotations from the specified source ClassNode to the destination ClassNode, replaces annotations of the equivalent type on the target with annotations from the source.
    `static void` | `merge​(org.objectweb.asm.tree.FieldNode from, org.objectweb.asm.tree.FieldNode to)` | Merge annotations from the specified source FieldNode to the destination FieldNode, replaces annotations of the equivalent type on the target with annotations from the source.
    `static void` | `merge​(org.objectweb.asm.tree.MethodNode from, org.objectweb.asm.tree.MethodNode to)` | Merge annotations from the specified source MethodNode to the destination MethodNode, replaces annotations of the equivalent type on the target with annotations from the source.
    `static void` | `setInvisible​(org.objectweb.asm.tree.FieldNode field, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Object... value)` | Set an invisible annotation of the specified class on the supplied field node
    `static void` | `setInvisible​(org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Object... value)` | Set a invisible annotation of the specified class on the supplied method node
    `static void` | `setValue​(org.objectweb.asm.tree.AnnotationNode annotation, java.lang.String key, java.lang.Object value)` | Set the value of an annotation node and do pseudo-duck-typing via Java's crappy generics
    `static void` | `setVisible​(org.objectweb.asm.tree.FieldNode field, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Object... value)` | Set a runtime-visible annotation of the specified class on the supplied field node
    `static void` | `setVisible​(org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Object... value)` | Set a runtime-visible annotation of the specified class on the supplied method node

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### handleOf

          public static IAnnotationHandle handleOf​(java.lang.Object annotation)

      Get the supplied annotation object as an annotation handle
      Parameters:
        `annotation` - Annotation to return
      Returns:
        Wrapped or cast annotation

    - #### getDesc

          public static java.lang.String getDesc​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)

      Returns the bytecode descriptor of an annotation
      Parameters:
        `annotationType` - annotation
      Returns:
        annotation's descriptor

    - #### getSimpleName

          public static java.lang.String getSimpleName​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)

      Returns the simple name of an annotation, mainly used for printing annotation names in error messages/user-facing strings
      Parameters:
        `annotationType` - annotation
      Returns:
        annotation's simple name

    - #### getSimpleName

          public static java.lang.String getSimpleName​(org.objectweb.asm.tree.AnnotationNode annotation)

      Returns the simple name of an annotation, mainly used for printing annotation names in error messages/user-facing strings
      Parameters:
        `annotation` - annotation node
      Returns:
        annotation's simple name

    - #### setVisible

          public static void setVisible​(org.objectweb.asm.tree.FieldNode field,
                                        java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                        java.lang.Object... value)

      Set a runtime-visible annotation of the specified class on the supplied field node
      Parameters:
        `field` - Target field
        `annotationClass` - Type of annotation to search for
        `value` - Values (interleaved key/value pairs) to set

    - #### setInvisible

          public static void setInvisible​(org.objectweb.asm.tree.FieldNode field,
                                          java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                          java.lang.Object... value)

      Set an invisible annotation of the specified class on the supplied field node
      Parameters:
        `field` - Target field
        `annotationClass` - Type of annotation to search for
        `value` - Values (interleaved key/value pairs) to set

    - #### setVisible

          public static void setVisible​(org.objectweb.asm.tree.MethodNode method,
                                        java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                        java.lang.Object... value)

      Set a runtime-visible annotation of the specified class on the supplied method node
      Parameters:
        `method` - Target method
        `annotationClass` - Type of annotation to search for
        `value` - Values (interleaved key/value pairs) to set

    - #### setInvisible

          public static void setInvisible​(org.objectweb.asm.tree.MethodNode method,
                                          java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                          java.lang.Object... value)

      Set a invisible annotation of the specified class on the supplied method node
      Parameters:
        `method` - Target method
        `annotationClass` - Type of annotation to search for
        `value` - Values (interleaved key/value pairs) to set

    - #### getVisible

          public static org.objectweb.asm.tree.AnnotationNode getVisible​(org.objectweb.asm.tree.FieldNode field,
                                                                         java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)

      Get a runtime-visible annotation of the specified class from the supplied field node
      Parameters:
        `field` - Source field
        `annotationClass` - Type of annotation to search for
      Returns:
        the annotation, or null if not present

    - #### getInvisible

          public static org.objectweb.asm.tree.AnnotationNode getInvisible​(org.objectweb.asm.tree.FieldNode field,
                                                                           java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)

      Get an invisible annotation of the specified class from the supplied field node
      Parameters:
        `field` - Source field
        `annotationClass` - Type of annotation to search for
      Returns:
        the annotation, or null if not present

    - #### getVisible

          public static org.objectweb.asm.tree.AnnotationNode getVisible​(org.objectweb.asm.tree.MethodNode method,
                                                                         java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)

      Get a runtime-visible annotation of the specified class from the supplied method node
      Parameters:
        `method` - Source method
        `annotationClass` - Type of annotation to search for
      Returns:
        the annotation, or null if not present

    - #### getInvisible

          public static org.objectweb.asm.tree.AnnotationNode getInvisible​(org.objectweb.asm.tree.MethodNode method,
                                                                           java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)

      Get an invisible annotation of the specified class from the supplied method node
      Parameters:
        `method` - Source method
        `annotationClass` - Type of annotation to search for
      Returns:
        the annotation, or null if not present

    - #### getSingleVisible

          public static org.objectweb.asm.tree.AnnotationNode getSingleVisible​(org.objectweb.asm.tree.MethodNode method,
                                                                               java.lang.Class<? extends java.lang.annotation.Annotation>... annotationClasses)

      Get a runtime-visible annotation of the specified class from the supplied method node
      Parameters:
        `method` - Source method
        `annotationClasses` - Types of annotation to search for
      Returns:
        the annotation, or null if not present

    - #### getSingleInvisible

          public static org.objectweb.asm.tree.AnnotationNode getSingleInvisible​(org.objectweb.asm.tree.MethodNode method,
                                                                                 java.lang.Class<? extends java.lang.annotation.Annotation>... annotationClasses)

      Get an invisible annotation of the specified class from the supplied method node
      Parameters:
        `method` - Source method
        `annotationClasses` - Types of annotation to search for
      Returns:
        the annotation, or null if not present

    - #### getVisible

          public static org.objectweb.asm.tree.AnnotationNode getVisible​(org.objectweb.asm.tree.ClassNode classNode,
                                                                         java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)

      Get a runtime-visible annotation of the specified class from the supplied class node
      Parameters:
        `classNode` - Source ClassNode
        `annotationClass` - Type of annotation to search for
      Returns:
        the annotation, or null if not present

    - #### getInvisible

          public static org.objectweb.asm.tree.AnnotationNode getInvisible​(org.objectweb.asm.tree.ClassNode classNode,
                                                                           java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)

      Get an invisible annotation of the specified class from the supplied class node
      Parameters:
        `classNode` - Source ClassNode
        `annotationClass` - Type of annotation to search for
      Returns:
        the annotation, or null if not present

    - #### getVisibleParameter

          public static org.objectweb.asm.tree.AnnotationNode getVisibleParameter​(org.objectweb.asm.tree.MethodNode method,
                                                                                  java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                                                                  int paramIndex)

      Get a runtime-visible parameter annotation of the specified class from the supplied method node
      Parameters:
        `method` - Source method
        `annotationClass` - Type of annotation to search for
        `paramIndex` - Index of the parameter to fetch annotation for, or the method itself if less than zero
      Returns:
        the annotation, or null if not present

    - #### getInvisibleParameter

          public static org.objectweb.asm.tree.AnnotationNode getInvisibleParameter​(org.objectweb.asm.tree.MethodNode method,
                                                                                    java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                                                                    int paramIndex)

      Get an invisible parameter annotation of the specified class from the supplied method node
      Parameters:
        `method` - Source method
        `annotationClass` - Type of annotation to search for
        `paramIndex` - Index of the parameter to fetch annotation for, or the method itself if less than zero
      Returns:
        the annotation, or null if not present

    - #### getParameter

          public static org.objectweb.asm.tree.AnnotationNode getParameter​(java.util.List<org.objectweb.asm.tree.AnnotationNode>[] parameterAnnotations,
                                                                           java.lang.String annotationType,
                                                                           int paramIndex)

      Get a parameter annotation of the specified class from the supplied method node
      Parameters:
        `parameterAnnotations` - Annotations for the parameter
        `annotationType` - Type of annotation to search for
        `paramIndex` - Index of the parameter to fetch annotation for
      Returns:
        the annotation, or null if not present

    - #### get

          public static org.objectweb.asm.tree.AnnotationNode get​(java.util.List<org.objectweb.asm.tree.AnnotationNode> annotations,
                                                                  java.lang.String annotationType)

      Search for and return an annotation node matching the specified type within the supplied collection of annotation nodes
      Parameters:
        `annotations` - Haystack
        `annotationType` - Needle
      Returns:
        matching annotation node or null if the annotation doesn't exist

    - #### getValue

          public static <T> T getValue​(org.objectweb.asm.tree.AnnotationNode annotation)

      Duck type the "value" entry (if any) of the specified annotation node
      Type Parameters:
        `T` - duck type
      Parameters:
        `annotation` - Annotation node to query
      Returns:
        duck-typed annotation value, null if missing, or inevitable `ClassCastException` if your duck is actually a rooster

    - #### getValue

          public static <T> T getValue​(org.objectweb.asm.tree.AnnotationNode annotation,
                                       java.lang.String key,
                                       T defaultValue)

      Get the value of an annotation node and do pseudo-duck-typing via Java's crappy generics
      Type Parameters:
        `T` - duck type
      Parameters:
        `annotation` - Annotation node to query
        `key` - Key to search for
        `defaultValue` - Value to return if the specified key is not found or is null
      Returns:
        duck-typed annotation value, null if missing, or inevitable `ClassCastException` if your duck is actually a rooster

    - #### getValue

          public static <T> T getValue​(org.objectweb.asm.tree.AnnotationNode annotation,
                                       java.lang.String key,
                                       java.lang.Class<?> annotationClass)

      Gets an annotation value or returns the default value of the annotation if the annotation value is not present
      Type Parameters:
        `T` - duck type
      Parameters:
        `annotation` - Annotation node to query
        `key` - Key to search for
        `annotationClass` - Annotation class to query reflectively for the default value
      Returns:
        Value of the specified annotation node, default value if not specified, or null if no value or default

    - #### getValue

          public static <T> T getValue​(org.objectweb.asm.tree.AnnotationNode annotation,
                                       java.lang.String key)

      Get the value of an annotation node and do pseudo-duck-typing via Java's crappy generics
      Type Parameters:
        `T` - duck type
      Parameters:
        `annotation` - Annotation node to query
        `key` - Key to search for
      Returns:
        duck-typed annotation value, null if missing, or inevitable `ClassCastException` if your duck is actually a rooster

    - #### getValue

          public static <T extends java.lang.Enum<T>> T getValue​(org.objectweb.asm.tree.AnnotationNode annotation,
                                                                 java.lang.String key,
                                                                 java.lang.Class<T> enumClass,
                                                                 T defaultValue)

      Get the value of an annotation node as the specified enum, returns defaultValue if the annotation value is not set
      Type Parameters:
        `T` - duck type
      Parameters:
        `annotation` - Annotation node to query
        `key` - Key to search for
        `enumClass` - Class of enum containing the enum constant to search for
        `defaultValue` - Value to return if the specified key isn't found
      Returns:
        duck-typed annotation value or defaultValue if missing

    - #### getValue

          public static <T> java.util.List<T> getValue​(org.objectweb.asm.tree.AnnotationNode annotation,
                                                       java.lang.String key,
                                                       boolean notNull)

      Return the specified annotation node value as a list of nodes
      Type Parameters:
        `T` - list element type
      Parameters:
        `annotation` - Annotation node to query
        `key` - Key to search for
        `notNull` - if true, return an empty list instead of null if the annotation value is absent

    - #### getValue

          public static <T extends java.lang.Enum<T>> java.util.List<T> getValue​(org.objectweb.asm.tree.AnnotationNode annotation,
                                                                                 java.lang.String key,
                                                                                 boolean notNull,
                                                                                 java.lang.Class<T> enumClass)

      Return the specified annotation node value as a list of enums
      Type Parameters:
        `T` - list element type
      Parameters:
        `annotation` - Annotation node to query
        `key` - Key to search for
        `notNull` - if true, return an empty list instead of null if the annotation value is absent
        `enumClass` - Class of enum containing the enum constant to use

    - #### setValue

          public static void setValue​(org.objectweb.asm.tree.AnnotationNode annotation,
                                      java.lang.String key,
                                      java.lang.Object value)

      Set the value of an annotation node and do pseudo-duck-typing via Java's crappy generics
      Parameters:
        `annotation` - Annotation node to modify
        `key` - Key to set
        `value` - Value to set `ClassCastException` if your duck is actually a rooster

    - #### merge

          public static void merge​(org.objectweb.asm.tree.ClassNode from,
                                   org.objectweb.asm.tree.ClassNode to)

      Merge annotations from the specified source ClassNode to the destination ClassNode, replaces annotations of the equivalent type on the target with annotations from the source. If the source node has no annotations then no action will take place, if the target node has no annotations then a new annotation list will be created. Annotations from the mixin package are not merged.
      Parameters:
        `from` - ClassNode to merge annotations from
        `to` - ClassNode to merge annotations to

    - #### merge

          public static void merge​(org.objectweb.asm.tree.MethodNode from,
                                   org.objectweb.asm.tree.MethodNode to)

      Merge annotations from the specified source MethodNode to the destination MethodNode, replaces annotations of the equivalent type on the target with annotations from the source. If the source node has no annotations then no action will take place, if the target node has no annotations then a new annotation list will be created. Annotations from the mixin package are not merged.
      Parameters:
        `from` - MethodNode to merge annotations from
        `to` - MethodNode to merge annotations to

    - #### merge

          public static void merge​(org.objectweb.asm.tree.FieldNode from,
                                   org.objectweb.asm.tree.FieldNode to)

      Merge annotations from the specified source FieldNode to the destination FieldNode, replaces annotations of the equivalent type on the target with annotations from the source. If the source node has no annotations then no action will take place, if the target node has no annotations then a new annotation list will be created. Annotations from the mixin package are not merged.
      Parameters:
        `from` - FieldNode to merge annotations from
        `to` - FieldNode to merge annotations to