Package org.spongepowered.asm.util
Class Annotations
java.lang.Object
org.spongepowered.asm.util.Annotations
Utility class for working with ASM annotations
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classWrapper forAnnotationNodeto support access via common interface -
Method Summary
Modifier and TypeMethodDescriptionstatic org.objectweb.asm.tree.AnnotationNodeSearch for and return an annotation node matching the specified type within the supplied collection of annotation nodesstatic StringgetDesc(Class<? extends Annotation> annotationType) Returns the bytecode descriptor of an annotationstatic org.objectweb.asm.tree.AnnotationNodegetInvisible(org.objectweb.asm.tree.ClassNode classNode, Class<? extends Annotation> annotationClass) Get an invisible annotation of the specified class from the supplied class nodestatic org.objectweb.asm.tree.AnnotationNodegetInvisible(org.objectweb.asm.tree.FieldNode field, Class<? extends Annotation> annotationClass) Get an invisible annotation of the specified class from the supplied field nodestatic org.objectweb.asm.tree.AnnotationNodegetInvisible(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation> annotationClass) Get an invisible annotation of the specified class from the supplied method nodestatic org.objectweb.asm.tree.AnnotationNodegetInvisibleParameter(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation> annotationClass, int paramIndex) Get an invisible parameter annotation of the specified class from the supplied method nodestatic org.objectweb.asm.tree.AnnotationNodegetParameter(List<org.objectweb.asm.tree.AnnotationNode>[] parameterAnnotations, String annotationType, int paramIndex) Get a parameter annotation of the specified class from the supplied method nodestatic StringgetSimpleName(Class<? extends Annotation> annotationType) Returns the simple name of an annotation, mainly used for printing annotation names in error messages/user-facing stringsstatic StringgetSimpleName(org.objectweb.asm.tree.AnnotationNode annotation) Returns the simple name of an annotation, mainly used for printing annotation names in error messages/user-facing stringsstatic org.objectweb.asm.tree.AnnotationNodegetSingleInvisible(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation>... annotationClasses) Get an invisible annotation of the specified class from the supplied method nodestatic org.objectweb.asm.tree.AnnotationNodegetSingleVisible(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation>... annotationClasses) Get a runtime-visible annotation of the specified class from the supplied method nodestatic <T> TgetValue(org.objectweb.asm.tree.AnnotationNode annotation) Duck type the "value" entry (if any) of the specified annotation nodestatic <T> TGet the value of an annotation node and do pseudo-duck-typing via Java's crappy genericsstatic <T> List<T> Return the specified annotation node value as a list of nodesgetValue(org.objectweb.asm.tree.AnnotationNode annotation, String key, boolean notNull, Class<T> enumClass) Return the specified annotation node value as a list of enumsstatic <T> TGets an annotation value or returns the default value of the annotation if the annotation value is not presentstatic <T extends Enum<T>>
TgetValue(org.objectweb.asm.tree.AnnotationNode annotation, String key, Class<T> enumClass, T defaultValue) Get the value of an annotation node as the specified enum, returns defaultValue if the annotation value is not setstatic <T> TGet the value of an annotation node and do pseudo-duck-typing via Java's crappy genericsstatic org.objectweb.asm.tree.AnnotationNodegetVisible(org.objectweb.asm.tree.ClassNode classNode, Class<? extends Annotation> annotationClass) Get a runtime-visible annotation of the specified class from the supplied class nodestatic org.objectweb.asm.tree.AnnotationNodegetVisible(org.objectweb.asm.tree.FieldNode field, Class<? extends Annotation> annotationClass) Get a runtime-visible annotation of the specified class from the supplied field nodestatic org.objectweb.asm.tree.AnnotationNodegetVisible(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation> annotationClass) Get a runtime-visible annotation of the specified class from the supplied method nodestatic org.objectweb.asm.tree.AnnotationNodegetVisibleParameter(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation> annotationClass, int paramIndex) Get a runtime-visible parameter annotation of the specified class from the supplied method nodestatic IAnnotationHandleGet the supplied annotation object as an annotation handlestatic voidmerge(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 voidmerge(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 voidmerge(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 voidsetInvisible(org.objectweb.asm.tree.FieldNode field, Class<? extends Annotation> annotationClass, Object... value) Set an invisible annotation of the specified class on the supplied field nodestatic voidsetInvisible(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation> annotationClass, Object... value) Set a invisible annotation of the specified class on the supplied method nodestatic voidSet the value of an annotation node and do pseudo-duck-typing via Java's crappy genericsstatic voidsetVisible(org.objectweb.asm.tree.FieldNode field, Class<? extends Annotation> annotationClass, Object... value) Set a runtime-visible annotation of the specified class on the supplied field nodestatic voidsetVisible(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation> annotationClass, Object... value) Set a runtime-visible annotation of the specified class on the supplied method node
-
Method Details
-
handleOf
Get the supplied annotation object as an annotation handle- Parameters:
annotation- Annotation to return- Returns:
- Wrapped or cast annotation
-
getDesc
Returns the bytecode descriptor of an annotation- Parameters:
annotationType- annotation- Returns:
- annotation's descriptor
-
getSimpleName
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
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, Class<? extends Annotation> annotationClass, Object... value) Set a runtime-visible annotation of the specified class on the supplied field node- Parameters:
field- Target fieldannotationClass- Type of annotation to search forvalue- Values (interleaved key/value pairs) to set
-
setInvisible
public static void setInvisible(org.objectweb.asm.tree.FieldNode field, Class<? extends Annotation> annotationClass, Object... value) Set an invisible annotation of the specified class on the supplied field node- Parameters:
field- Target fieldannotationClass- Type of annotation to search forvalue- Values (interleaved key/value pairs) to set
-
setVisible
public static void setVisible(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation> annotationClass, Object... value) Set a runtime-visible annotation of the specified class on the supplied method node- Parameters:
method- Target methodannotationClass- Type of annotation to search forvalue- Values (interleaved key/value pairs) to set
-
setInvisible
public static void setInvisible(org.objectweb.asm.tree.MethodNode method, Class<? extends Annotation> annotationClass, Object... value) Set a invisible annotation of the specified class on the supplied method node- Parameters:
method- Target methodannotationClass- Type of annotation to search forvalue- Values (interleaved key/value pairs) to set
-
getVisible
public static org.objectweb.asm.tree.AnnotationNode getVisible(org.objectweb.asm.tree.FieldNode field, Class<? extends Annotation> annotationClass) Get a runtime-visible annotation of the specified class from the supplied field node- Parameters:
field- Source fieldannotationClass- 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, Class<? extends Annotation> annotationClass) Get an invisible annotation of the specified class from the supplied field node- Parameters:
field- Source fieldannotationClass- 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, Class<? extends Annotation> annotationClass) Get a runtime-visible annotation of the specified class from the supplied method node- Parameters:
method- Source methodannotationClass- 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, Class<? extends Annotation> annotationClass) Get an invisible annotation of the specified class from the supplied method node- Parameters:
method- Source methodannotationClass- 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, Class<? extends Annotation>... annotationClasses) Get a runtime-visible annotation of the specified class from the supplied method node- Parameters:
method- Source methodannotationClasses- 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, Class<? extends Annotation>... annotationClasses) Get an invisible annotation of the specified class from the supplied method node- Parameters:
method- Source methodannotationClasses- 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, Class<? extends Annotation> annotationClass) Get a runtime-visible annotation of the specified class from the supplied class node- Parameters:
classNode- Source ClassNodeannotationClass- 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, Class<? extends Annotation> annotationClass) Get an invisible annotation of the specified class from the supplied class node- Parameters:
classNode- Source ClassNodeannotationClass- 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, Class<? extends Annotation> annotationClass, int paramIndex) Get a runtime-visible parameter annotation of the specified class from the supplied method node- Parameters:
method- Source methodannotationClass- Type of annotation to search forparamIndex- 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, Class<? extends Annotation> annotationClass, int paramIndex) Get an invisible parameter annotation of the specified class from the supplied method node- Parameters:
method- Source methodannotationClass- Type of annotation to search forparamIndex- 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(List<org.objectweb.asm.tree.AnnotationNode>[] parameterAnnotations, String annotationType, int paramIndex) Get a parameter annotation of the specified class from the supplied method node- Parameters:
parameterAnnotations- Annotations for the parameterannotationType- Type of annotation to search forparamIndex- 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(List<org.objectweb.asm.tree.AnnotationNode> annotations, String annotationType) Search for and return an annotation node matching the specified type within the supplied collection of annotation nodes- Parameters:
annotations- HaystackannotationType- 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
ClassCastExceptionif your duck is actually a rooster
-
getValue
public static <T> T getValue(org.objectweb.asm.tree.AnnotationNode annotation, 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 querykey- Key to search fordefaultValue- Value to return if the specified key is not found or is null- Returns:
- duck-typed annotation value, null if missing, or inevitable
ClassCastExceptionif your duck is actually a rooster
-
getValue
public static <T> T getValue(org.objectweb.asm.tree.AnnotationNode annotation, String key, 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 querykey- Key to search forannotationClass- 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
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 querykey- Key to search for- Returns:
- duck-typed annotation value, null if missing, or inevitable
ClassCastExceptionif your duck is actually a rooster
-
getValue
public static <T extends Enum<T>> T getValue(org.objectweb.asm.tree.AnnotationNode annotation, String key, 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 querykey- Key to search forenumClass- Class of enum containing the enum constant to search fordefaultValue- Value to return if the specified key isn't found- Returns:
- duck-typed annotation value or defaultValue if missing
-
getValue
public static <T> List<T> getValue(org.objectweb.asm.tree.AnnotationNode annotation, 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 querykey- Key to search fornotNull- if true, return an empty list instead of null if the annotation value is absent
-
getValue
public static <T extends Enum<T>> List<T> getValue(org.objectweb.asm.tree.AnnotationNode annotation, String key, boolean notNull, 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 querykey- Key to search fornotNull- if true, return an empty list instead of null if the annotation value is absentenumClass- Class of enum containing the enum constant to use
-
setValue
public static void setValue(org.objectweb.asm.tree.AnnotationNode annotation, String key, Object value) Set the value of an annotation node and do pseudo-duck-typing via Java's crappy generics- Parameters:
annotation- Annotation node to modifykey- Key to setvalue- Value to setClassCastExceptionif 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 fromto- 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 fromto- 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 fromto- FieldNode to merge annotations to
-