org.datanucleus.util
Class AnnotationProcessorUtils

java.lang.Object
  extended by org.datanucleus.util.AnnotationProcessorUtils

public class AnnotationProcessorUtils
extends java.lang.Object

Series of method to aid in the writing of annotation processors.


Nested Class Summary
static class AnnotationProcessorUtils.TypeCategory
           
 
Constructor Summary
AnnotationProcessorUtils()
           
 
Method Summary
static javax.lang.model.type.TypeMirror getDeclaredType(javax.lang.model.element.Element elem)
          Accessor for the declared type of this element.
static java.lang.String getDeclaredTypeName(javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.type.TypeMirror type, boolean box)
          Method to return the declared type name of the provided TypeMirror.
static java.util.List<? extends javax.lang.model.element.Element> getFieldMembers(javax.lang.model.element.TypeElement el)
          Convenience accessor for all field members of the supplied type element.
static java.lang.String getMemberName(javax.lang.model.element.Element el)
          Accessor for the member name for a field or Java bean getter/setter.
static java.util.List<? extends javax.lang.model.element.Element> getPropertyMembers(javax.lang.model.element.TypeElement el)
          Convenience accessor for all property members of the supplied type element.
static AnnotationProcessorUtils.TypeCategory getTypeCategoryForTypeMirror(java.lang.String typeName)
          Method to return the JPA2 type category for a type.
static java.lang.Object getValueForAnnotationAttribute(javax.lang.model.element.Element elem, java.lang.Class annotCls, java.lang.String attribute)
          Accessor for the value for an annotation attribute.
static boolean isJavaBeanGetter(javax.lang.model.element.ExecutableElement method)
          Convenience method to return if the provided method is a java bean getter.
static boolean isJavaBeanSetter(javax.lang.model.element.ExecutableElement method)
          Convenience method to return if the provided method is a java bean setter.
static boolean isMethod(javax.lang.model.element.Element elem)
          Convenience method to return if the provided element represents a method (otherwise a field).
static boolean returnsBoolean(javax.lang.model.element.ExecutableElement method)
          Convenience method returning if the provided method returns boolean.
static boolean returnsVoid(javax.lang.model.element.ExecutableElement method)
          Convenience method returning if the provided method returns void.
static boolean typeIsPrimitive(javax.lang.model.type.TypeMirror type)
          Convenience method to return if the provided type is a primitive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationProcessorUtils

public AnnotationProcessorUtils()
Method Detail

getTypeCategoryForTypeMirror

public static AnnotationProcessorUtils.TypeCategory getTypeCategoryForTypeMirror(java.lang.String typeName)
Method to return the JPA2 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 java.util.List<? extends javax.lang.model.element.Element> getFieldMembers(javax.lang.model.element.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 java.util.List<? extends javax.lang.model.element.Element> getPropertyMembers(javax.lang.model.element.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(javax.lang.model.element.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 java.lang.String getMemberName(javax.lang.model.element.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(javax.lang.model.element.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(javax.lang.model.element.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 javax.lang.model.type.TypeMirror getDeclaredType(javax.lang.model.element.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 java.lang.Object getValueForAnnotationAttribute(javax.lang.model.element.Element elem,
                                                              java.lang.Class annotCls,
                                                              java.lang.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(javax.lang.model.element.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(javax.lang.model.element.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(javax.lang.model.type.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 java.lang.String getDeclaredTypeName(javax.annotation.processing.ProcessingEnvironment processingEnv,
                                                   javax.lang.model.type.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")


Copyright © 2011. All Rights Reserved.