com.sun.xml.bind.v2.model.nav
Interface Navigator<T,C,F,M>

All Known Implementing Classes:
APTNavigator, NavigatorImpl, ReflectionNavigator

public interface Navigator<T,C,F,M>

Provides unified view of the underlying reflection library, such as java.lang.reflect and/or APT.

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 APT) 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.


Field Summary
static ReflectionNavigator REFLECTION
          The singleton instance.
 
Method Summary
 C asDecl(Class c)
          Gets the C representation for the given class.
 C asDecl(T type)
          If the given type is an use of class declaration, returns the type casted as C.
<P> T
erasure(T contentInMemoryType)
          Computes the erasure
 C findClass(String className, C referencePoint)
          Finds the class/interface/enum/annotation of the given name.
 T getBaseClass(T type, C baseType)
          Gets the parameterization of the given base type.
 Location getClassLocation(C clazz)
          Returns a location of the specified class.
 String getClassName(C clazz)
          Gets the fully-qualified name of the class.
 String getClassShortName(C clazz)
          Gets the short name of the class ("Object" for Object.) For nested classes, this method should just return the inner name.
 T getComponentType(T t)
          Gets the component type of the array.
 F 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.)
 C getDeclaringClassForField(F field)
          Gets the class that declares the given field.
 C getDeclaringClassForMethod(M method)
          Gets the class that declares the given method.
 F[] getEnumConstants(C clazz)
          Gets the enumeration constants from an enum class.
 Location getFieldLocation(F field)
           
 String getFieldName(F field)
          Gets the name of the field.
 T getFieldType(F f)
          Gets the type of the field.
 Location getMethodLocation(M getter)
           
 String 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.
 String getPackageName(C clazz)
          Gets the package name of the given class.
 T getPrimitive(Class primitiveType)
          Returns the representation for the given primitive type.
 T getReturnType(M m)
          Gets the return type of a method.
 C getSuperClass(C clazz)
          Gets the base class of the specified class.
 T getTypeArgument(T t, int i)
          Gets the i-th type argument from a parameterized type.
 String getTypeName(T rawType)
          Gets the display name of the type object
 T getVoidType()
          Gets 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 isArray(T t)
          Checks if the type is an array type.
 boolean isArrayButNotByteArray(T t)
          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 isEnum(C clazz)
          Returns true if this is an enum class.
 boolean isFinal(C clazz)
          Returns true if this is a final class.
 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 isParameterizedType(T t)
          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 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 if sub is a sub-type of sup.
 boolean isTransient(F f)
          Returns true if the field is transient.
 T ref(Class c)
          Gets the representation of the given Java type in T.
 T use(C c)
          Gets the T for the given C.
 

Field Detail

REFLECTION

static final ReflectionNavigator REFLECTION
The singleton instance.

Method Detail

getSuperClass

C getSuperClass(C clazz)
Gets the base class of the specified class.

Returns:
null if the parameter represents Object.

getBaseClass

T getBaseClass(T type,
               C baseType)
Gets the parameterization of the given base type.

For 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>
 

Parameters:
type - The type that derives from baseType
baseType - The class whose parameterization we are interested in.
Returns:
The use of baseType in type. or null if the type is not assignable to the base type.

getClassName

String getClassName(C clazz)
Gets the fully-qualified name of the class. ("java.lang.Object" for Object)


getTypeName

String getTypeName(T rawType)
Gets the display name of the type object

Returns:
a human-readable name that the type represents.

getClassShortName

String getClassShortName(C clazz)
Gets the short name of the class ("Object" for Object.) For nested classes, this method should just return the inner name. (for example "Inner" for "com.acme.Outer$Inner".


getDeclaredFields

Collection<? extends F> getDeclaredFields(C clazz)
Gets all the declared fields of the given class.


getDeclaredField

F getDeclaredField(C clazz,
                   String fieldName)
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

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.)

Note that this method does not list methods declared on base classes.

Returns:
can be empty but always non-null.

