Package libcore.reflect
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 Summary
Modifier and Type Method Description static <A extends Annotation>
AcreateAnnotation(Class<? extends Annotation> annotationType, AnnotationMember[] elements)Provides a new annotation instance.booleanequals(Object obj)Returns true if the specified object represents the same annotation instance.static AnnotationMember[]getElementsDescription(Class<? extends Annotation> annotationType)Reflects specified annotation type and returns an array of member element definitions with default values.inthashCode()Returns a hash code composed as a sum of hash codes of member elements, including elements with default values.Objectinvoke(Object proxy, Method method, Object[] args)Processes a method invocation request to this annotation instance.StringtoString()Provides detailed description of this annotation instance, including all member name-values pairs.
-
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 definitionelements- name-value pairs representing elements of the annotation- Returns:
- a new annotation instance
-
equals
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:
equalsin classObject- 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:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
AnnotationMember.hashCode()
-
toString
Provides detailed description of this annotation instance, including all member name-values pairs. -
invoke
Processes a method invocation request to this annotation instance. Recognizes the methods declared in thejava.lang.annotation.Annotationinterface, and member-defining methods of the implemented annotation type.- Specified by:
invokein interfaceInvocationHandler- Parameters:
proxy- the proxy instance on which the method was invokedmethod- the method invoked on the proxy instanceargs- an array of objects containing the parameters passed to the method, ornullif no arguments are expected. Primitive types are boxed.- Returns:
- the invocation result
- Throws:
IllegalArgumentException- If the specified method is none of the aboveThrowable- 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 anUndeclaredThrowableExceptionis thrown
-