Class AnnotationProcessorUtils


  • public class AnnotationProcessorUtils
    extends Object
    Series of method to aid in the writing of annotation processors.
    • Constructor Detail

      • AnnotationProcessorUtils

        public AnnotationProcessorUtils()
    • Method Detail

      • getTypeCategoryForTypeMirror

        public static AnnotationProcessorUtils.TypeCategory getTypeCategoryForTypeMirror​(String typeName)
        Method to return the type category for a type.
        Parameters:
        typeName - The type name (e.g java.lang.String, java.util.Collection)
        Returns:
        The type category
      • getFieldMembers

        public static List<? extends Element> getFieldMembers​(TypeElement el)
        Convenience accessor for all field members of the supplied type element.
        Parameters:
        el - The type element
        Returns:
        The field members
      • getPropertyMembers

        public static List<? extends Element> getPropertyMembers​(TypeElement el)
        Convenience accessor for all property members of the supplied type element.
        Parameters:
        el - The type element
        Returns:
        The property members
      • isJavaBeanGetter

        public static boolean isJavaBeanGetter​(ExecutableElement method)
        Convenience method to return if the provided method is a java bean getter.
        Parameters:
        method - The method
        Returns:
        Whether it is a java bean getter
      • getMemberName

        public static String getMemberName​(Element el)
        Accessor for the member name for a field or Java bean getter/setter. If this is a field then just returns the field name, and if "getXxx"/"setXxx" then returns "xxx"
        Parameters:
        el - The element
        Returns:
        The member name
      • isJavaBeanSetter

        public static boolean isJavaBeanSetter​(ExecutableElement method)
        Convenience method to return if the provided method is a java bean setter.
        Parameters:
        method - The method
        Returns:
        Whether it is a java bean setter
      • isMethod

        public static boolean isMethod​(Element elem)
        Convenience method to return if the provided element represents a method (otherwise a field).
        Parameters:
        elem - The element
        Returns:
        Whether it represents a method
      • getDeclaredType

        public static TypeMirror getDeclaredType​(Element elem)
        Accessor for the declared type of this element. If this is a field then returns the declared type of the field. If this is a java bean getter then returns the return type.
        Parameters:
        elem - The element
        Returns:
        The declared type
      • getValueForAnnotationAttribute

        public static Object getValueForAnnotationAttribute​(Element elem,
                                                            Class annotCls,
                                                            String attribute)
        Accessor for the value for an annotation attribute.
        Parameters:
        elem - The element
        annotCls - Annotation class
        attribute - The attribute we're interested in
        Returns:
        The value
      • returnsVoid

        public static boolean returnsVoid​(ExecutableElement method)
        Convenience method returning if the provided method returns void.
        Parameters:
        method - The method
        Returns:
        Whether it returns void
      • returnsBoolean

        public static boolean returnsBoolean​(ExecutableElement method)
        Convenience method returning if the provided method returns boolean.
        Parameters:
        method - The method
        Returns:
        Whether it returns boolean
      • typeIsPrimitive

        public static boolean typeIsPrimitive​(TypeMirror type)
        Convenience method to return if the provided type is a primitive.
        Parameters:
        type - The type
        Returns:
        Whether it is a primitive
      • getDeclaredTypeName

        public static String getDeclaredTypeName​(ProcessingEnvironment processingEnv,
                                                 TypeMirror type,
                                                 boolean box)
        Method to return the declared type name of the provided TypeMirror.
        Parameters:
        processingEnv - Processing environment
        type - The type (mirror)
        box - Whether to (auto)box this type
        Returns:
        The type name (e.g "java.lang.String")