- java.lang.Object
-
- com.sun.tools.jxc.model.nav.ApNavigator
-
- All Implemented Interfaces:
Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
public final class ApNavigator extends Object implements Navigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
Navigatorimplementation for annotation processing. TODO: check the spec on how generics are supposed to be handled- Author:
- Kohsuke Kawaguchi (kk@kohsuke.org)
-
-
Constructor Summary
Constructors Constructor Description ApNavigator(ProcessingEnvironment env)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeElementasDecl(Class<?> c)Gets theCrepresentation for the given class.TypeElementasDecl(TypeMirror m)If the given type is an use of class declaration, returns the type casted asC.TypeMirrorerasure(TypeMirror t)Computes the erasureTypeMirrorgetBaseClass(TypeMirror type, TypeElement sup)Gets the parameterization of the given base type.LocationgetClassLocation(TypeElement typeElement)Returns a location of the specified class.StringgetClassName(TypeElement t)Gets the fully-qualified name of the class.StringgetClassShortName(TypeElement t)Gets the short name of the class ("Object" forObject.) For nested classes, this method should just return the inner name.TypeMirrorgetComponentType(TypeMirror t)Gets the component type of the array.VariableElementgetDeclaredField(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.)TypeElementgetDeclaringClassForField(VariableElement f)Gets the class that declares the given field.TypeElementgetDeclaringClassForMethod(ExecutableElement m)Gets the class that declares the given method.VariableElement[]getEnumConstants(TypeElement clazz)Gets the enumeration constants from an enum class.LocationgetFieldLocation(VariableElement variableElement)StringgetFieldName(VariableElement f)Gets the name of the field.TypeMirrorgetFieldType(VariableElement f)Gets the type of the field.LocationgetMethodLocation(ExecutableElement executableElement)StringgetMethodName(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.StringgetPackageName(TypeElement clazz)Gets the package name of the given class.TypeMirrorgetPrimitive(Class<?> primitiveType)Returns the representation for the given primitive type.TypeMirrorgetReturnType(ExecutableElement m)Gets the return type of a method.TypeElementgetSuperClass(TypeElement typeElement)Gets the base class of the specified class.TypeMirrorgetTypeArgument(TypeMirror typeMirror, int i)Gets the i-th type argument from a parameterized type.StringgetTypeName(TypeMirror typeMirror)Gets the display name of the type objectTypeMirrorgetVoidType()Gets the representation of the primitive "void" type.booleanhasDefaultConstructor(TypeElement t)Returns true if the given class has a no-arg default constructor.booleanisAbstract(TypeElement clazz)Returns true if this is an abstract class.booleanisArray(TypeMirror type)Checks if the type is an array type.booleanisArrayButNotByteArray(TypeMirror t)Checks if the type is an array type but not byte[].booleanisBridgeMethod(ExecutableElement method)Returns true if this method is a bridge method as defined in JLS.booleanisEnum(TypeElement t)Returns true if this is an enum class.booleanisFinal(TypeElement clazz)Returns true if this is a final class.booleanisFinalMethod(ExecutableElement m)Returns true if the method is final.booleanisInnerClass(TypeElement clazz)Returns true if the given class is an inner class.booleanisInterface(TypeElement clazz)Returns true if 'clazz' is an interface.booleanisOverriding(ExecutableElement method, TypeElement base)Returns true if the given method is overriding another one defined in the base class 'base' or its ancestors.booleanisParameterizedType(TypeMirror typeMirror)Returns true if t is a parameterized type.booleanisPrimitive(TypeMirror t)Checks if the given type is a primitive type.booleanisPublicField(VariableElement f)Returns true if the field is public.booleanisPublicMethod(ExecutableElement m)Returns true if the method is public.booleanisSameType(TypeMirror t1, TypeMirror t2)Checks if types are the samebooleanisStaticField(VariableElement f)Returns true if the field is static.booleanisStaticMethod(ExecutableElement m)Returns true if the method is static.booleanisSubClassOf(TypeMirror sub, TypeMirror sup)Checks ifsubis a sub-type ofsup.booleanisTransient(VariableElement f)Returns true if the field is transient.TypeElementloadObjectFactory(TypeElement referencePoint, String packageName)Finds ObjectFactory for the given referencePoint.TypeMirrorref(Class<?> c)Gets the representation of the given Java type inT.TypeMirroruse(TypeElement t)Gets the T for the given C.
-
-
-
Constructor Detail
-
ApNavigator
public ApNavigator(ProcessingEnvironment env)
-
-
Method Detail
-
getSuperClass
public TypeElement getSuperClass(TypeElement typeElement)
Description copied from interface:NavigatorGets the base class of the specified class.- Specified by:
getSuperClassin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Returns:
- null if the parameter represents
Object.
-
getBaseClass
public TypeMirror getBaseClass(TypeMirror type, TypeElement sup)
Description copied from interface:NavigatorGets the parameterization of the given base type.For example, given the following
This method works like this:interface Foo<T> extends List<List<T>> {} interface Bar extends Foo<String> {}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>- Specified by:
getBaseClassin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Parameters:
type- The type that derives frombaseTypesup- The class whose parameterization we are interested in.- Returns:
- The use of
baseTypeintype. or null if the type is not assignable to the base type.
-
getClassName
public String getClassName(TypeElement t)
Description copied from interface:NavigatorGets the fully-qualified name of the class. ("java.lang.Object" forObject)- Specified by:
getClassNamein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getTypeName
public String getTypeName(TypeMirror typeMirror)
Description copied from interface:NavigatorGets the display name of the type object- Specified by:
getTypeNamein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Returns:
- a human-readable name that the type represents.
-
getClassShortName
public String getClassShortName(TypeElement t)
Description copied from interface:NavigatorGets the short name of the class ("Object" forObject.) For nested classes, this method should just return the inner name. (for example "Inner" for "com.acme.Outer$Inner".- Specified by:
getClassShortNamein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getDeclaredFields
public Collection<VariableElement> getDeclaredFields(TypeElement typeElement)
Description copied from interface:NavigatorGets all the declared fields of the given class.- Specified by:
getDeclaredFieldsin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getDeclaredField
public VariableElement getDeclaredField(TypeElement clazz, String fieldName)
Description copied from interface:NavigatorGets the named field declared on the given class. This method doesn't visit ancestors, but does recognize non-public fields.- Specified by:
getDeclaredFieldin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Returns:
- null if not found
-
getDeclaredMethods
public Collection<ExecutableElement> getDeclaredMethods(TypeElement typeElement)
Description copied from interface:NavigatorGets all the declared methods of the given class (regardless of their access modifiers, regardless of whether they override methods of the base classes.)Note that this method does not list methods declared on base classes.
- Specified by:
getDeclaredMethodsin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Returns:
- can be empty but always non-null.
-
getDeclaringClassForField
public TypeElement getDeclaringClassForField(VariableElement f)
Description copied from interface:NavigatorGets the class that declares the given field.- Specified by:
getDeclaringClassForFieldin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getDeclaringClassForMethod
public TypeElement getDeclaringClassForMethod(ExecutableElement m)
Description copied from interface:NavigatorGets the class that declares the given method.- Specified by:
getDeclaringClassForMethodin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getFieldType
public TypeMirror getFieldType(VariableElement f)
Description copied from interface:NavigatorGets the type of the field.- Specified by:
getFieldTypein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getFieldName
public String getFieldName(VariableElement f)
Description copied from interface:NavigatorGets the name of the field.- Specified by:
getFieldNamein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getMethodName
public String getMethodName(ExecutableElement m)
Description copied from interface:NavigatorGets the name of the method, such as "toString" or "equals".- Specified by:
getMethodNamein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getReturnType
public TypeMirror getReturnType(ExecutableElement m)
Description copied from interface:NavigatorGets the return type of a method.- Specified by:
getReturnTypein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getMethodParameters
public TypeMirror[] getMethodParameters(ExecutableElement m)
Description copied from interface:NavigatorReturns the list of parameters to the method.- Specified by:
getMethodParametersin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isStaticMethod
public boolean isStaticMethod(ExecutableElement m)
Description copied from interface:NavigatorReturns true if the method is static.- Specified by:
isStaticMethodin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isFinalMethod
public boolean isFinalMethod(ExecutableElement m)
Description copied from interface:NavigatorReturns true if the method is final.- Specified by:
isFinalMethodin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isSubClassOf
public boolean isSubClassOf(TypeMirror sub, TypeMirror sup)
Description copied from interface:NavigatorChecks ifsubis a sub-type ofsup. TODO: should this method take T or C?- Specified by:
isSubClassOfin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
ref
public TypeMirror ref(Class<?> c)
Description copied from interface:NavigatorGets the representation of the given Java type inT.- Specified by:
refin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Parameters:
c- can be a primitive, array, class, or anything. (therefore the return type has to be T, not C)
-
use
public TypeMirror use(TypeElement t)
Description copied from interface:NavigatorGets the T for the given C.- Specified by:
usein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
asDecl
public TypeElement asDecl(TypeMirror m)
Description copied from interface:NavigatorIf the given type is an use of class declaration, returns the type casted asC. Otherwise null.TODO: define the exact semantics.
- Specified by:
asDeclin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
asDecl
public TypeElement asDecl(Class<?> c)
Description copied from interface:NavigatorGets theCrepresentation for the given class. The behavior is undefined if the class object represents primitives, arrays, and other types that are not class declaration.- Specified by:
asDeclin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
erasure
public TypeMirror erasure(TypeMirror t)
Description copied from interface:NavigatorComputes the erasure- Specified by:
erasurein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isAbstract
public boolean isAbstract(TypeElement clazz)
Description copied from interface:NavigatorReturns true if this is an abstract class.- Specified by:
isAbstractin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isFinal
public boolean isFinal(TypeElement clazz)
Description copied from interface:NavigatorReturns true if this is a final class.- Specified by:
isFinalin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getEnumConstants
public VariableElement[] getEnumConstants(TypeElement clazz)
Description copied from interface:NavigatorGets the enumeration constants from an enum class.- Specified by:
getEnumConstantsin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Parameters:
clazz- must derive fromEnum.- Returns:
- can be empty but never null.
-
getVoidType
public TypeMirror getVoidType()
Description copied from interface:NavigatorGets the representation of the primitive "void" type.- Specified by:
getVoidTypein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getPackageName
public String getPackageName(TypeElement clazz)
Description copied from interface:NavigatorGets the package name of the given class.- Specified by:
getPackageNamein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Returns:
- i.e. "", "java.lang" but not null.
-
loadObjectFactory
public TypeElement loadObjectFactory(TypeElement referencePoint, String packageName)
Description copied from interface:NavigatorFinds ObjectFactory for the given referencePoint.- Specified by:
loadObjectFactoryin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Parameters:
referencePoint- The class that refers to the specified class.- Returns:
- null if not found.
-
isBridgeMethod
public boolean isBridgeMethod(ExecutableElement method)
Description copied from interface:NavigatorReturns true if this method is a bridge method as defined in JLS.- Specified by:
isBridgeMethodin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isOverriding
public boolean isOverriding(ExecutableElement method, TypeElement base)
Description copied from interface:NavigatorReturns true if the given method is overriding another one defined in the base class 'base' or its ancestors.- Specified by:
isOverridingin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isInterface
public boolean isInterface(TypeElement clazz)
Description copied from interface:NavigatorReturns true if 'clazz' is an interface.- Specified by:
isInterfacein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isTransient
public boolean isTransient(VariableElement f)
Description copied from interface:NavigatorReturns true if the field is transient.- Specified by:
isTransientin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isInnerClass
public boolean isInnerClass(TypeElement clazz)
Description copied from interface:NavigatorReturns true if the given class is an inner class. This is only used to improve the error diagnostics, so it's OK to fail to detect some inner classes as such. Note that this method should return false for nested classes (static classes.)- Specified by:
isInnerClassin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isSameType
public boolean isSameType(TypeMirror t1, TypeMirror t2)
Description copied from interface:NavigatorChecks if types are the same- Specified by:
isSameTypein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Parameters:
t1- typet2- type- Returns:
- true if types are the same
-
isArray
public boolean isArray(TypeMirror type)
Description copied from interface:NavigatorChecks if the type is an array type.- Specified by:
isArrayin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isArrayButNotByteArray
public boolean isArrayButNotByteArray(TypeMirror t)
Description copied from interface:NavigatorChecks if the type is an array type but not byte[].- Specified by:
isArrayButNotByteArrayin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getComponentType
public TypeMirror getComponentType(TypeMirror t)
Description copied from interface:NavigatorGets the component type of the array.- Specified by:
getComponentTypein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Parameters:
t- must be an array.
-
getTypeArgument
public TypeMirror getTypeArgument(TypeMirror typeMirror, int i)
Description copied from interface:NavigatorGets the i-th type argument from a parameterized type. For example,getTypeArgument([Map<Integer,String>],0)=Integer- Specified by:
getTypeArgumentin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- See Also:
Navigator.isParameterizedType(Object)
-
isParameterizedType
public boolean isParameterizedType(TypeMirror typeMirror)
Description copied from interface:NavigatorReturns true if t is a parameterized type.- Specified by:
isParameterizedTypein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isPrimitive
public boolean isPrimitive(TypeMirror t)
Description copied from interface:NavigatorChecks if the given type is a primitive type.- Specified by:
isPrimitivein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getPrimitive
public TypeMirror getPrimitive(Class<?> primitiveType)
Description copied from interface:NavigatorReturns the representation for the given primitive type.- Specified by:
getPrimitivein interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>- Parameters:
primitiveType- must be Class objects likeInteger.TYPE.
-
getClassLocation
public Location getClassLocation(TypeElement typeElement)
Description copied from interface:NavigatorReturns a location of the specified class.- Specified by:
getClassLocationin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getFieldLocation
public Location getFieldLocation(VariableElement variableElement)
- Specified by:
getFieldLocationin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
getMethodLocation
public Location getMethodLocation(ExecutableElement executableElement)
- Specified by:
getMethodLocationin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
hasDefaultConstructor
public boolean hasDefaultConstructor(TypeElement t)
Description copied from interface:NavigatorReturns true if the given class has a no-arg default constructor. The constructor does not need to be public.- Specified by:
hasDefaultConstructorin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isStaticField
public boolean isStaticField(VariableElement f)
Description copied from interface:NavigatorReturns true if the field is static.- Specified by:
isStaticFieldin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isPublicMethod
public boolean isPublicMethod(ExecutableElement m)
Description copied from interface:NavigatorReturns true if the method is public.- Specified by:
isPublicMethodin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isPublicField
public boolean isPublicField(VariableElement f)
Description copied from interface:NavigatorReturns true if the field is public.- Specified by:
isPublicFieldin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
isEnum
public boolean isEnum(TypeElement t)
Description copied from interface:NavigatorReturns true if this is an enum class.- Specified by:
isEnumin interfaceNavigator<TypeMirror,TypeElement,VariableElement,ExecutableElement>
-
-