com.sun.xml.bind.v2.model.nav

Class ReflectionNavigator

public final class ReflectionNavigator extends Object implements Navigator<Type,Class,Field,Method>

Navigator implementation for {@code java.lang.reflect}.
Constructor Summary
ReflectionNavigator()
Singleton.
Method Summary
ClassasDecl(Type t)
ClassasDecl(Class c)
TypecreateParameterizedType(Class rawType, Type... arguments)
Returns the Type object that represents {@code clazz<T1,T2,T3>}.
<T> Class<T>erasure(Type t)
Returns the runtime representation of the given type.
ClassfindClass(String className, Class referencePoint)
TypegetBaseClass(Type t, Class sup)
LocationgetClassLocation(Class clazz)
StringgetClassName(Class clazz)
StringgetClassShortName(Class clazz)
TypegetComponentType(Type t)
FieldgetDeclaredField(Class clazz, String fieldName)
Collection<? extends Field>getDeclaredFields(Class clazz)
Collection<? extends Method>getDeclaredMethods(Class clazz)
ClassgetDeclaringClassForField(Field field)
ClassgetDeclaringClassForMethod(Method method)
Field[]getEnumConstants(Class clazz)
LocationgetFieldLocation(Field field)
StringgetFieldName(Field field)
TypegetFieldType(Field field)
LocationgetMethodLocation(Method method)
StringgetMethodName(Method method)
Type[]getMethodParameters(Method method)
StringgetPackageName(Class clazz)
TypegetPrimitive(Class primitiveType)
TypegetReturnType(Method method)
ClassgetSuperClass(Class clazz)
TypegetTypeArgument(Type type, int i)
StringgetTypeName(Type type)
TypegetVoidType()
booleanhasDefaultConstructor(Class c)
booleanisAbstract(Class clazz)
booleanisArray(Type t)
booleanisArrayButNotByteArray(Type t)
booleanisBridgeMethod(Method method)
booleanisEnum(Class c)
booleanisFinal(Class clazz)
booleanisFinalMethod(Method method)
booleanisInnerClass(Class clazz)
booleanisInterface(Class clazz)
booleanisOverriding(Method method, Class base)
booleanisParameterizedType(Type type)
booleanisPrimitive(Type type)
booleanisPublicField(Field field)
booleanisPublicMethod(Method method)
booleanisStaticField(Field field)
booleanisStaticMethod(Method method)
booleanisSubClassOf(Type sub, Type sup)
booleanisTransient(Field f)
Classref(Class c)
Classuse(Class c)

Constructor Detail

ReflectionNavigator

ReflectionNavigator()
Singleton. Use REFLECTION

Method Detail

asDecl

public Class asDecl(Type t)

asDecl

public Class asDecl(Class c)

createParameterizedType

public Type createParameterizedType(Class rawType, Type... arguments)
Returns the Type object that represents {@code clazz<T1,T2,T3>}.

erasure

public <T> Class<T> erasure(Type t)
Returns the runtime representation of the given type. This corresponds to the notion of the erasure in JSR-14.

Because of the difference in the way APT and the Java reflection treats primitive type and array type, we can't define this method on Navigator.

It made me realize how difficult it is to define the common navigation layer for two different underlying reflection library. The other way is to throw away the entire parameterization and go to the wrapper approach.

findClass

public Class findClass(String className, Class referencePoint)

getBaseClass

public Type getBaseClass(Type t, Class sup)

getClassLocation

public Location getClassLocation(Class clazz)

getClassName

public String getClassName(Class clazz)

getClassShortName

public String getClassShortName(Class clazz)

getComponentType

public Type getComponentType(Type t)

getDeclaredField

public Field getDeclaredField(Class clazz, String fieldName)

getDeclaredFields

public Collection<? extends Field> getDeclaredFields(Class clazz)

getDeclaredMethods

public Collection<? extends Method> getDeclaredMethods(Class clazz)

getDeclaringClassForField

public Class getDeclaringClassForField(Field field)

getDeclaringClassForMethod

public Class getDeclaringClassForMethod(Method method)

getEnumConstants

public Field[] getEnumConstants(Class clazz)

getFieldLocation

public Location getFieldLocation(Field field)

getFieldName

public String getFieldName(Field field)

getFieldType

public Type getFieldType(Field field)

getMethodLocation

public Location getMethodLocation(Method method)

getMethodName

public String getMethodName(Method method)

getMethodParameters

public Type[] getMethodParameters(Method method)

getPackageName

public String getPackageName(Class clazz)

getPrimitive

public Type getPrimitive(Class primitiveType)

getReturnType

public Type getReturnType(Method method)

getSuperClass

public Class getSuperClass(Class clazz)

getTypeArgument

public Type getTypeArgument(Type type, int i)

getTypeName

public String getTypeName(Type type)

getVoidType

public Type getVoidType()

hasDefaultConstructor

public boolean hasDefaultConstructor(Class c)

isAbstract

public boolean isAbstract(Class clazz)

isArray

public boolean isArray(Type t)

isArrayButNotByteArray

public boolean isArrayButNotByteArray(Type t)

isBridgeMethod

public boolean isBridgeMethod(Method method)

isEnum

public boolean isEnum(Class c)

isFinal

public boolean isFinal(Class clazz)

isFinalMethod

public boolean isFinalMethod(Method method)

isInnerClass

public boolean isInnerClass(Class clazz)

isInterface

public boolean isInterface(Class clazz)

isOverriding

public boolean isOverriding(Method method, Class base)

isParameterizedType

public boolean isParameterizedType(Type type)

isPrimitive

public boolean isPrimitive(Type type)

isPublicField

public boolean isPublicField(Field field)

isPublicMethod

public boolean isPublicMethod(Method method)

isStaticField

public boolean isStaticField(Field field)

isStaticMethod

public boolean isStaticMethod(Method method)

isSubClassOf

public boolean isSubClassOf(Type sub, Type sup)

isTransient

public boolean isTransient(Field f)

ref

public Class ref(Class c)

use

public Class use(Class c)