getDeclaringClassForField

C getDeclaringClassForField(F field)
Gets the class that declares the given field.


getDeclaringClassForMethod

C getDeclaringClassForMethod(M method)
Gets the class that declares the given method.


getFieldType

T getFieldType(F f)
Gets the type of the field.


getFieldName

String getFieldName(F field)
Gets the name of the field.


getMethodName

String getMethodName(M m)
Gets the name of the method, such as "toString" or "equals".


getReturnType

T getReturnType(M m)
Gets the return type of a method.


getMethodParameters

T[] getMethodParameters(M method)
Returns the list of parameters to the method.


isStaticMethod

boolean isStaticMethod(M method)
Returns true if the method is static.


isSubClassOf

boolean isSubClassOf(T sub,
                     T sup)
Checks if sub is a sub-type of sup. TODO: should this method take T or C?


ref

T ref(Class c)
Gets the representation of the given Java type in T.

Parameters:
c - can be a primitive, array, class, or anything. (therefore the return type has to be T, not C)

use

T use(C c)
Gets the T for the given C.


asDecl

C asDecl(T type)
If the given type is an use of class declaration, returns the type casted as C. Otherwise null.

TODO: define the exact semantics.


asDecl

C asDecl(Class c)
Gets the 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.


isArray

boolean isArray(T t)
Checks if the type is an array type.


isArrayButNotByteArray

boolean isArrayButNotByteArray(T t)
Checks if the type is an array type but not byte[].


getComponentType

T getComponentType(T t)
Gets the component type of the array.

Parameters:
t - must be an array.

getTypeArgument

T getTypeArgument(T t,
                  int i)
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 type
IndexOutOfBoundsException - If i is out of range.
See Also:
isParameterizedType(Object)

isParameterizedType

boolean isParameterizedType(T t)
Returns true if t is a parameterized type.


isPrimitive

boolean isPrimitive(T t)
Checks if the given type is a primitive type.


getPrimitive

T getPrimitive(Class primitiveType)
Returns the representation for the given primitive type.

Parameters:
primitiveType - must be Class objects like Integer.TYPE.

getClassLocation

Location getClassLocation(C clazz)
Returns a location of the specified class.


getFieldLocation

Location getFieldLocation(F field)

getMethodLocation

Location getMethodLocation(M getter)

hasDefaultConstructor

boolean hasDefaultConstructor(C clazz)
Returns true if the given class has a no-arg default constructor. The constructor does not need to be public.


isStaticField

boolean isStaticField(F field)
Returns true if the field is static.


isPublicMethod

boolean isPublicMethod(M method)
Returns true if the method is public.


isPublicField

boolean isPublicField(F field)
Returns true if the field is public.


isEnum

boolean isEnum(C clazz)
Returns true if this is an enum class.


erasure

<P> T erasure(T contentInMemoryType)
Computes the erasure


isAbstract

boolean isAbstract(C clazz)
Returns true if this is an abstract class.


isFinal

boolean isFinal(C clazz)
Returns true if this is a final class.


getEnumConstants

F[] getEnumConstants(C clazz)
Gets the enumeration constants from an enum class.

Parameters:
clazz - must derive from Enum.
Returns:
can be empty but never null.

getVoidType

T getVoidType()
Gets the representation of the primitive "void" type.


getPackageName

String getPackageName(C clazz)
Gets the package name of the given class.

Returns:
i.e. "", "java.lang" but not null.

findClass

C findClass(String className,
            C referencePoint)
Finds the class/interface/enum/annotation of the given name.

Parameters:
referencePoint - The class that refers to the specified class.
Returns:
null if not found.

isBridgeMethod

boolean isBridgeMethod(M method)
Returns true if this method is a bridge method as defined in JLS.


isOverriding

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.


isInterface

boolean isInterface(C clazz)
Returns true if 'clazz' is an interface.


isTransient

boolean isTransient(F f)
Returns true if the field is transient.


isInnerClass

boolean isInnerClass(C clazz)
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.)