public final class ApNavigator extends Object implements Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
Navigator
implementation for annotation processing.
TODO: check the spec on how generics are supposed to be handledConstructor and Description |
---|
ApNavigator(ProcessingEnvironment env) |
Modifier and Type | Method and Description |
---|---|
TypeElement |
asDecl(Class c)
Gets the
C representation for the given class. |
TypeElement |
asDecl(TypeMirror m)
If the given type is an use of class declaration,
returns the type casted as
C . |
TypeMirror |
erasure(TypeMirror t)
Computes the erasure
|
TypeMirror |
getBaseClass(TypeMirror type,
TypeElement sup)
Gets the parameterization of the given base type.
|
Location |
getClassLocation(TypeElement typeElement)
Returns a location of the specified class.
|
String |
getClassName(TypeElement t)
Gets the fully-qualified name of the class.
|
String |
getClassShortName(TypeElement t)
Gets the short name of the class ("Object" for
Object .)
For nested classes, this method should just return the inner name. |
TypeMirror |
getComponentType(TypeMirror t)
Gets the component type of the array.
|
VariableElement |
getDeclaredField(TypeElement clazz,
String fieldName)
Gets the named field declared on the given class.
|
Collection<VariableElement> |
getDeclaredFields(TypeElement typeElement)
Gets all the declared fields of the given class.
|
Collection<ExecutableElement> |
getDeclaredMethods(TypeElement typeElement)
Gets all the declared methods of the given class
(regardless of their access modifiers, regardless
of whether they override methods of the base classes.)
|
TypeElement |
getDeclaringClassForField(VariableElement f)
Gets the class that declares the given field.
|
TypeElement |
getDeclaringClassForMethod(ExecutableElement m)
Gets the class that declares the given method.
|
VariableElement[] |
getEnumConstants(TypeElement clazz)
Gets the enumeration constants from an enum class.
|
Location |
getFieldLocation(VariableElement variableElement) |
String |
getFieldName(VariableElement f)
Gets the name of the field.
|
TypeMirror |
getFieldType(VariableElement f)
Gets the type of the field.
|
Location |
getMethodLocation(ExecutableElement executableElement) |
String |
getMethodName(ExecutableElement m)
Gets the name of the method, such as "toString" or "equals".
|
TypeMirror[] |
getMethodParameters(ExecutableElement m)
Returns the list of parameters to the method.
|
String |
getPackageName(TypeElement clazz)
Gets the package name of the given class.
|
TypeMirror |
getPrimitive(Class primitiveType)
Returns the representation for the given primitive type.
|
TypeMirror |
getReturnType(ExecutableElement m)
Gets the return type of a method.
|
TypeElement |
getSuperClass(TypeElement typeElement)
Gets the base class of the specified class.
|
TypeMirror |
getTypeArgument(TypeMirror typeMirror,
int i)
Gets the i-th type argument from a parameterized type.
|
String |
getTypeName(TypeMirror typeMirror)
Gets the display name of the type object
|
TypeMirror |
getVoidType()
Gets the representation of the primitive "void" type.
|
boolean |
hasDefaultConstructor(TypeElement t)
Returns true if the given class has a no-arg default constructor.
|
boolean |
isAbstract(TypeElement clazz)
Returns true if this is an abstract class.
|
boolean |
isArray(TypeMirror type)
Checks if the type is an array type.
|
boolean |
isArrayButNotByteArray(TypeMirror t)
Checks if the type is an array type but not byte[].
|
boolean |
isBridgeMethod(ExecutableElement method)
Returns true if this method is a bridge method as defined in JLS.
|
boolean |
isEnum(TypeElement t)
Returns true if this is an enum class.
|
boolean |
isFinal(TypeElement clazz)
Returns true if this is a final class.
|
boolean |
isFinalMethod(ExecutableElement m)
Returns true if the method is final.
|
boolean |
isInnerClass(TypeElement clazz)
Returns true if the given class is an inner class.
|
boolean |
isInterface(TypeElement clazz)
Returns true if 'clazz' is an interface.
|
boolean |
isOverriding(ExecutableElement method,
TypeElement base)
Returns true if the given method is overriding another one
defined in the base class 'base' or its ancestors.
|
boolean |
isParameterizedType(TypeMirror typeMirror)
Returns true if t is a parameterized type.
|
boolean |
isPrimitive(TypeMirror t)
Checks if the given type is a primitive type.
|
boolean |
isPublicField(VariableElement f)
Returns true if the field is public.
|
boolean |
isPublicMethod(ExecutableElement m)
Returns true if the method is public.
|
boolean |
isSameType(TypeMirror t1,
TypeMirror t2)
Checks if types are the same
|
boolean |
isStaticField(VariableElement f)
Returns true if the field is static.
|
boolean |
isStaticMethod(ExecutableElement m)
Returns true if the method is static.
|
boolean |
isSubClassOf(TypeMirror sub,
TypeMirror sup)
Checks if
sub is a sub-type of sup . |
boolean |
isTransient(VariableElement f)
Returns true if the field is transient.
|
TypeElement |
loadObjectFactory(TypeElement referencePoint,
String packageName)
Finds ObjectFactory for the given referencePoint.
|
TypeMirror |
ref(Class c)
Gets the representation of the given Java type in
T . |
TypeMirror |
use(TypeElement t)
Gets the T for the given C.
|
public ApNavigator(ProcessingEnvironment env)
public TypeElement getSuperClass(TypeElement typeElement)
Navigator
getSuperClass
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
Object
.public TypeMirror getBaseClass(TypeMirror type, TypeElement sup)
Navigator
For example, given the following
This method works like this:interface Foo extends List > {} interface Bar extends Foo
{}
getBaseClass( Bar, List ) = List getBaseClass( Bar, Foo ) = Foo
getBaseClass( Foo extends Number>, Collection ) = Collection > getBaseClass( ArrayList extends BigInteger>, List ) = List extends BigInteger>
getBaseClass
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
type
- The type that derives from baseType
sup
- The class whose parameterization we are interested in.baseType
in type
.
or null if the type is not assignable to the base type.public String getClassName(TypeElement t)
Navigator
Object
)getClassName
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public String getTypeName(TypeMirror typeMirror)
Navigator
getTypeName
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public String getClassShortName(TypeElement t)
Navigator
Object
.)
For nested classes, this method should just return the inner name.
(for example "Inner" for "com.acme.Outer$Inner".getClassShortName
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public Collection<VariableElement> getDeclaredFields(TypeElement typeElement)
Navigator
getDeclaredFields
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public VariableElement getDeclaredField(TypeElement clazz, String fieldName)
Navigator
getDeclaredField
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public Collection<ExecutableElement> getDeclaredMethods(TypeElement typeElement)
Navigator
Note that this method does not list methods declared on base classes.
getDeclaredMethods
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeElement getDeclaringClassForField(VariableElement f)
Navigator
getDeclaringClassForField
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeElement getDeclaringClassForMethod(ExecutableElement m)
Navigator
getDeclaringClassForMethod
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeMirror getFieldType(VariableElement f)
Navigator
getFieldType
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public String getFieldName(VariableElement f)
Navigator
getFieldName
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public String getMethodName(ExecutableElement m)
Navigator
getMethodName
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeMirror getReturnType(ExecutableElement m)
Navigator
getReturnType
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeMirror[] getMethodParameters(ExecutableElement m)
Navigator
getMethodParameters
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isStaticMethod(ExecutableElement m)
Navigator
isStaticMethod
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isFinalMethod(ExecutableElement m)
Navigator
isFinalMethod
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isSubClassOf(TypeMirror sub, TypeMirror sup)
Navigator
sub
is a sub-type of sup
.
TODO: should this method take T or C?isSubClassOf
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeMirror ref(Class c)
Navigator
T
.ref
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
c
- can be a primitive, array, class, or anything.
(therefore the return type has to be T, not C)public TypeMirror use(TypeElement t)
Navigator
use
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeElement asDecl(TypeMirror m)
Navigator
C
.
Otherwise null.
TODO: define the exact semantics.
asDecl
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeElement asDecl(Class c)
Navigator
C
representation for the given class.
The behavior is undefined if the class object represents
primitives, arrays, and other types that are not class declaration.asDecl
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeMirror erasure(TypeMirror t)
Navigator
erasure
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isAbstract(TypeElement clazz)
Navigator
isAbstract
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isFinal(TypeElement clazz)
Navigator
isFinal
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public VariableElement[] getEnumConstants(TypeElement clazz)
Navigator
getEnumConstants
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
clazz
- must derive from Enum
.public TypeMirror getVoidType()
Navigator
getVoidType
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public String getPackageName(TypeElement clazz)
Navigator
getPackageName
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeElement loadObjectFactory(TypeElement referencePoint, String packageName)
Navigator
loadObjectFactory
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
referencePoint
- The class that refers to the specified class.public boolean isBridgeMethod(ExecutableElement method)
Navigator
isBridgeMethod
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isOverriding(ExecutableElement method, TypeElement base)
Navigator
isOverriding
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isInterface(TypeElement clazz)
Navigator
isInterface
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isTransient(VariableElement f)
Navigator
isTransient
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isInnerClass(TypeElement clazz)
Navigator
isInnerClass
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isSameType(TypeMirror t1, TypeMirror t2)
Navigator
isSameType
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
t1
- typet2
- typepublic boolean isArray(TypeMirror type)
Navigator
isArray
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isArrayButNotByteArray(TypeMirror t)
Navigator
isArrayButNotByteArray
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeMirror getComponentType(TypeMirror t)
Navigator
getComponentType
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
t
- must be an array.public TypeMirror getTypeArgument(TypeMirror typeMirror, int i)
Navigator
getTypeArgument([Map<Integer,String>],0)=Integer
getTypeArgument
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
Navigator.isParameterizedType(Object)
public boolean isParameterizedType(TypeMirror typeMirror)
Navigator
isParameterizedType
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isPrimitive(TypeMirror t)
Navigator
isPrimitive
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public TypeMirror getPrimitive(Class primitiveType)
Navigator
getPrimitive
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
primitiveType
- must be Class objects like Integer.TYPE
.public Location getClassLocation(TypeElement typeElement)
Navigator
getClassLocation
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public Location getFieldLocation(VariableElement variableElement)
getFieldLocation
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public Location getMethodLocation(ExecutableElement executableElement)
getMethodLocation
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean hasDefaultConstructor(TypeElement t)
Navigator
hasDefaultConstructor
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isStaticField(VariableElement f)
Navigator
isStaticField
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isPublicMethod(ExecutableElement m)
Navigator
isPublicMethod
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isPublicField(VariableElement f)
Navigator
isPublicField
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public boolean isEnum(TypeElement t)
Navigator
isEnum
in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
Copyright © 2017 JBoss by Red Hat. All rights reserved.