Class SourceAnnotationHandler

  • All Implemented Interfaces:
    MetadataProcessor<javax.lang.model.element.TypeElement,​javax.lang.model.element.Element>

    public class SourceAnnotationHandler
    extends java.lang.Object
    implements MetadataProcessor<javax.lang.model.element.TypeElement,​javax.lang.model.element.Element>
    Extracts persistent metadata information by analyzing available annotation in *.java source files. Requires JDK6 Annotation Processing environment available.
    Since:
    2.0.0
    Author:
    Pinaki Poddar
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.AnnotatedFilter annotatedFilter  
      protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.AccessFilter fieldAccessFilter  
      protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.KindFilter fieldFilter  
      protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.GetterFilter getterFilter  
      protected static java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> mappingAnnos  
      protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.KindFilter methodFilter  
      protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.TransientFilter nonTransientFilter  
      protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.AccessFilter propertyAccessFilter
      Set of Inclusion Filters based on member type, access type or transient annotations.
      protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.SetterFilter setterFilter  
    • Constructor Summary

      Constructors 
      Constructor Description
      SourceAnnotationHandler​(javax.annotation.processing.ProcessingEnvironment processingEnv, CompileTimeLogger logger)
      Construct with JDK6 annotation processing environment.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.lang.model.type.TypeMirror box​(javax.lang.model.type.TypeMirror t)  
      int determineMemberAccess​(javax.lang.model.element.Element m)
      Determine the access type of the given member.
      int determineTypeAccess​(javax.lang.model.element.TypeElement type)
      Determine the access type of the given type.
      static boolean equalsByValue​(java.lang.Enum<?> e, java.lang.Object v)
      Affirms if the given enum equals the given value.
      java.lang.String extractFieldName​(javax.lang.model.element.ExecutableElement method)  
      static java.lang.Object getAnnotationValue​(javax.lang.model.element.Element decl, java.lang.Class<? extends java.lang.annotation.Annotation> anno)
      Gets the value of the given annotation, if present, in the given declaration.
      static java.lang.Object getAnnotationValue​(javax.lang.model.element.Element e, java.lang.Class<? extends java.lang.annotation.Annotation> anno, java.lang.String attr)
      Gets the value of the given attribute of the given annotation, if present, in the given declaration.
      java.util.Set<javax.lang.model.element.Element> getPersistentMembers​(javax.lang.model.element.TypeElement type)
      Gets the list of persistent fields and/or methods for the given type.
      javax.lang.model.element.TypeElement getPersistentSupertype​(javax.lang.model.element.TypeElement cls)  
      static boolean isAnnotated​(javax.lang.model.element.Element e)
      Affirms if the given element is annotated with any jakarta.persistence
      static boolean isAnnotatedWith​(javax.lang.model.element.Element e, java.lang.Class<? extends java.lang.annotation.Annotation> anno)
      Affirms if the given declaration has the given annotation.
      static boolean isAnnotatedWith​(javax.lang.model.element.Element e, java.util.Set<java.lang.String> annos)
      Affirms if the given element is annotated with any of the given annotations.
      static boolean isBoolean​(javax.lang.model.type.TypeMirror type)
      Affirms if the given mirror represents a primitive or non-primitive boolean.
      static boolean isBooleanGetter​(javax.lang.model.element.ExecutableElement method)
      Affirms if the given method matches the following signature public boolean isXyz() public Boolean isXyz()
      static boolean isGetter​(javax.lang.model.element.ExecutableElement method)  
      static boolean isMethod​(javax.lang.model.element.Element e)
      Affirms if the given element represents a method.
      boolean isMixedAccess​(javax.lang.model.element.TypeElement t)
      Affirms if the members of given type are using both field and property based access.
      static boolean isNormalGetter​(javax.lang.model.element.ExecutableElement method)
      Affirms if the given method matches the following signature public T getXXX() where T is any non-void type.
      static boolean isRootObject​(javax.lang.model.type.TypeMirror type)
      Affirms if the given mirror represents root java.lang.Object.
      static boolean isSetter​(javax.lang.model.element.ExecutableElement method)
      Affirms if the given method matches the following signature public void setXXX(T t)
      static boolean isVoid​(javax.lang.model.type.TypeMirror type)
      Affirms if the given mirror represents a void.
      static boolean startsWith​(java.lang.String full, java.lang.String head)
      Affirms if the given full string starts with the given head.
      static java.lang.String toString​(java.util.Collection<? extends javax.lang.model.element.Element> elements)  
      java.util.List<java.lang.Exception> validateAccess​(javax.lang.model.element.TypeElement t)
      Gets the violations, if any.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • propertyAccessFilter

        protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.AccessFilter propertyAccessFilter
        Set of Inclusion Filters based on member type, access type or transient annotations. Used to determine the subset of available field/method that are persistent.
      • fieldAccessFilter

        protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.AccessFilter fieldAccessFilter
      • fieldFilter

        protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.KindFilter fieldFilter
      • methodFilter

        protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.KindFilter methodFilter
      • nonTransientFilter

        protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.TransientFilter nonTransientFilter
      • annotatedFilter

        protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.AnnotatedFilter annotatedFilter
      • getterFilter

        protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.GetterFilter getterFilter
      • setterFilter

        protected org.apache.openjpa.persistence.meta.SourceAnnotationHandler.SetterFilter setterFilter
      • mappingAnnos

        protected static java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> mappingAnnos
    • Constructor Detail

      • SourceAnnotationHandler

        public SourceAnnotationHandler​(javax.annotation.processing.ProcessingEnvironment processingEnv,
                                       CompileTimeLogger logger)
        Construct with JDK6 annotation processing environment.
    • Method Detail

      • determineTypeAccess

        public int determineTypeAccess​(javax.lang.model.element.TypeElement type)
        Description copied from interface: MetadataProcessor
        Determine the access type of the given type.
        Specified by:
        determineTypeAccess in interface MetadataProcessor<javax.lang.model.element.TypeElement,​javax.lang.model.element.Element>
        Returns:
        an integer denoting the type of access. The integer value corresponds to ClassMetaData.getAccessType().
      • determineMemberAccess

        public int determineMemberAccess​(javax.lang.model.element.Element m)
        Description copied from interface: MetadataProcessor
        Determine the access type of the given member.
        Specified by:
        determineMemberAccess in interface MetadataProcessor<javax.lang.model.element.TypeElement,​javax.lang.model.element.Element>
        Returns:
        an integer denoting the type of access. The integer value corresponds to FieldMetaData.getAccessType().
      • validateAccess

        public java.util.List<java.lang.Exception> validateAccess​(javax.lang.model.element.TypeElement t)
        Description copied from interface: MetadataProcessor
        Gets the violations, if any.
        Specified by:
        validateAccess in interface MetadataProcessor<javax.lang.model.element.TypeElement,​javax.lang.model.element.Element>
        Returns:
        null or empty list if no exceptions.
      • isMixedAccess

        public boolean isMixedAccess​(javax.lang.model.element.TypeElement t)
        Description copied from interface: MetadataProcessor
        Affirms if the members of given type are using both field and property based access.
        Specified by:
        isMixedAccess in interface MetadataProcessor<javax.lang.model.element.TypeElement,​javax.lang.model.element.Element>
      • getPersistentMembers

        public java.util.Set<javax.lang.model.element.Element> getPersistentMembers​(javax.lang.model.element.TypeElement type)
        Gets the list of persistent fields and/or methods for the given type. Scans relevant @AccessType annotation and field/method as per JPA specification to determine the candidate set of field/methods.
        Specified by:
        getPersistentMembers in interface MetadataProcessor<javax.lang.model.element.TypeElement,​javax.lang.model.element.Element>
      • getAnnotationValue

        public static java.lang.Object getAnnotationValue​(javax.lang.model.element.Element decl,
                                                          java.lang.Class<? extends java.lang.annotation.Annotation> anno)
        Gets the value of the given annotation, if present, in the given declaration. Otherwise, null.
      • getAnnotationValue

        public static java.lang.Object getAnnotationValue​(javax.lang.model.element.Element e,
                                                          java.lang.Class<? extends java.lang.annotation.Annotation> anno,
                                                          java.lang.String attr)
        Gets the value of the given attribute of the given annotation, if present, in the given declaration. Otherwise, null.
      • toString

        public static java.lang.String toString​(java.util.Collection<? extends javax.lang.model.element.Element> elements)
      • extractFieldName

        public java.lang.String extractFieldName​(javax.lang.model.element.ExecutableElement method)
      • isAnnotated

        public static boolean isAnnotated​(javax.lang.model.element.Element e)
        Affirms if the given element is annotated with any jakarta.persistence.* or org.apache.openjpa.* annotation.
      • isAnnotatedWith

        public static boolean isAnnotatedWith​(javax.lang.model.element.Element e,
                                              java.lang.Class<? extends java.lang.annotation.Annotation> anno)
        Affirms if the given declaration has the given annotation.
      • isAnnotatedWith

        public static boolean isAnnotatedWith​(javax.lang.model.element.Element e,
                                              java.util.Set<java.lang.String> annos)
        Affirms if the given element is annotated with any of the given annotations.
        Parameters:
        annos - null checks for any annotation that starts with 'jakarta.persistence.' or 'openjpa.*'.
      • box

        public javax.lang.model.type.TypeMirror box​(javax.lang.model.type.TypeMirror t)
      • getPersistentSupertype

        public javax.lang.model.element.TypeElement getPersistentSupertype​(javax.lang.model.element.TypeElement cls)
        Specified by:
        getPersistentSupertype in interface MetadataProcessor<javax.lang.model.element.TypeElement,​javax.lang.model.element.Element>
      • isBoolean

        public static boolean isBoolean​(javax.lang.model.type.TypeMirror type)
        Affirms if the given mirror represents a primitive or non-primitive boolean.
      • isVoid

        public static boolean isVoid​(javax.lang.model.type.TypeMirror type)
        Affirms if the given mirror represents a void.
      • isMethod

        public static boolean isMethod​(javax.lang.model.element.Element e)
        Affirms if the given element represents a method.
      • isNormalGetter

        public static boolean isNormalGetter​(javax.lang.model.element.ExecutableElement method)
        Affirms if the given method matches the following signature public T getXXX() where T is any non-void type.
      • isBooleanGetter

        public static boolean isBooleanGetter​(javax.lang.model.element.ExecutableElement method)
        Affirms if the given method matches the following signature public boolean isXyz() public Boolean isXyz()
      • isGetter

        public static boolean isGetter​(javax.lang.model.element.ExecutableElement method)
      • isSetter

        public static boolean isSetter​(javax.lang.model.element.ExecutableElement method)
        Affirms if the given method matches the following signature public void setXXX(T t)
      • isRootObject

        public static boolean isRootObject​(javax.lang.model.type.TypeMirror type)
        Affirms if the given mirror represents root java.lang.Object.
      • startsWith

        public static boolean startsWith​(java.lang.String full,
                                         java.lang.String head)
        Affirms if the given full string starts with the given head.
      • equalsByValue

        public static boolean equalsByValue​(java.lang.Enum<?> e,
                                            java.lang.Object v)
        Affirms if the given enum equals the given value.