Package com.sun.xml.bind.v2.model.nav
Interface Navigator<T,C,F,M>
- All Known Implementing Classes:
ApNavigator
,NavigatorImpl
public interface Navigator<T,C,F,M>
Provides unified view of the underlying reflection library,
such as
java.lang.reflect
and/or Annotation Processing.
This interface provides navigation over the reflection model
to decouple the caller from any particular implementation.
This allows the JAXB RI to reuse much of the code between
the compile time (which works on top of Annotation Processing) and the run-time
(which works on top of java.lang.reflect
)
Navigator
instances are stateless and immutable.
Parameterization
C
A Java class declaration (not an interface, a class and an enum.)
T
A Java type. This includs declaration, but also includes such things like arrays, primitive types, parameterized types, and etc.
- Author:
- Kohsuke Kawaguchi (kk@kohsuke.org)
-
Method Summary
Modifier and TypeMethodDescriptionGets theC
representation for the given class.If the given type is an use of class declaration, returns the type casted asC
.<P> T
Computes the erasuregetBaseClass
(T type, C baseType) Gets the parameterization of the given base type.getClassLocation
(C clazz) Returns a location of the specified class.getClassName
(C clazz) Gets the fully-qualified name of the class.getClassShortName
(C clazz) 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
(C clazz, String fieldName) Gets the named field declared on the given class.Collection
<? extends F> getDeclaredFields
(C clazz) Gets all the declared fields of the given class.Collection
<? extends M> getDeclaredMethods
(C clazz) Gets all the declared methods of the given class (regardless of their access modifiers, regardless of whether they override methods of the base classes.)getDeclaringClassForField
(F field) Gets the class that declares the given field.getDeclaringClassForMethod
(M method) Gets the class that declares the given method.F[]
getEnumConstants
(C clazz) Gets the enumeration constants from an enum class.getFieldLocation
(F field) getFieldName
(F field) Gets the name of the field.getFieldType
(F f) Gets the type of the field.getMethodLocation
(M getter) getMethodName
(M m) Gets the name of the method, such as "toString" or "equals".T[]
getMethodParameters
(M method) Returns the list of parameters to the method.getPackageName
(C clazz) Gets the package name of the given class.getPrimitive
(Class primitiveType) Returns the representation for the given primitive type.getReturnType
(M m) Gets the return type of a method.getSuperClass
(C clazz) Gets the base class of the specified class.getTypeArgument
(T t, int i) Gets the i-th type argument from a parameterized type.getTypeName
(T rawType) Gets the display name of the type objectGets the representation of the primitive "void" type.boolean
hasDefaultConstructor
(C clazz) Returns true if the given class has a no-arg default constructor.boolean
isAbstract
(C clazz) Returns true if this is an abstract class.boolean
Checks if the type is an array type.boolean
Checks if the type is an array type but not byte[].boolean
isBridgeMethod
(M method) Returns true if this method is a bridge method as defined in JLS.boolean
Returns true if this is an enum class.boolean
Returns true if this is a final class.boolean
isFinalMethod
(M method) Returns true if the method is final.boolean
isInnerClass
(C clazz) Returns true if the given class is an inner class.boolean
isInterface
(C clazz) Returns true if 'clazz' is an interface.boolean
isOverriding
(M method, C base) Returns true if the given method is overriding another one defined in the base class 'base' or its ancestors.boolean
Returns true if t is a parameterized type.boolean
isPrimitive
(T t) Checks if the given type is a primitive type.boolean
isPublicField
(F field) Returns true if the field is public.boolean
isPublicMethod
(M method) Returns true if the method is public.boolean
isSameType
(T t1, T t2) Checks if types are the sameboolean
isStaticField
(F field) Returns true if the field is static.boolean
isStaticMethod
(M method) Returns true if the method is static.boolean
isSubClassOf
(T sub, T sup) Checks ifsub
is a sub-type ofsup
.boolean
isTransient
(F f) Returns true if the field is transient.loadObjectFactory
(C referencePoint, String packageName) Finds ObjectFactory for the given referencePoint.Gets the representation of the given Java type inT
.Gets the T for the given C.
-
Method Details
-
getSuperClass
Gets the base class of the specified class.- Returns:
- null if the parameter represents
Object
.
-
getBaseClass
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>
- Parameters:
type
- The type that derives frombaseType
baseType
- 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
Gets the fully-qualified name of the class. ("java.lang.Object" forObject
) -
getTypeName
Gets the display name of the type object- Returns:
- a human-readable name that the type represents.
-
getClassShortName
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". -
getDeclaredFields
Gets all the declared fields of the given class. -
getDeclaredField
Gets the named field declared on the given class. This method doesn't visit ancestors, but does recognize non-public fields.- Returns:
- null if not found
-
getDeclaredMethods
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.
- Returns:
- can be empty but always non-null.
-
getDeclaringClassForField
Gets the class that declares the given field. -
getDeclaringClassForMethod
Gets the class that declares the given method. -
getFieldType
Gets the type of the field. -
getFieldName
Gets the name of the field. -
getMethodName
Gets the name of the method, such as "toString" or "equals". -
getReturnType
Gets the return type of a method. -
getMethodParameters
Returns the list of parameters to the method. -
isStaticMethod
Returns true if the method is static. -
isSubClassOf
Checks ifsub
is a sub-type ofsup
. TODO: should this method take T or C? -
ref
Gets the representation of the given Java type inT
.- Parameters:
c
- can be a primitive, array, class, or anything. (therefore the return type has to be T, not C)
-
use
Gets the T for the given C. -
asDecl
If the given type is an use of class declaration, returns the type casted asC
. Otherwise null.TODO: define the exact semantics.
-
asDecl
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. -
isArray
Checks if the type is an array type. -
isArrayButNotByteArray
Checks if the type is an array type but not byte[]. -
getComponentType
Gets the component type of the array.- Parameters:
t
- must be an array.
-
getTypeArgument
Gets the i-th type argument from a parameterized type. For example,getTypeArgument([Map<Integer,String>],0)=Integer
- Throws:
IllegalArgumentException
- If t is not a parameterized typeIndexOutOfBoundsException
- If i is out of range.- See Also:
-
isParameterizedType
Returns true if t is a parameterized type. -
isPrimitive
Checks if the given type is a primitive type. -
getPrimitive
Returns the representation for the given primitive type.- Parameters:
primitiveType
- must be Class objects likeInteger.TYPE
.
-
getClassLocation
Returns a location of the specified class. -
getFieldLocation
-
getMethodLocation
-
hasDefaultConstructor
Returns true if the given class has a no-arg default constructor. The constructor does not need to be public. -
isStaticField
Returns true if the field is static. -
isPublicMethod
Returns true if the method is public. -
isFinalMethod
Returns true if the method is final. -
isPublicField
Returns true if the field is public. -
isEnum
Returns true if this is an enum class. -
erasure
Computes the erasure -
isAbstract
Returns true if this is an abstract class. -
isFinal
Returns true if this is a final class. -
getEnumConstants
Gets the enumeration constants from an enum class.- Parameters:
clazz
- must derive fromEnum
.- Returns:
- can be empty but never null.
-
getVoidType
T getVoidType()Gets the representation of the primitive "void" type. -
getPackageName
Gets the package name of the given class.- Returns:
- i.e. "", "java.lang" but not null.
-
loadObjectFactory
Finds ObjectFactory for the given referencePoint.- Parameters:
referencePoint
- The class that refers to the specified class.- Returns:
- null if not found.
-
isBridgeMethod
Returns true if this method is a bridge method as defined in JLS. -
isOverriding
Returns true if the given method is overriding another one defined in the base class 'base' or its ancestors. -
isInterface
Returns true if 'clazz' is an interface. -
isTransient
Returns true if the field is transient. -
isInnerClass
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.) -
isSameType
Checks if types are the same- Parameters:
t1
- typet2
- type- Returns:
- true if types are the same
-