Top Description Methods
org.glassfish.jaxb.core.v2.model.nav

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

Known Direct Implementers
org.glassfish.jaxb.core.v2.model.nav.ReflectionNavigator, com.sun.tools.xjc.model.nav.NavigatorImpl, com.sun.tools.jxc.model.nav.ApNavigator
Imports
java.util.Collection, org.glassfish.jaxb.core.v2.runtime.Location

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 ([email protected])

Method Summary

Modifier and TypeMethod and Description
public C
asDecl(T type)

If the given type is an use of class declaration, returns the type casted as C.

public C
asDecl(Class<?> c)

Gets the C representation for the given class.

public <P> T
erasure(T contentInMemoryType)

Computes the erasure

public T

Returns:

The use of baseType in type. or null if the type is not assignable to the base type.
getBaseClass
(T
The type that derives from baseType
type
,
C
The class whose parameterization we are interested in.
baseType
)

Gets the parameterization of the given base type.

public Location
getClassLocation(C clazz)

Returns a location of the specified class.

public String
getClassName(C clazz)

Gets the fully-qualified name of the class.

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

public T
getComponentType(T
must be an array.
t
)

Gets the component type of the array.

public F

Returns:

null if not found
getDeclaredField
(C clazz, String fieldName)

Gets the named field declared on the given class.

public Collection<? extends F>
getDeclaredFields(C clazz)

Gets all the declared fields of the given class.

public Collection<? extends M>

Returns:

can be empty but always non-null.
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.

public C
getDeclaringClassForField(F field)

Gets the class that declares the given field.

public C
getDeclaringClassForMethod(M method)

Gets the class that declares the given method.

public F[]

Returns:

can be empty but never null.
getEnumConstants
(C
must derive from Enum.
clazz
)

Gets the enumeration constants from an enum class.

public Location
public String
getFieldName(F field)

Gets the name of the field.

public T
getFieldType(F f)

Gets the type of the field.

public Location
public String
getMethodName(M m)

Gets the name of the method, such as "toString" or "equals".

public T[]
getMethodParameters(M method)

Returns the list of parameters to the method.

public String

Returns:

i.e. "", "java.lang" but not null.
getPackageName
(C clazz)

Gets the package name of the given class.

public T
getPrimitive(Class<?>
must be Class objects like Integer#TYPE.
primitiveType
)

Returns the representation for the given primitive type.

public T
getReturnType(M m)

Gets the return type of a method.

public C

Returns:

null if the parameter represents Object.
getSuperClass
(C clazz)

Gets the base class of the specified class.

public T
getTypeArgument(T t, int i)

Gets the i-th type argument from a parameterized type.

public String

Returns:

a human-readable name that the type represents.
getTypeName
(T rawType)

Gets the display name of the type object

public T
getVoidType()

Gets the representation of the primitive "void" type.

public boolean
hasDefaultConstructor(C clazz)

Returns true if the given class has a no-arg default constructor.

public boolean
isAbstract(C clazz)

Returns true if this is an abstract class.

public boolean
isArray(T t)

Checks if the type is an array type.

public boolean
isArrayButNotByteArray(T t)

Checks if the type is an array type but not byte[].

public boolean
isBridgeMethod(M method)

Returns true if this method is a bridge method as defined in JLS.

public boolean
isEnum(C clazz)

Returns true if this is an enum class.

public boolean
isFinal(C clazz)

Returns true if this is a final class.

public boolean
isFinalMethod(M method)

Returns true if the method is final.

public boolean
isInnerClass(C clazz)

Returns true if the given class is an inner class.

public boolean
isInterface(C clazz)

Returns true if 'clazz' is an interface.

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

public boolean
isParameterizedType(T t)

Returns true if t is a parameterized type.

public boolean
isPrimitive(T t)

Checks if the given type is a primitive type.

public boolean
isPublicField(F field)

Returns true if the field is public.

public boolean
isPublicMethod(M method)

Returns true if the method is public.

public boolean

Returns:

true if types are the same
isSameType
(T
type
t1
,
T
type
t2
)

Checks if types are the same

public boolean
isStaticField(F field)

Returns true if the field is static.

public boolean
isStaticMethod(M method)

Returns true if the method is static.

public boolean
isSubClassOf(T sub, T sup)

Checks if sub is a sub-type of sup.

public boolean
isTransient(F f)

Returns true if the field is transient.

public C

Returns:

null if not found.
loadObjectFactory
(C
The class that refers to the specified class.
referencePoint
,
String packageName)

Finds ObjectFactory for the given referencePoint.

public T
ref(Class<?>
can be a primitive, array, class, or anything. (therefore the return type has to be T, not C)
c
)

Gets the representation of the given Java type in T.

public T
use(C c)

Gets the T for the given C.

Method Detail

asDeclback to summary
public 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.

asDeclback to summary
public 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.

erasureback to summary
public <P> T erasure(T contentInMemoryType)

Computes the erasure

getBaseClassback to summary
public 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:T

The type that derives from baseType

baseType:C

The class whose parameterization we are interested in.

Returns:T

The use of baseType in type. or null if the type is not assignable to the base type.

getClassLocationback to summary
public Location getClassLocation(C clazz)

