Silk DI 0.6


se.jbee.inject
Class Type<T>

Object
  extended by se.jbee.inject.Type<T>
All Implemented Interfaces:
Parameter<T>, PreciserThan<Type<?>>, Typed<T>

public final class Type<T>
extends Object
implements PreciserThan<Type<?>>, Parameter<T>

A generic version of Class like Type but without a complex hierarchy. Instead all cases are represented as a general model. The key difference is that this model just describes concrete types. So there is no representation for a TypeVariable. There are some generic cases that are not supported right now because they haven't been needed.

Author:
Jan Bernitt (jan@jbee.se)

Field Summary
static Type<Object> OBJECT
           
static Type<Void> VOID
           
static Type<? extends Object> WILDCARD
           
 
Method Summary
 boolean allArgumentsAreUpperBounds()
           
 int arrayDimensions()
           
 Type<? extends T> asExactType()
           
 Type<? extends T> asUpperBound()
           
<S> Type<? extends S>
castTo(Type<S> supertype)
           
 Type<?> elementType()
           
static
<T> Type<T>
elementType(Class<T[]> arrayType)
           
 boolean equals(Object obj)
           
 boolean equalTo(Type<?> other)
           
static Type<?> fieldType(Field field)
           
 Type<T[]> getArrayType()
           
 Type<?>[] getParameters()
           
 Class<T> getRawType()
           
 Type<T> getType()
           
 int hashCode()
           
 boolean hasTypeParameter()
           
 boolean isAbstract()
           
 boolean isAssignableTo(Type<?> other)
           
 boolean isFinal()
           
 boolean isInterface()
           
 boolean isParameterized()
           
 boolean isRawType()
           
 boolean isUpperBound()
           
 boolean morePreciseThan(Type<?> other)
           
 Type<?> parameter(int index)
           
static Type<?>[] parameterTypes(Constructor<?> constructor)
           
static Type<?>[] parameterTypes(Method method)
           
 Type<T> parametized(Class<?>... arguments)
           
 Type<T> parametized(Type<?>... parameters)
           
 Type<T> parametizedAsUpperBounds()
          Example - typeOf Map<String,String> => Map<?
static
<T> Class<T>
primitiveAsWrapper(Class<T> primitive)
           
static
<T> Type<T>
raw(Class<T> type)
           
static Type<?> returnType(Method method)
           
 String simpleName()
           
static
<S> Type<? extends S>
supertype(Class<S> supertype, Type<? extends S> type)
           
 Type<? super T>[] supertypes()
           
 String toString()
           
(package private)  void toString(StringBuilder b, boolean canonicalName)
           
<E> Type<E>
typed(Type<E> type)
           
 Type<? extends T> upperBound(boolean upperBound)
           
static Type<?>[] wildcards(TypeVariable<?>... variables)
           
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

OBJECT

public static final Type<Object> OBJECT

VOID

public static final Type<Void> VOID

WILDCARD

public static final Type<? extends Object> WILDCARD
Method Detail

fieldType

public static Type<?> fieldType(Field field)

returnType

public static Type<?> returnType(Method method)

parameterTypes

public static Type<?>[] parameterTypes(Constructor<?> constructor)

parameterTypes

public static Type<?>[] parameterTypes(Method method)

wildcards

public static Type<?>[] wildcards(TypeVariable<?>... variables)

elementType

public static <T> Type<T> elementType(Class<T[]> arrayType)

raw

public static <T> Type<T> raw(Class<T> type)

getType

public Type<T> getType()
Specified by:
getType in interface Typed<T>
Returns:
The Type of this object.

typed

public <E> Type<E> typed(Type<E> type)
Specified by:
typed in interface Typed<T>
Returns:
This object with the given Type.

castTo

public <S> Type<? extends S> castTo(Type<S> supertype)

asUpperBound

public Type<? extends T> asUpperBound()

upperBound

public Type<? extends T> upperBound(boolean upperBound)

asExactType

public Type<? extends T> asExactType()

getArrayType

public Type<T[]> getArrayType()

equalTo

public boolean equalTo(Type<?> other)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

elementType

public Type<?> elementType()
Returns:
in case of an array type the Class.getComponentType() with the same type parameters as this type or otherwise this type.

getRawType

public Class<T> getRawType()

getParameters

public Type<?>[] getParameters()
Returns:
The actual type parameters (arguments).

parameter

public Type<?> parameter(int index)

isAssignableTo

public boolean isAssignableTo(Type<?> other)
Specified by:
isAssignableTo in interface Parameter<T>

isInterface

public boolean isInterface()

isAbstract

public boolean isAbstract()

isFinal

public boolean isFinal()

isUpperBound

public boolean isUpperBound()
Returns:
true if this type describes the upper bound of the required types (a wildcard generic).

isParameterized

public boolean isParameterized()
Returns:
true if the type hasTypeParameter() and parameters are given.
See Also:
To check if the {@link Class} defines type parameter.

hasTypeParameter

public boolean hasTypeParameter()
Returns:
true when the Class defines type parameters (generics).
See Also:
To check if actual type parameters are given.

arrayDimensions

public int arrayDimensions()

morePreciseThan

public boolean morePreciseThan(Type<?> other)
Specified by:
morePreciseThan in interface PreciserThan<Type<?>>
Returns:
Whether or not this object or more precise than the given one. Equal objects are not more precise! Also objects that have no common context or relationship are never more precise. An example would be that two Types with no common super-type do not define one of them that is more precise.

parametizedAsUpperBounds

public Type<T> parametizedAsUpperBounds()
Example - typeOf
 Map<String,String> => Map<? extends String, ? extends String>
 

Returns:
A Type having all its type arguments asUpperBound()s. Use this to model <?> wildcard generic.

isRawType

public boolean isRawType()
Returns:
true, in case this is a raw type - that is a generic type without any generic type information available.

allArgumentsAreUpperBounds

public boolean allArgumentsAreUpperBounds()
Returns:
True when all type parameters are upper bounds.

parametized

public Type<T> parametized(Class<?>... arguments)

parametized

public Type<T> parametized(Type<?>... parameters)

toString

public String toString()
Overrides:
toString in class Object

toString

void toString(StringBuilder b,
              boolean canonicalName)

simpleName

public String simpleName()

supertype

public static <S> Type<? extends S> supertype(Class<S> supertype,
                                              Type<? extends S> type)

supertypes

public Type<? super T>[] supertypes()
Returns:
a list of all super-classes and super-interfaces of this type starting with the direct super-class followed by the direct super-interfaces continuing by going up the type hierarchy.

primitiveAsWrapper

public static <T> Class<T> primitiveAsWrapper(Class<T> primitive)

Silk DI 0.6