Package org.jboss.jandex
Class AnnotationInstance
- java.lang.Object
-
- org.jboss.jandex.AnnotationInstance
-
public final class AnnotationInstance extends java.lang.ObjectAn annotation instance represents a specific usage of an annotation on a target. It contains a set of values, as well as a reference to the target itself (e.g. class, field, method, etc).Thread-Safety
This class is immutable and can be shared between threads without safe publication.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classAnnotationInstance.InstanceNameComparator
-
Field Summary
Fields Modifier and Type Field Description private static AnnotationValue[]ANNOTATION_VALUES_TYPE(package private) static AnnotationInstance[]EMPTY_ARRAYprivate DotNamename(package private) static AnnotationInstance.InstanceNameComparatorNAME_COMPARATORprivate AnnotationTargettargetprivate AnnotationValue[]values
-
Constructor Summary
Constructors Constructor Description AnnotationInstance(AnnotationInstance instance, AnnotationTarget target)AnnotationInstance(DotName name, AnnotationTarget target, AnnotationValue[] values)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AnnotationInstancecreate(DotName name, AnnotationTarget target, java.util.List<AnnotationValue> values)Construct a new mock annotation instance.static AnnotationInstancecreate(DotName name, AnnotationTarget target, AnnotationValue[] values)Construct a new mock annotation instance.booleanequals(java.lang.Object o)Returns whether or not this annotation instance is equivalent to another instance.inthashCode()Returns a hash code representing this object.DotNamename()The name of this annotation in DotName form.(package private) voidsetTarget(AnnotationTarget target)AnnotationTargettarget()The Java element that this annotation was declared on.java.lang.StringtoString()Returns a string representation for this annotation instance.java.lang.StringtoString(boolean simple)Returns an optionally simplified string that represents this annotation instance.AnnotationValuevalue()Returns the value that is associated with the special default "value" parameter.AnnotationValuevalue(java.lang.String name)Returns a value that corresponds with the specified parameter name.(package private) AnnotationValue[]valueArray()java.util.List<AnnotationValue>values()Returns a list of all parameter values on this annotation instance.java.util.List<AnnotationValue>valuesWithDefaults(IndexView index)Returns a list of all parameter values on this annotation instance, including default values id defined.AnnotationValuevalueWithDefault(IndexView index)Returns the value that is associated with the special default "value" parameter, also accounting for a value default.AnnotationValuevalueWithDefault(IndexView index, java.lang.String name)Returns a value that corresponds with the specified parameter name, accounting for its default value.
-
-
-
Field Detail
-
ANNOTATION_VALUES_TYPE
private static final AnnotationValue[] ANNOTATION_VALUES_TYPE
-
NAME_COMPARATOR
static final AnnotationInstance.InstanceNameComparator NAME_COMPARATOR
-
EMPTY_ARRAY
static final AnnotationInstance[] EMPTY_ARRAY
-
name
private final DotName name
-
target
private AnnotationTarget target
-
values
private final AnnotationValue[] values
-
-
Constructor Detail
-
AnnotationInstance
AnnotationInstance(AnnotationInstance instance, AnnotationTarget target)
-
AnnotationInstance
AnnotationInstance(DotName name, AnnotationTarget target, AnnotationValue[] values)
-
-
Method Detail
-
create
public static final AnnotationInstance create(DotName name, AnnotationTarget target, AnnotationValue[] values)
Construct a new mock annotation instance. The passed values array will be defensively copied.- Parameters:
name- the name of the annotation instancetarget- the thing the annotation is declared onvalues- the values of this annotation instance- Returns:
- the new mock Annotation Instance
-
create
public static final AnnotationInstance create(DotName name, AnnotationTarget target, java.util.List<AnnotationValue> values)
Construct a new mock annotation instance. The passed values list will be defensively copied.- Parameters:
name- the name of the annotation instancetarget- the thing the annotation is declared onvalues- the values of this annotation instance- Returns:
- the new mock Annotation Instance
-
name
public DotName name()
The name of this annotation in DotName form.- Returns:
- the name of this annotation
-
target
public AnnotationTarget target()
The Java element that this annotation was declared on. This can be a class, a field, a method, or a method parameter. In addition it may be null if this instance is a nested annotation, in which case there is no target.- Returns:
- the target this annotation instance refers to
-
value
public AnnotationValue value(java.lang.String name)
Returns a value that corresponds with the specified parameter name. If the parameter was not specified by this instance then null is returned. Note that this also applies to a defaulted parameter, which is not recorded in the target class.- Parameters:
name- the parameter name- Returns:
- the value of the specified parameter, or null if not provided
-
value
public AnnotationValue value()
Returns the value that is associated with the special default "value" parameter.- Returns:
- the "value" value
-
valueWithDefault
public AnnotationValue valueWithDefault(IndexView index, java.lang.String name)
Returns a value that corresponds with the specified parameter name, accounting for its default value. Since an annotation's defaults are only stored on the annotation's defining class, and not usages of the annotation, an index containing the Annotation class must be provided as a parameter. If the index does not contain the defining annotation class, then anIllegalArgumentExceptionwill be thrown to prevent non-deterministic results.If the parameter was not specified by this instance, then the annotation's
ClassInfois checked for a default value. If there is a default, that value is returned. Otherwise null is returned.- Parameters:
index- the index containing the defining annotation classname- the name of the annotation parameter- Returns:
- the value of the specified parameter, the default, or null
- Throws:
java.lang.IllegalArgumentException- if index does not contain the defining annotation class- Since:
- 2.1
-
valueWithDefault
public AnnotationValue valueWithDefault(IndexView index)
Returns the value that is associated with the special default "value" parameter, also accounting for a value default. Since an annotation's defaults are only stored on the annotation's defining class, and not usages of the annotation, an index containing the Annotation class must be provided as a parameter. If the index does not contain the defining annotation class, then anIllegalArgumentExceptionwill be thrown to prevent non-deterministic results.If the "value" parameter was not specified by this instance, then the annotation's
ClassInfois checked for a default value. If there is a default, that value is returned. Otherwise null is returned.- Parameters:
index- the index containing the defining annotation class- Returns:
- the "value" value, or its default, or null
- Throws:
java.lang.IllegalArgumentException- if index does not contain the defining annotation class- Since:
- 2.1
-
valuesWithDefaults
public java.util.List<AnnotationValue> valuesWithDefaults(IndexView index)
Returns a list of all parameter values on this annotation instance, including default values id defined. Since an annotation's defaults are only stored on the annotation's defining class, and not usages of the annotation, an index containing the Annotation class must be provided as a parameter. If the index does not contain the defining annotation class, then anIllegalArgumentExceptionwill be thrown to prevent non-deterministic results.The order of this list is undefined.
- Returns:
- the parameter values of this annotation
- Throws:
java.lang.IllegalArgumentException- if index does not contain the defining annotation class- Since:
- 2.1
-
values
public java.util.List<AnnotationValue> values()
Returns a list of all parameter values on this annotation instance. While random access is allowed, the ordering algorithm of the list should not be relied upon. Although it will be consistent for the life of this instance.- Returns:
- the parameter values of this annotation
-
valueArray
AnnotationValue[] valueArray()
-
toString
public java.lang.String toString(boolean simple)
Returns an optionally simplified string that represents this annotation instance. If simplified the output is smaller but missing information, such as the package qualifier.- Parameters:
simple- whether to provide a simpler string representation- Returns:
- a string representation for this object
- Since:
- 2.0
-
toString
public java.lang.String toString()
Returns a string representation for this annotation instance. This method is equivalent to callingtoString(boolean)with a value of true.- Overrides:
toStringin classjava.lang.Object- Returns:
- a simple string representation for this annotation instance
-
setTarget
void setTarget(AnnotationTarget target)
-
equals
public boolean equals(java.lang.Object o)
Returns whether or not this annotation instance is equivalent to another instance. An annotation instance is equivalent if its name and values are equal, and it shares the exact sameAnnotationTargetinstance. The latter restriction may be softened in future versions.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the annotation instance to compare to.- Returns:
- true if equal, false if not
- See Also:
Object.equals(Object)
-
hashCode
public int hashCode()
Returns a hash code representing this object.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code of this object
- See Also:
Object.hashCode()
-
-