Returns a location of the specified class.

getClassNameback to summary
public String getClassName(C clazz)

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

getClassShortNameback to summary
public 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".

getComponentTypeback to summary
public T getComponentType(T t)

Gets the component type of the array.

Parameters
t:T

must be an array.

getDeclaredFieldback to summary
public 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:F

null if not found

getDeclaredFieldsback to summary
public Collection<? extends F> getDeclaredFields(C clazz)

Gets all the declared fields of the given class.

getDeclaredMethodsback to summary
public 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:Collection<? extends M>

can be empty but always non-null.

getDeclaringClassForFieldback to summary
public C getDeclaringClassForField(F field)

Gets the class that declares the given field.

getDeclaringClassForMethodback to summary
public C getDeclaringClassForMethod(M method)

Gets the class that declares the given method.

getEnumConstantsback to summary
public F[] getEnumConstants(C clazz)

Gets the enumeration constants from an enum class.

Parameters
clazz:C

must derive from Enum.

Returns:F[]

can be empty but never null.

getFieldLocationback to summary
public Location getFieldLocation(F field)
getFieldNameback to summary
public String getFieldName(F field)

Gets the name of the field.

getFieldTypeback to summary
public T getFieldType(F f)

Gets the type of the field.

getMethodLocationback to summary
public Location getMethodLocation(M getter)
getMethodNameback to summary
public String getMethodName(M m)

Gets the name of the method, such as "toString" or "equals".

getMethodParametersback to summary
public T[] getMethodParameters(M method)

Returns the list of parameters to the method.

getPackageNameback to summary
public String getPackageName(C clazz)

Gets the package name of the given class.

Returns:String

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

getPrimitiveback to summary
public T getPrimitive(Class<?> primitiveType)

Returns the representation for the given primitive type.

Parameters
primitiveType:Class<?>

must be Class objects like Integer#TYPE.

getReturnTypeback to summary
public T getReturnType(M m)

Gets the return type of a method.

getSuperClassback to summary
public C getSuperClass(C clazz)

Gets the base class of the specified class.

Returns:C

null if the parameter represents Object.

getTypeArgumentback to summary
public T getTypeArgument(T t, int i)

Gets the i-th type argument from a parameterized type. For example, getTypeArgument([Map<Integer,String>],0)=Integer

Exceptions
IllegalArgumentException:
If t is not a parameterized type
IndexOutOfBoundsException:
If i is out of range.
See Also
isParameterizedType(Object)
getTypeNameback to summary
public String getTypeName(T rawType)

Gets the display name of the type object

Returns:String

a human-readable name that the type represents.

getVoidTypeback to summary
public T getVoidType()

Gets the representation of the primitive "void" type.

hasDefaultConstructorback to summary
public boolean hasDefaultConstructor(C clazz)

Returns true if the given class has a no-arg default constructor. The constructor does not need to be public.

isAbstractback to summary
public boolean isAbstract(C clazz)

Returns true if this is an abstract class.

isArrayback to summary
public boolean isArray(T t)

Checks if the type is an array type.

isArrayButNotByteArrayback to summary
public boolean isArrayButNotByteArray(T t)

Checks if the type is an array type but not byte[].

isBridgeMethodback to summary
public boolean isBridgeMethod(M method)

Returns true if this method is a bridge method as defined in JLS.

isEnumback to summary
public boolean isEnum(C clazz)

Returns true if this is an enum class.

isFinalback to summary
public boolean isFinal(C clazz)

Returns true if this is a final class.

isFinalMethodback to summary
public boolean isFinalMethod(M method)

Returns true if the method is final.

isInnerClassback to summary
public 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.)

isInterfaceback to summary
public boolean isInterface(C clazz)

Returns true if 'clazz' is an interface.

isOverridingback to summary
public 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.

isParameterizedTypeback to summary
public boolean isParameterizedType(T t)

Returns true if t is a parameterized type.

isPrimitiveback to summary
public boolean isPrimitive(T t)

Checks if the given type is a primitive type.

isPublicFieldback to summary
public boolean isPublicField(F field)

Returns true if the field is public.

isPublicMethodback to summary
public boolean isPublicMethod(M method)

Returns true if the method is public.

isSameTypeback to summary
public boolean isSameType(T t1, T t2)

Checks if types are the same

Parameters
t1:T

type

t2:T

type

Returns:boolean

true if types are the same

isStaticFieldback to summary
public boolean isStaticField(F field)

Returns true if the field is static.

isStaticMethodback to summary
public boolean isStaticMethod(M method)

Returns true if the method is static.

isSubClassOfback to summary
public boolean isSubClassOf(T sub, T sup)

Checks if sub is a sub-type of sup.

Todo

should this method take T or C?

isTransientback to summary
public boolean isTransient(F f)

Returns true if the field is transient.

loadObjectFactoryback to summary
public C loadObjectFactory(C referencePoint, String packageName)

Finds ObjectFactory for the given referencePoint.

Parameters
referencePoint:C

The class that refers to the specified class.

Returns:C

null if not found.

refback to summary
public T ref(Class<?> c)

Gets the representation of the given Java type in T.

Parameters
c:Class<?>

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

useback to summary
public T use(C c)

Gets the T for the given C.