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:
The value may be one of the following types:
- boxed primitive
- Class
- enum constant
- annotation (nested)
- one-dimensional array of the above
- Throwable
- Version:
- $Revision$
- Author:
- Alexey V. Varlamov, Serguei S. Zapreyev
- 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
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 Details
-
ERROR
protected static final char ERRORTag description of a Throwable value type.- See Also:
- Constant Field Values
-
ARRAY
protected static final char ARRAYTag description of an array value type.- See Also:
- Constant Field Values
-
OTHER
protected static final char OTHERTag description of all value types except arrays and Throwables.- See Also:
- Constant Field Values
-
NO_VALUE
Singleton representing missing element value. -
name
-
value
-
tag
protected final char tag -
elementType
-
definingMethod
-
-
Constructor Details
-
AnnotationMember
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
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 Details
-
setDefinition
Fills in element's definition info and returns this. -
toString
Returns readable description of this annotation value. -
equals
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
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
Throws contained error (if any) with a renewed stack trace.- Throws:
Throwable
-
validateValue
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()
-
copyValue
Provides mutation-safe access to contained value. That is, caller is free to modify the returned value, it will not affect the contained data value.- Returns:
- cloned value if it is mutable or the original immutable value
- Throws:
Throwable
-