|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.spicefactory.lib.reflect.TypeContext
public class TypeContext
A TypeContext instance reflects on a given supertype from the perspective of a subtype.
This is useful if you have parameterized types and want to easily resolve their TypeVariables
from the perspective of a subtype. Example: If you have a type MyClass<E> with a method
public void doSomethingWith (E element) and then create a subtype
MySubclass extends MyClass<String> without overriding the method and want to
reflect on this method, you will still get the TypeVariable E and not String as the genericParameter.
TypeContext instances offer convenience methods for resolving these TypeVariables.
Each TypeContext instance is defined with a (probably parameterized) base type (in the example
above MyClass) and a target type (in the example above MySubclass). The target type serves as
the "perspective" from which all TypeVariables of the base type will be resolved.
| Method Summary | |
|---|---|
Object |
convert(Object value)
Converts (if necessary) the given object to an instance of the target type of this TypeContext. |
Class<?> |
getBaseType()
Returns the base type for this TypeContext. |
Type |
getGenericTargetType()
Returns the generic target type for this TypeContext. |
Class<?> |
getRawTargetType()
Returns the raw target type for this TypeContext. |
boolean |
isAssignableType(Object value)
Checks if the given object is an instance of the target type of this TypeContext instance. |
boolean |
isConvertibleType(Object value)
Checks if the given object can be converted (if necessary) to an instance of the target type of this TypeContext. |
boolean |
isEqualType(Object value)
Checks if the class of the given object equals the raw target type of this TypeContext. |
Type |
resolve(Type type)
Resolves all TypeVariables contained in the given Type from the perspective of the target type of this TypeVariable. |
Type |
resolveTypeVariable(int typeVariableIndex)
Resolves the TypeVariable at the given index of the base type declaration of this TypeContext from the perspective of the target type. |
Type |
resolveTypeVariable(String typeVariableName)
Resolves the specified TypeVariable of the base type of this TypeContext from the perspective of the target type. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public Class<?> getBaseType()
public Type getGenericTargetType()
public Class<?> getRawTargetType()
public Type resolveTypeVariable(String typeVariableName)
List<E>
and the target type is MyList extends ArrayList<Integer> then
resolveTypeVariable("E") will return Integer.
typeVariableName - the name of the TypeVariable of the parameterized base type
public Type resolveTypeVariable(int typeVariableIndex)
Map<K,V>
and the target type is MyMap implements Map<String, File> then
resolveTypeVariable(1) will return File.
typeVariableIndex - the index of the TypeVariable of the parameterized base type
public Type resolve(Type type)
MyClass<E>
and the target type is MySubclass extends MyClass<String>
and the Type passed to this method is List<E> (presumably obtained through reflecting
on a method of MyClass like public void setElements (List<E> elements)
then this method would return List<String> as the resolved type.
type - a Type instance obtained through reflection on the base type of this TypeContext
public boolean isEqualType(Object value)
value - the instance to be checked
public boolean isAssignableType(Object value)
value - the instance to be checked
public boolean isConvertibleType(Object value)
value - the instance to be checked
public Object convert(Object value)
value - instance that should become an instance of the target type of this TypeContext
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||