Class AnnotationFactory

java.lang.Object
libcore.reflect.AnnotationFactory
All Implemented Interfaces:
Serializable, InvocationHandler

public final class AnnotationFactory
extends Object
implements InvocationHandler, Serializable
The annotation implementation based on dynamically generated proxy instances. It conforms to all requirements stated in public APIs, see in particular java.lang.reflect.AnnotatedElement and java.lang.annotation.Annotation. Namely, annotation instances are immutable and serializable; they provide conforming access to annotation member values and required implementations of methods declared in Annotation interface.
Version:
$Revision$
Author:
Alexey V. Varlamov, Serguei S. Zapreyev
See Also:
AnnotationMember, Annotation, Serialized Form
  • Method Details

    • getElementsDescription

      public static AnnotationMember[] getElementsDescription​(Class<? extends Annotation> annotationType)
      Reflects specified annotation type and returns an array of member element definitions with default values.
    • createAnnotation

      public static <A extends Annotation> A createAnnotation​(Class<? extends Annotation> annotationType, AnnotationMember[] elements)
      Provides a new annotation instance.
      Parameters:
      annotationType - the annotation type definition
      elements - name-value pairs representing elements of the annotation
      Returns:
      a new annotation instance
    • equals

      public boolean equals​(Object obj)
      Returns true if the specified object represents the same annotation instance. That is, if it implements the same annotation type and returns the same element values.
      Note, actual underlying implementation mechanism does not matter - it may differ completely from this class.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare this instance with.
      Returns:
      true if the passed object is equivalent annotation instance, false otherwise.
      See Also:
      AnnotationMember.equals(Object)
    • hashCode

      public int hashCode()
      Returns a hash code composed as a sum of hash codes of member elements, including elements with default values.
      Overrides:
      hashCode in class Object
      Returns:
      this object's hash code.
      See Also:
      AnnotationMember.hashCode()
    • toString

      public String toString()
      Provides detailed description of this annotation instance, including all member name-values pairs.
      Overrides:
      toString in class Object
      Returns:
      string representation of this annotation
    • invoke

      public Object invoke​(Object proxy, Method method, Object[] args) throws Throwable
      Processes a method invocation request to this annotation instance. Recognizes the methods declared in the java.lang.annotation.Annotation interface, and member-defining methods of the implemented annotation type.
      Specified by:
      invoke in interface InvocationHandler
      Parameters:
      proxy - the proxy instance on which the method was invoked
      method - the method invoked on the proxy instance
      args - an array of objects containing the parameters passed to the method, or null if no arguments are expected. Primitive types are boxed.
      Returns:
      the invocation result
      Throws:
      IllegalArgumentException - If the specified method is none of the above
      Throwable - the exception to throw from the invoked method on the proxy. The exception must match one of the declared exception types of the invoked method or any unchecked exception type. If not then an UndeclaredThrowableException is thrown