Package org.spongepowered.asm.util
Class Annotations
- java.lang.Object
-
- org.spongepowered.asm.util.Annotations
-
public final class Annotations extends java.lang.ObjectUtility class for working with ASM annotations
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAnnotations.HandleWrapper forAnnotationNodeto support access via common interface
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.objectweb.asm.tree.AnnotationNodeget(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 nodesstatic java.lang.StringgetDesc(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns the bytecode descriptor of an annotationstatic org.objectweb.asm.tree.AnnotationNodegetInvisible(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 nodestatic org.objectweb.asm.tree.AnnotationNodegetInvisible(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 nodestatic org.objectweb.asm.tree.AnnotationNodegetInvisible(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 nodestatic org.objectweb.asm.tree.AnnotationNodegetInvisibleParameter(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 nodestatic org.objectweb.asm.tree.AnnotationNodegetParameter(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 nodestatic java.lang.StringgetSimpleName(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 stringsstatic java.lang.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, java.lang.Class<? extends java.lang.annotation.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, java.lang.Class<? extends java.lang.annotation.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> TgetValue(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 genericsstatic <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 nodesstatic <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 enumsstatic <T> TgetValue(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 presentstatic <T extends java.lang.Enum<T>>
TgetValue(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 setstatic <T> TgetValue(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 genericsstatic org.objectweb.asm.tree.AnnotationNodegetVisible(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 nodestatic org.objectweb.asm.tree.AnnotationNodegetVisible(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 nodestatic org.objectweb.asm.tree.AnnotationNodegetVisible(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 nodestatic org.objectweb.asm.tree.AnnotationNodegetVisibleParameter(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 nodestatic IAnnotationHandlehandleOf(java.lang.Object annotation)Get 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, 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 nodestatic voidsetInvisible(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 nodestatic voidsetValue(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 genericsstatic voidsetVisible(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 nodestatic voidsetVisible(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
-
-
-
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 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, 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 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, 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 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, 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 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, 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 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, 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 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, 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 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, 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 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, 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 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, 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 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, 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 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, 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 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, 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 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, 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 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(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 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(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- 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, 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 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, 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 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
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 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 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 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> 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 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 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 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, 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 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
-
-