Class AnnotationInvocationHandler

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.annotation.Annotation, java.lang.reflect.InvocationHandler

    class AnnotationInvocationHandler
    extends java.lang.Object
    implements java.lang.annotation.Annotation, java.lang.reflect.InvocationHandler, java.io.Serializable
    An implementation of Annotation that mimics the behavior of normal annotations. It is an InvocationHandler, meant to be used via TypeFactory.annotation(Class, Map).

    The constructor checks that the all the elements required by the annotation interface are provided and that the types are compatible. If extra elements are provided, they are ignored. If a value is of an incompatible type is provided or no value is provided for an element without a default value, AnnotationFormatException is thrown.

    Note: equals(Object) and hashCode() and implemented as specified by Annotation, so instances are safe to mix with normal annotations.

    See Also:
    Annotation
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<? extends java.lang.annotation.Annotation> annotationType  
      private int hashCode  
      private static java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> primitiveWrapperMap
      Maps primitive Classes to their corresponding wrapper Class.
      private static long serialVersionUID  
      private java.util.Map<java.lang.String,​java.lang.Object> values  
    • Constructor Summary

      Constructors 
      Constructor Description
      AnnotationInvocationHandler​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.util.Map<java.lang.String,​java.lang.Object> values)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<? extends java.lang.annotation.Annotation> annotationType()  
      private int calculateHashCode()  
      private int calculateHashCode​(java.lang.Object element)  
      boolean equals​(java.lang.Object other)
      Performs an equality check as described in Annotation.equals(Object).
      int hashCode()
      Calculates the hash code of this annotation as described in Annotation.hashCode().
      java.lang.Object invoke​(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)  
      (package private) static java.util.Map<java.lang.String,​java.lang.Object> normalize​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.util.Map<java.lang.String,​java.lang.Object> values)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • primitiveWrapperMap

        private static final java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> primitiveWrapperMap
        Maps primitive Classes to their corresponding wrapper Class.
      • annotationType

        private final java.lang.Class<? extends java.lang.annotation.Annotation> annotationType
      • values

        private final java.util.Map<java.lang.String,​java.lang.Object> values
      • hashCode

        private final int hashCode
    • Constructor Detail

      • AnnotationInvocationHandler

        AnnotationInvocationHandler​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                    java.util.Map<java.lang.String,​java.lang.Object> values)
                             throws AnnotationFormatException
        Throws:
        AnnotationFormatException
    • Method Detail

      • normalize

        static java.util.Map<java.lang.String,​java.lang.Object> normalize​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
                                                                                java.util.Map<java.lang.String,​java.lang.Object> values)
                                                                         throws AnnotationFormatException
        Throws:
        AnnotationFormatException
      • invoke

        public java.lang.Object invoke​(java.lang.Object proxy,
                                       java.lang.reflect.Method method,
                                       java.lang.Object[] args)
                                throws java.lang.Throwable
        Specified by:
        invoke in interface java.lang.reflect.InvocationHandler
        Throws:
        java.lang.Throwable
      • annotationType

        public java.lang.Class<? extends java.lang.annotation.Annotation> annotationType()
        Specified by:
        annotationType in interface java.lang.annotation.Annotation
      • equals

        public boolean equals​(java.lang.Object other)
        Performs an equality check as described in Annotation.equals(Object).
        Specified by:
        equals in interface java.lang.annotation.Annotation
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - The object to compare
        Returns:
        Whether the given object is equal to this annotation or not
        See Also:
        Annotation.equals(Object)
      • hashCode

        public int hashCode()
        Calculates the hash code of this annotation as described in Annotation.hashCode().
        Specified by:
        hashCode in interface java.lang.annotation.Annotation
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code of this annotation.
        See Also:
        Annotation.hashCode()
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface java.lang.annotation.Annotation
        Overrides:
        toString in class java.lang.Object
      • calculateHashCode

        private int calculateHashCode()
      • calculateHashCode

        private int calculateHashCode​(java.lang.Object element)