net.sf.mmm.util.reflect.impl
Class GenericTypeImpl<T>

java.lang.Object
  extended by net.sf.mmm.util.reflect.base.AbstractGenericType<T>
      extended by net.sf.mmm.util.reflect.impl.GenericTypeImpl<T>
Type Parameters:
T - is the templated type of the upper bound.
All Implemented Interfaces:
Type, GenericType<T>

public class GenericTypeImpl<T>
extends AbstractGenericType<T>

This is the implementation of the GenericType interface.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Nested Class Summary
protected static class GenericTypeImpl.ClassBounds
          This inner class represents the bounds of a GenericType.
 
Field Summary
private  Class<? extends T> assignmentClass
           
private  GenericType<?> componentType
           
private  GenericType<?> definingType
           
private  GenericType<?> keyType
           
private  Class<T> retrievalClass
           
private  Type type
           
private  Type[] typeArgs
           
private  GenericType<?>[] typesArguments
           
 
Fields inherited from interface net.sf.mmm.util.reflect.api.GenericType
NO_TYPES
 
Constructor Summary
GenericTypeImpl(Type type)
          The constructor.
GenericTypeImpl(Type valueType, GenericType<?> definingType)
          The constructor.
 
Method Summary
protected  GenericType<?> create(Type genericType)
          This method creates the GenericType that encapsulates the given type.
protected  AbstractGenericType<T> create(Type genericType, GenericType<?> genericDefiningType)
          This method creates a new instance of this class.
 Class<?> getArrayClass(Class<?> componentClass)
          This method creates the Class reflecting an array of the given componentType.
 Class<? extends T> getAssignmentClass()
          This method gets the Class to be used for assignment (as parameter) of a value of this GenericType.
protected  GenericTypeImpl.ClassBounds getClassBounds(Type currentType)
          This method gets the most specific Class available by the type-safe analyzation of the given generic type.
 GenericType<?> getComponentType()
          This method gets the component-type of this GenericType if it represents an array, Collection or Map.
 GenericType<?> getDefiningType()
          This method gets the defining type.
 GenericType<?> getKeyType()
          This method gets the key-type of this GenericType if it represents a Map.
 Class<T> getRetrievalClass()
          This method gets the Class to be used for retrieval (the return-type) of a value of this GenericType.
 Type getType()
          This method gets the Type represented by this GenericType.
 GenericType<?> getTypeArgument(int index)
          This method gets the type-argument at the given index.
 int getTypeArgumentCount()
          This method gets the number of type-arguments .
 
Methods inherited from class net.sf.mmm.util.reflect.base.AbstractGenericType
equals, getDeclarationIndex, getGenericDeclarations, hashCode, isAssignableFrom, resolveTypeVariable, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

definingType

private final GenericType<?> definingType
See Also:
getDefiningType()

type

private final Type type
See Also:
getType()

assignmentClass

private final Class<? extends T> assignmentClass
See Also:
getAssignmentClass()

retrievalClass

private final Class<T> retrievalClass
See Also:
getRetrievalClass()

componentType

private final GenericType<?> componentType
See Also:
getComponentType()

keyType

private final GenericType<?> keyType
See Also:
getKeyType()

typeArgs

private final Type[] typeArgs
See Also:
getTypeArgument(int)

typesArguments

private final GenericType<?>[] typesArguments
See Also:
getTypeArgument(int)
Constructor Detail

GenericTypeImpl

public GenericTypeImpl(Type type)
The constructor.

Parameters:
type - is the type.

GenericTypeImpl

public GenericTypeImpl(Type valueType,
                       GenericType<?> definingType)
The constructor.

Parameters:
valueType - is the value-type.
definingType - is the defining-type.
Method Detail

create

protected GenericType<?> create(Type genericType)
This method creates the GenericType that encapsulates the given type.

Specified by:
create in class AbstractGenericType<T>
Parameters:
genericType - is the Type to get as GenericType.
Returns:
the according GenericType.
See Also:
GenericTypeFactory.createGenericType(Type)

create

protected AbstractGenericType<T> create(Type genericType,
                                        GenericType<?> genericDefiningType)
