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
The last type is specific for this implementation; a Throwable value means that the error occured during parsing or resolution of corresponding class-data structures and throwing is delayed until the element is requested for value.
Version:
$Revision$
Author:
Alexey V. Varlamov, Serguei S. Zapreyev
See Also:
AnnotationFactory, Serialized Form
  • Field Details

    • 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 Details

    • 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 null
      val - 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 null
      value - element value, should be of addmissible type, as specified in the description of this class
      m - element-defining method, reflected on the annotation type
      type - declared type of this element (return type of the defining method)
  • Method Details

    • 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.
      Overrides:
      toString in class Object
      Returns:
      a printable representation of this object.
    • 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:
      equals in class Object
      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:
      hashCode in class Object
      Returns:
      the hash code
      See Also:
      Arrays.hashCode(java.lang.Object[]), Annotation.hashCode()
    • rethrowError

      public void rethrowError() throws Throwable
      Throws 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()
    • copyValue

      public Object copyValue() throws Throwable
      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