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 handled| Constructor 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)
NavigatorgetSuperClass in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>Object.public TypeMirror getBaseClass(TypeMirror type, TypeElement sup)
NavigatorFor example, given the following
interface Foo<T> extends List<List<T>> {}
interface Bar extends Foo<String> {}
This method works like this:
getBaseClass( Bar, List ) = List<List<String>>
getBaseClass( Bar, Foo ) = Foo<String>
getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>>
getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger>
getBaseClass in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>type - The type that derives from baseTypesup - 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)
NavigatorObject)getClassName in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public String getTypeName(TypeMirror typeMirror)
NavigatorgetTypeName in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public String getClassShortName(TypeElement t)
NavigatorObject.)
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)
NavigatorgetDeclaredFields in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public VariableElement getDeclaredField(TypeElement clazz, String fieldName)
NavigatorgetDeclaredField in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public Collection<ExecutableElement> getDeclaredMethods(TypeElement typeElement)
NavigatorNote that this method does not list methods declared on base classes.
getDeclaredMethods in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeElement getDeclaringClassForField(VariableElement f)
NavigatorgetDeclaringClassForField in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeElement getDeclaringClassForMethod(ExecutableElement m)
NavigatorgetDeclaringClassForMethod in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeMirror getFieldType(VariableElement f)
NavigatorgetFieldType in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public String getFieldName(VariableElement f)
NavigatorgetFieldName in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public String getMethodName(ExecutableElement m)
NavigatorgetMethodName in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeMirror getReturnType(ExecutableElement m)
NavigatorgetReturnType in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeMirror[] getMethodParameters(ExecutableElement m)
NavigatorgetMethodParameters in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isStaticMethod(ExecutableElement m)
NavigatorisStaticMethod in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isFinalMethod(ExecutableElement m)
NavigatorisFinalMethod in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isSubClassOf(TypeMirror sub, TypeMirror sup)
Navigatorsub 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)
NavigatorT.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)
Navigatoruse in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeElement asDecl(TypeMirror m)
NavigatorC.
Otherwise null.
TODO: define the exact semantics.
asDecl in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeElement asDecl(Class c)
NavigatorC 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)
Navigatorerasure in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isAbstract(TypeElement clazz)
NavigatorisAbstract in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isFinal(TypeElement clazz)
NavigatorisFinal in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public VariableElement[] getEnumConstants(TypeElement clazz)
NavigatorgetEnumConstants in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>clazz - must derive from Enum.public TypeMirror getVoidType()
NavigatorgetVoidType in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public String getPackageName(TypeElement clazz)
NavigatorgetPackageName in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeElement loadObjectFactory(TypeElement referencePoint, String packageName)
NavigatorloadObjectFactory in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>referencePoint - The class that refers to the specified class.public boolean isBridgeMethod(ExecutableElement method)
NavigatorisBridgeMethod in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isOverriding(ExecutableElement method, TypeElement base)
NavigatorisOverriding in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isInterface(TypeElement clazz)
NavigatorisInterface in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isTransient(VariableElement f)
NavigatorisTransient in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isInnerClass(TypeElement clazz)
NavigatorisInnerClass in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isSameType(TypeMirror t1, TypeMirror t2)
NavigatorisSameType in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>t1 - typet2 - typepublic boolean isArray(TypeMirror type)
NavigatorisArray in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isArrayButNotByteArray(TypeMirror t)
NavigatorisArrayButNotByteArray in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeMirror getComponentType(TypeMirror t)
NavigatorgetComponentType in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>t - must be an array.public TypeMirror getTypeArgument(TypeMirror typeMirror, int i)
NavigatorgetTypeArgument([Map<Integer,String>],0)=IntegergetTypeArgument in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>Navigator.isParameterizedType(Object)public boolean isParameterizedType(TypeMirror typeMirror)
NavigatorisParameterizedType in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isPrimitive(TypeMirror t)
NavigatorisPrimitive in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public TypeMirror getPrimitive(Class primitiveType)
NavigatorgetPrimitive in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>primitiveType - must be Class objects like Integer.TYPE.public Location getClassLocation(TypeElement typeElement)
NavigatorgetClassLocation 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)
NavigatorhasDefaultConstructor in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isStaticField(VariableElement f)
NavigatorisStaticField in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isPublicMethod(ExecutableElement m)
NavigatorisPublicMethod in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isPublicField(VariableElement f)
NavigatorisPublicField in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>public boolean isEnum(TypeElement t)
NavigatorisEnum in interface Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>Copyright © 2018 JBoss by Red Hat. All rights reserved.