This method creates a new instance of this class. It may be overridden to create the appropriate sub-type.

Parameters:
genericType - is the value-type.
genericDefiningType - is the defining-type.
Returns:
a new GenericType instance.

getClassBounds

protected GenericTypeImpl.ClassBounds getClassBounds(Type currentType)
This method gets the most specific Class available by the type-safe analyzation of the given generic type. Unlike getClassBounds(Type) this method resolves TypeVariables with the proper type they have been bound with.
Examples:
type owningType getClass(type, owningType) comment
E List<Foo> Foo E is a TypeVariable representing the generic return-type of the method List.get(int)

Parameters:
currentType - is the type to convert.
Returns:
the closest class representing the given type.

getArrayClass

public Class<?> getArrayClass(Class<?> componentClass)
This method creates the Class reflecting an array of the given componentType.

Parameters:
componentClass - is the component type.
Returns:
the according array-class.

getComponentType

public GenericType<?> getComponentType()
This method gets the component-type of this GenericType if it represents an array, Collection or Map.
Here are some examples:
type GenericType.getComponentType()
List<Map<String, Long>> Map<String, Long>
List Object
Foo[] Foo
Foo<Bar>[] Foo<Bar>
Foo<Bar> null
Map<String, Long> Long

Returns:
the component-type of this GenericType or null if this GenericType does NOT represent an array, Collection or Map.

getKeyType

public GenericType<?> getKeyType()
This method gets the key-type of this GenericType if it represents a Map.
Here are some examples:
type GenericType.getComponentType()
List<Map<String, Long>> null
Map Object
Foo[] null
Foo<K,V> null
Map<String, Long> String

Returns:
the key-type of this GenericType or null if this GenericType does NOT represent a Map .

getDefiningType

public GenericType<?> getDefiningType()
This method gets the defining type.

Specified by:
getDefiningType in class AbstractGenericType<T>
Returns:
the defining type or null if NOT available.

getAssignmentClass

public Class<? extends T> getAssignmentClass()
This method gets the Class to be used for assignment (as parameter) of a value of this GenericType.
It will only differ from the retrieval-class if this GenericType is a WildcardType.
Unlike the lower-bound, the assignment-class is never null. If there is no lower-bound, the assignment-class is the same as the retrieval-class. Therefore the assignment-class is always equal or more specific to the retrieval-class.
Here are some examples:
Type GenericType.getAssignmentClass()
<? super Integer> Integer
<? extends CharSequence> CharSequence
String String

Returns:
the Class that is the lower bound.

getRetrievalClass

public Class<T> getRetrievalClass()
This method gets the Class to be used for retrieval (the return-type) of a value of this GenericType.
It will only differ from the assignment-class if this GenericType is a WildcardType.
The retrieval-class is the upper-bound, however for usability and simplicity only one bound is supported.
Here are some examples:
Type GenericType.getAssignmentClass()
<? super Integer> Object
<? extends CharSequence> CharSequence
String String

Returns:
the Class that is the upper bound.

getType

public Type getType()
This method gets the Type represented by this GenericType.

Returns:
the value-type.
See Also:
Class.getGenericSuperclass(), Class.getGenericInterfaces(), Method.getGenericReturnType(), Method.getGenericParameterTypes(), Field.getGenericType(), Constructor.getGenericParameterTypes()

getTypeArgumentCount

public int getTypeArgumentCount()
This method gets the number of type-arguments .

Returns:
the type-argument count.

getTypeArgument

public GenericType<?> getTypeArgument(int index)
This method gets the type-argument at the given index.
E.g. for the GenericType representing Map<String, List<Integer>> this method would return String for an index of 0 and List<Integer> for an index of 1.

Parameters:
index - is the position of the requested type-argument. It has to be in the range from 0 to GenericType.getTypeArgumentCount() - 1.
Returns:
the type-argument at the given index.
See Also:
GenericType.getTypeArgumentCount(), ParameterizedType.getActualTypeArguments()


Copyright © 2001-2010 mmm-Team. All Rights Reserved.