Package com.sun.tools.jxc.model.nav
Class ApNavigator
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>
Navigator
implementation for annotation processing.
TODO: check the spec on how generics are supposed to be handled- Author:
- Kohsuke Kawaguchi (kk@kohsuke.org)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets theC
representation for the given class.asDecl
(TypeMirror m) If the given type is an use of class declaration, returns the type casted asC
.Computes the erasuregetBaseClass
(TypeMirror type, TypeElement sup) Gets the parameterization of the given base type.getClassLocation
(TypeElement typeElement) Returns a location of the specified class.Gets the fully-qualified name of the class.Gets the short name of the class ("Object" forObject
.) For nested classes, this method should just return the inner name.Gets the component type of the array.getDeclaredField
(TypeElement clazz, String fieldName) Gets the named field declared on the given class.getDeclaredFields
(TypeElement typeElement) Gets all the declared fields of the given class.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.)Gets the class that declares the given field.Gets the class that declares the given method.getEnumConstants
(TypeElement clazz) Gets the enumeration constants from an enum class.getFieldLocation
(VariableElement variableElement) Gets the name of the field.Gets the type of the field.getMethodLocation
(ExecutableElement executableElement) Gets the name of the method, such as "toString" or "equals".Returns the list of parameters to the method.getPackageName
(TypeElement clazz) Gets the package name of the given class.getPrimitive
(Class primitiveType) Returns the representation for the given primitive type.Gets the return type of a method.getSuperClass
(TypeElement typeElement) Gets the base class of the specified class.getTypeArgument
(TypeMirror typeMirror, int i) Gets the i-th type argument from a parameterized type.getTypeName
(TypeMirror typeMirror) Gets the display name of the type objectGets the representation of the primitive "void" type.boolean
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
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
Returns true if this is an enum class.boolean
isFinal
(TypeElement clazz) Returns true if this is a final class.boolean
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
Checks if the given type is a primitive type.boolean
Returns true if the field is public.boolean
Returns true if the method is public.boolean
isSameType
(TypeMirror t1, TypeMirror t2) Checks if types are the sameboolean
Returns true if the field is static.boolean
Returns true if the method is static.boolean
isSubClassOf
(TypeMirror sub, TypeMirror sup) Checks ifsub
is a sub-type ofsup
.boolean
Returns true if the field is transient.loadObjectFactory
(TypeElement referencePoint, String packageName) Finds ObjectFactory for the given referencePoint.Gets the representation of the given Java type inT
.use
(TypeElement t) Gets the T for the given C.
-
Constructor Details
-
ApNavigator
-
-
Method Details
-
getSuperClass
Description copied from interface:Navigator
Gets the base class of the specified class.- Specified by:
getSuperClass
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Returns:
- null if the parameter represents
Object
.
-
getBaseClass
Description copied from interface:Navigator
Gets 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:
getBaseClass
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Parameters:
type
- The type that derives frombaseType
sup
- The class whose parameterization we are interested in.- Returns:
- The use of
baseType
intype
. or null if the type is not assignable to the base type.
-
getClassName
Description copied from interface:Navigator
Gets the fully-qualified name of the class. ("java.lang.Object" forObject
)- Specified by:
getClassName
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getTypeName
Description copied from interface:Navigator
Gets the display name of the type object- Specified by:
getTypeName
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Returns:
- a human-readable name that the type represents.
-
getClassShortName
Description copied from interface:Navigator
Gets 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:
getClassShortName
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getDeclaredFields
Description copied from interface:Navigator
Gets all the declared fields of the given class.- Specified by:
getDeclaredFields
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getDeclaredField
Description copied from interface:Navigator
Gets the named field declared on the given class. This method doesn't visit ancestors, but does recognize non-public fields.- Specified by:
getDeclaredField
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Returns:
- null if not found
-
getDeclaredMethods
Description copied from interface:Navigator
Gets 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:
getDeclaredMethods
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Returns:
- can be empty but always non-null.
-
getDeclaringClassForField
Description copied from interface:Navigator
Gets the class that declares the given field.- Specified by:
getDeclaringClassForField
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getDeclaringClassForMethod
Description copied from interface:Navigator
Gets the class that declares the given method.- Specified by:
getDeclaringClassForMethod
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getFieldType
Description copied from interface:Navigator
Gets the type of the field.- Specified by:
getFieldType
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getFieldName
Description copied from interface:Navigator
Gets the name of the field.- Specified by:
getFieldName
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getMethodName
Description copied from interface:Navigator
Gets the name of the method, such as "toString" or "equals".- Specified by:
getMethodName
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getReturnType
Description copied from interface:Navigator
Gets the return type of a method.- Specified by:
getReturnType
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getMethodParameters
Description copied from interface:Navigator
Returns the list of parameters to the method.- Specified by:
getMethodParameters
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isStaticMethod
Description copied from interface:Navigator
Returns true if the method is static.- Specified by:
isStaticMethod
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isFinalMethod
Description copied from interface:Navigator
Returns true if the method is final.- Specified by:
isFinalMethod
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isSubClassOf
Description copied from interface:Navigator
Checks ifsub
is a sub-type ofsup
. TODO: should this method take T or C?- Specified by:
isSubClassOf
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
ref
Description copied from interface:Navigator
Gets the representation of the given Java type inT
.- Specified by:
ref
in 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
Description copied from interface:Navigator
Gets the T for the given C.- Specified by:
use
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
asDecl
Description copied from interface:Navigator
If the given type is an use of class declaration, returns the type casted asC
. Otherwise null.TODO: define the exact semantics.
- Specified by:
asDecl
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
asDecl
Description copied from interface:Navigator
Gets theC
representation 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:
asDecl
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
erasure
Description copied from interface:Navigator
Computes the erasure- Specified by:
erasure
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isAbstract
Description copied from interface:Navigator
Returns true if this is an abstract class.- Specified by:
isAbstract
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isFinal
Description copied from interface:Navigator
Returns true if this is a final class.- Specified by:
isFinal
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getEnumConstants
Description copied from interface:Navigator
Gets the enumeration constants from an enum class.- Specified by:
getEnumConstants
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Parameters:
clazz
- must derive fromEnum
.- Returns:
- can be empty but never null.
-
getVoidType
Description copied from interface:Navigator
Gets the representation of the primitive "void" type.- Specified by:
getVoidType
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getPackageName
Description copied from interface:Navigator
Gets the package name of the given class.- Specified by:
getPackageName
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Returns:
- i.e. "", "java.lang" but not null.
-
loadObjectFactory
Description copied from interface:Navigator
Finds ObjectFactory for the given referencePoint.- Specified by:
loadObjectFactory
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Parameters:
referencePoint
- The class that refers to the specified class.- Returns:
- null if not found.
-
isBridgeMethod
Description copied from interface:Navigator
Returns true if this method is a bridge method as defined in JLS.- Specified by:
isBridgeMethod
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isOverriding
Description copied from interface:Navigator
Returns true if the given method is overriding another one defined in the base class 'base' or its ancestors.- Specified by:
isOverriding
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isInterface
Description copied from interface:Navigator
Returns true if 'clazz' is an interface.- Specified by:
isInterface
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isTransient
Description copied from interface:Navigator
Returns true if the field is transient.- Specified by:
isTransient
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isInnerClass
Description copied from interface:Navigator
Returns 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:
isInnerClass
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isSameType
Description copied from interface:Navigator
Checks if types are the same- Specified by:
isSameType
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Parameters:
t1
- typet2
- type- Returns:
- true if types are the same
-
isArray
Description copied from interface:Navigator
Checks if the type is an array type.- Specified by:
isArray
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isArrayButNotByteArray
Description copied from interface:Navigator
Checks if the type is an array type but not byte[].- Specified by:
isArrayButNotByteArray
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getComponentType
Description copied from interface:Navigator
Gets the component type of the array.- Specified by:
getComponentType
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Parameters:
t
- must be an array.
-
getTypeArgument
Description copied from interface:Navigator
Gets the i-th type argument from a parameterized type. For example,getTypeArgument([Map<Integer,String>],0)=Integer
- Specified by:
getTypeArgument
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - See Also:
-
isParameterizedType
Description copied from interface:Navigator
Returns true if t is a parameterized type.- Specified by:
isParameterizedType
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isPrimitive
Description copied from interface:Navigator
Checks if the given type is a primitive type.- Specified by:
isPrimitive
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getPrimitive
Description copied from interface:Navigator
Returns the representation for the given primitive type.- Specified by:
getPrimitive
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement> - Parameters:
primitiveType
- must be Class objects likeInteger.TYPE
.
-
getClassLocation
Description copied from interface:Navigator
Returns a location of the specified class.- Specified by:
getClassLocation
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getFieldLocation
- Specified by:
getFieldLocation
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
getMethodLocation
- Specified by:
getMethodLocation
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
hasDefaultConstructor
Description copied from interface:Navigator
Returns true if the given class has a no-arg default constructor. The constructor does not need to be public.- Specified by:
hasDefaultConstructor
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isStaticField
Description copied from interface:Navigator
Returns true if the field is static.- Specified by:
isStaticField
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isPublicMethod
Description copied from interface:Navigator
Returns true if the method is public.- Specified by:
isPublicMethod
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isPublicField
Description copied from interface:Navigator
Returns true if the field is public.- Specified by:
isPublicField
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-
isEnum
Description copied from interface:Navigator
Returns true if this is an enum class.- Specified by:
isEnum
in interfaceNavigator<TypeMirror,
TypeElement, VariableElement, ExecutableElement>
-