public final class ReflectionNavigator extends java.lang.Object implements Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>
Navigator implementation for java.lang.reflect.REFLECTION| Modifier and Type | Method and Description |
|---|---|
java.lang.Class |
asDecl(java.lang.Class c)
Gets the
C representation for the given class. |
java.lang.Class |
asDecl(java.lang.reflect.Type t)
If the given type is an use of class declaration,
returns the type casted as
C. |
java.lang.reflect.Type |
createParameterizedType(java.lang.Class rawType,
java.lang.reflect.Type... arguments)
Returns the
Type object that represents clazz<T1,T2,T3>. |
<T> java.lang.Class<T> |
erasure(java.lang.reflect.Type t)
Returns the runtime representation of the given type.
|
java.lang.Class |
findClass(java.lang.String className,
java.lang.Class referencePoint)
Finds the class/interface/enum/annotation of the given name.
|
java.lang.reflect.Type |
getBaseClass(java.lang.reflect.Type t,
java.lang.Class sup)
Gets the parameterization of the given base type.
|
Location |
getClassLocation(java.lang.Class clazz)
Returns a location of the specified class.
|
java.lang.String |
getClassName(java.lang.Class clazz)
Gets the fully-qualified name of the class.
|
java.lang.String |
getClassShortName(java.lang.Class clazz)
Gets the short name of the class ("Object" for
Object.)
For nested classes, this method should just return the inner name. |
java.lang.reflect.Type |
getComponentType(java.lang.reflect.Type t)
Gets the component type of the array.
|
java.lang.reflect.Field |
getDeclaredField(java.lang.Class clazz,
java.lang.String fieldName)
Gets the named field declared on the given class.
|
java.util.Collection<? extends java.lang.reflect.Field> |
getDeclaredFields(java.lang.Class clazz)
Gets all the declared fields of the given class.
|
java.util.Collection<? extends java.lang.reflect.Method> |
getDeclaredMethods(java.lang.Class 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.)
|
java.lang.Class |
getDeclaringClassForField(java.lang.reflect.Field field)
Gets the class that declares the given field.
|
java.lang.Class |
getDeclaringClassForMethod(java.lang.reflect.Method method)
Gets the class that declares the given method.
|
java.lang.reflect.Field[] |
getEnumConstants(java.lang.Class clazz)
Gets the enumeration constants from an enum class.
|
Location |
getFieldLocation(java.lang.reflect.Field field) |
java.lang.String |
getFieldName(java.lang.reflect.Field field)
Gets the name of the field.
|
java.lang.reflect.Type |
getFieldType(java.lang.reflect.Field field)
Gets the type of the field.
|
Location |
getMethodLocation(java.lang.reflect.Method method) |
java.lang.String |
getMethodName(java.lang.reflect.Method method)
Gets the name of the method, such as "toString" or "equals".
|
java.lang.reflect.Type[] |
getMethodParameters(java.lang.reflect.Method method)
Returns the list of parameters to the method.
|
java.lang.String |
getPackageName(java.lang.Class clazz)
Gets the package name of the given class.
|
java.lang.reflect.Type |
getPrimitive(java.lang.Class primitiveType)
Returns the representation for the given primitive type.
|
java.lang.reflect.Type |
getReturnType(java.lang.reflect.Method method)
Gets the return type of a method.
|
java.lang.Class |
getSuperClass(java.lang.Class clazz)
Gets the base class of the specified class.
|
java.lang.reflect.Type |
getTypeArgument(java.lang.reflect.Type type,
int i)
Gets the i-th type argument from a parameterized type.
|
java.lang.String |
getTypeName(java.lang.reflect.Type type)
Gets the display name of the type object
|
java.lang.reflect.Type |
getVoidType()
Gets the representation of the primitive "void" type.
|
boolean |
hasDefaultConstructor(java.lang.Class c)
Returns true if the given class has a no-arg default constructor.
|
boolean |
isAbstract(java.lang.Class clazz)
Returns true if this is an abstract class.
|
boolean |
isArray(java.lang.reflect.Type t)
Checks if the type is an array type.
|
boolean |
isArrayButNotByteArray(java.lang.reflect.Type t)
Checks if the type is an array type but not byte[].
|
boolean |
isBridgeMethod(java.lang.reflect.Method method)
Returns true if this method is a bridge method as defined in JLS.
|
boolean |
isEnum(java.lang.Class c)
Returns true if this is an enum class.
|
boolean |
isFinal(java.lang.Class clazz)
Returns true if this is a final class.
|
boolean |
isFinalMethod(java.lang.reflect.Method method)
Returns true if the method is final.
|
boolean |
isInnerClass(java.lang.Class clazz)
Returns true if the given class is an inner class.
|
boolean |
isInterface(java.lang.Class clazz)
Returns true if 'clazz' is an interface.
|
boolean |
isOverriding(java.lang.reflect.Method method,
java.lang.Class base)
Returns true if the given method is overriding another one
defined in the base class 'base' or its ancestors.
|
boolean |
isParameterizedType(java.lang.reflect.Type type)
Returns true if t is a parameterized type.
|
boolean |
isPrimitive(java.lang.reflect.Type type)
Checks if the given type is a primitive type.
|
boolean |
isPublicField(java.lang.reflect.Field field)
Returns true if the field is public.
|
boolean |
isPublicMethod(java.lang.reflect.Method method)
Returns true if the method is public.
|
boolean |
isSameType(java.lang.reflect.Type t1,
java.lang.reflect.Type t2)
Checks if types are the same
|
boolean |
isStaticField(java.lang.reflect.Field field)
Returns true if the field is static.
|
boolean |
isStaticMethod(java.lang.reflect.Method method)
Returns true if the method is static.
|
boolean |
isSubClassOf(java.lang.reflect.Type sub,
java.lang.reflect.Type sup)
Checks if
sub is a sub-type of sup. |
boolean |
isTransient(java.lang.reflect.Field f)
Returns true if the field is transient.
|
java.lang.Class |
ref(java.lang.Class c)
Gets the representation of the given Java type in
T. |
java.lang.Class |
use(java.lang.Class c)
Gets the T for the given C.
|
public java.lang.Class getSuperClass(java.lang.Class clazz)
NavigatorgetSuperClass in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>Object.public java.lang.reflect.Type getBaseClass(java.lang.reflect.Type t,
java.lang.Class sup)
NavigatorFor example, given the following
This method works like this:interface Foo extends List > {} interface Bar extends Foo
{}
getBaseClass( Bar, List ) = List getBaseClass( Bar, Foo ) = Foo
getBaseClass( Foo extends Number>, Collection ) = Collection > getBaseClass( ArrayList extends BigInteger>, List ) = List extends BigInteger>
getBaseClass in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>t - The type that derives from baseTypesup - The class whose parameterization we are interested in.baseType in type.
or null if the type is not assignable to the base type.public java.lang.String getClassName(java.lang.Class clazz)
NavigatorObject)getClassName in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.String getTypeName(java.lang.reflect.Type type)
NavigatorgetTypeName in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.String getClassShortName(java.lang.Class clazz)
NavigatorObject.)
For nested classes, this method should just return the inner name.
(for example "Inner" for "com.acme.Outer$Inner".getClassShortName in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.util.Collection<? extends java.lang.reflect.Field> getDeclaredFields(java.lang.Class clazz)
NavigatorgetDeclaredFields in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.reflect.Field getDeclaredField(java.lang.Class clazz,
java.lang.String fieldName)
NavigatorgetDeclaredField in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.util.Collection<? extends java.lang.reflect.Method> getDeclaredMethods(java.lang.Class clazz)
NavigatorNote that this method does not list methods declared on base classes.
getDeclaredMethods in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.Class getDeclaringClassForField(java.lang.reflect.Field field)
NavigatorgetDeclaringClassForField in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.Class getDeclaringClassForMethod(java.lang.reflect.Method method)
NavigatorgetDeclaringClassForMethod in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.reflect.Type getFieldType(java.lang.reflect.Field field)
NavigatorgetFieldType in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.String getFieldName(java.lang.reflect.Field field)
NavigatorgetFieldName in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.String getMethodName(java.lang.reflect.Method method)
NavigatorgetMethodName in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.reflect.Type getReturnType(java.lang.reflect.Method method)
NavigatorgetReturnType in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.reflect.Type[] getMethodParameters(java.lang.reflect.Method method)
NavigatorgetMethodParameters in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isStaticMethod(java.lang.reflect.Method method)
NavigatorisStaticMethod in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isFinalMethod(java.lang.reflect.Method method)
NavigatorisFinalMethod in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isSubClassOf(java.lang.reflect.Type sub,
java.lang.reflect.Type sup)
Navigatorsub is a sub-type of sup.
TODO: should this method take T or C?isSubClassOf in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.Class ref(java.lang.Class c)
NavigatorT.public java.lang.Class use(java.lang.Class c)
Navigatorpublic java.lang.Class asDecl(java.lang.reflect.Type t)
NavigatorC.
Otherwise null.
TODO: define the exact semantics.
public java.lang.Class asDecl(java.lang.Class c)
NavigatorC representation for the given class.
The behavior is undefined if the class object represents
primitives, arrays, and other types that are not class declaration.public <T> java.lang.Class<T> erasure(java.lang.reflect.Type t)
Because of the difference in the way Annotation Processing 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.
public boolean isAbstract(java.lang.Class clazz)
NavigatorisAbstract in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isFinal(java.lang.Class clazz)
Navigatorpublic java.lang.reflect.Type createParameterizedType(java.lang.Class rawType,
java.lang.reflect.Type... arguments)
Type object that represents clazz<T1,T2,T3>.public boolean isArray(java.lang.reflect.Type t)
Navigatorpublic boolean isArrayButNotByteArray(java.lang.reflect.Type t)
NavigatorisArrayButNotByteArray in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.reflect.Type getComponentType(java.lang.reflect.Type t)
NavigatorgetComponentType in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>t - must be an array.public java.lang.reflect.Type getTypeArgument(java.lang.reflect.Type type,
int i)
NavigatorgetTypeArgument([Map<Integer,String>],0)=IntegergetTypeArgument in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>Navigator.isParameterizedType(Object)public boolean isParameterizedType(java.lang.reflect.Type type)
NavigatorisParameterizedType in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isPrimitive(java.lang.reflect.Type type)
NavigatorisPrimitive in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.reflect.Type getPrimitive(java.lang.Class primitiveType)
NavigatorgetPrimitive in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>primitiveType - must be Class objects like Integer.TYPE.public Location getClassLocation(java.lang.Class clazz)
NavigatorgetClassLocation in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public Location getFieldLocation(java.lang.reflect.Field field)
getFieldLocation in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public Location getMethodLocation(java.lang.reflect.Method method)
getMethodLocation in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean hasDefaultConstructor(java.lang.Class c)
NavigatorhasDefaultConstructor in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isStaticField(java.lang.reflect.Field field)
NavigatorisStaticField in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isPublicMethod(java.lang.reflect.Method method)
NavigatorisPublicMethod in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isPublicField(java.lang.reflect.Field field)
NavigatorisPublicField in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isEnum(java.lang.Class c)
Navigatorpublic java.lang.reflect.Field[] getEnumConstants(java.lang.Class clazz)
NavigatorgetEnumConstants in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>clazz - must derive from Enum.public java.lang.reflect.Type getVoidType()
NavigatorgetVoidType in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.String getPackageName(java.lang.Class clazz)
NavigatorgetPackageName in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public java.lang.Class findClass(java.lang.String className,
java.lang.Class referencePoint)
Navigatorpublic boolean isBridgeMethod(java.lang.reflect.Method method)
NavigatorisBridgeMethod in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isOverriding(java.lang.reflect.Method method,
java.lang.Class base)
NavigatorisOverriding in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isInterface(java.lang.Class clazz)
NavigatorisInterface in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isTransient(java.lang.reflect.Field f)
NavigatorisTransient in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isInnerClass(java.lang.Class clazz)
NavigatorisInnerClass in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>public boolean isSameType(java.lang.reflect.Type t1,
java.lang.reflect.Type t2)
NavigatorisSameType in interface Navigator<java.lang.reflect.Type,java.lang.Class,java.lang.reflect.Field,java.lang.reflect.Method>t1 - typet2 - type