Package libcore.reflect
Class AnnotationMember
- java.lang.Object
-
- libcore.reflect.AnnotationMember
-
- All Implemented Interfaces:
Serializable
public final class AnnotationMember extends Object implements Serializable
This class represents member element of an annotation. It consists of name and value, supplemented with element definition information (such as declared type of element).
The value may be one of the following types:- boxed primitive
- Class
- enum constant
- annotation (nested)
- one-dimensional array of the above
- Throwable
- See Also:
AnnotationFactory, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static charARRAYTag description of an array value type.protected MethoddefiningMethodprotected Class<?>elementTypeprotected static charERRORTag description of a Throwable value type.protected Stringnameprotected static ObjectNO_VALUESingleton representing missing element value.protected static charOTHERTag description of all value types except arrays and Throwables.protected chartagprotected Objectvalue
-
Constructor Summary
Constructors Constructor Description AnnotationMember(String name, Object val)Creates a new element with specified name and value.AnnotationMember(String name, Object val, Class type, Method m)Creates the completely defined element.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectcopyValue()Provides mutation-safe access to contained value.booleanequalArrayValue(Object otherValue)Returns true if the contained value and a passed object are equal arrays, false otherwise.booleanequals(Object obj)Returns true if the specified object represents equal element (equivalent name-value pair).inthashCode()Computes hash code of this element.voidrethrowError()Throws contained error (if any) with a renewed stack trace.protected AnnotationMembersetDefinition(AnnotationMember copy)Fills in element's definition info and returns this.StringtoString()Returns readable description of this annotation value.ObjectvalidateValue()Validates contained value against its member definition and if ok returns the value.
-
-
-
Field Detail
-
ERROR
protected static final char ERROR
Tag description of a Throwable value type.- See Also:
- Constant Field Values
-
ARRAY
protected static final char ARRAY
Tag description of an array value type.- See Also:
- Constant Field Values
-
OTHER
protected static final char OTHER
Tag description of all value types except arrays and Throwables.- See Also:
- Constant Field Values
-
NO_VALUE
protected static final Object NO_VALUE
Singleton representing missing element value.
-
name
protected final String name
-
value
protected final Object value
-
tag
protected final char tag
-
elementType
protected transient Class<?> elementType
-
definingMethod
protected transient Method definingMethod
-
-
Constructor Detail
-
AnnotationMember
public AnnotationMember(String name, Object val)
Creates a new element with specified name and value. Definition info will be provided later when this element becomes actual annotation member.- Parameters:
name- element name, must not be nullval- element value, should be of addmissible type, as specified in the description of this class- See Also:
setDefinition(AnnotationMember)
-
AnnotationMember
public AnnotationMember(String name, Object val, Class type, Method m)
Creates the completely defined element.- Parameters:
name- element name, must not be nullvalue- element value, should be of addmissible type, as specified in the description of this classm- element-defining method, reflected on the annotation typetype- declared type of this element (return type of the defining method)
-
-
Method Detail
-
setDefinition
protected AnnotationMember setDefinition(AnnotationMember copy)
Fills in element's definition info and returns this.
-
toString
public String toString()
Returns readable description of this annotation value.
-
equals
public boolean equals(Object obj)
Returns true if the specified object represents equal element (equivalent name-value pair).
A special case is the contained Throwable value; it is considered transcendent so no other element would be equal.- Overrides:
equalsin classObject- Parameters:
obj- the object to compare this instance with.- Returns:
- true if passed object is equivalent element representation, false otherwise
- See Also:
equalArrayValue(Object),Annotation.equals(Object)
-
equalArrayValue
public boolean equalArrayValue(Object otherValue)
Returns true if the contained value and a passed object are equal arrays, false otherwise. Appropriate overloaded method of Arrays.equals() is used for equality testing.- Returns:
- true if the value is array and is equal to specified object, false otherwise
- See Also:
Arrays.equals(java.lang.Object[], java.lang.Object[])
-
hashCode
public int hashCode()
Computes hash code of this element. The formula is as follows:(name.hashCode() * 127) ^ value.hashCode()
If value is an array, one of overloaded Arrays.hashCode() methods is used.- Overrides:
hashCodein classObject- Returns:
- the hash code
- See Also:
Arrays.hashCode(java.lang.Object[]),Annotation.hashCode()
-
rethrowError
public void rethrowError() throws ThrowableThrows contained error (if any) with a renewed stack trace.- Throws:
Throwable
-
validateValue
public Object validateValue() throws Throwable
Validates contained value against its member definition and if ok returns the value. Otherwise, if the value type mismatches definition or the value itself describes an error, throws appropriate exception.
Note, this method may return null if this element was constructed with such value.- Returns:
- actual valid value or null if no value
- Throws:
Throwable- See Also:
rethrowError(),copyValue()
-
-