Class TypeVariableView<D extends GenericDeclaration>
- java.lang.Object
-
- org.perfectable.introspection.type.TypeView
-
- org.perfectable.introspection.type.TypeVariableView<D>
-
- Type Parameters:
D
- Type declaring this variable
public final class TypeVariableView<D extends GenericDeclaration> extends TypeView
TypeView
that handlesTypeVariable
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.perfectable.introspection.type.TypeView
TypeView.PartialVisitor<T>, TypeView.Visitor<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected T
type
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ArrayTypeView
asArray()
Deprecated.the type system already knows this is a type variable, and this call will failClassView<?>
asClass()
Deprecated.the type system already knows this is a type variable, and this call will failParameterizedTypeView
asParameterized()
Deprecated.the type system already knows this is a type variable, and this call will failTypeVariableView<?>
asVariable()
Deprecated.the type system already knows this is a variable, and this call does not change the typeWildcardTypeView
asWildcard()
Deprecated.the type system already knows this is a type variable, and this call will failboolean
equals(Object obj)
Class<?>
erasure()
Finds exact class that would be erasure of wrapped type.int
hashCode()
boolean
isSubTypeOf(TypeView other)
Tests if type wrapped in this view is subtype of the provided one.static <D extends GenericDeclaration>
TypeVariableView<D>of(TypeVariable<D> variable)
Creates view over provided type.String
toString()
T
unwrap()
Extracts native type from this view.Collection<TypeView>
upperBounds()
Extracts upper bounds for this variable.<T> T
visit(TypeView.Visitor<T> visitor)
Visitor patter method dispatching method.-
Methods inherited from class org.perfectable.introspection.type.TypeView
isInstance, isProperSubtypeOf, isProperSubtypeOf, isProperSupertypeOf, isProperSupertypeOf, isSubTypeOf, isSuperTypeOf, isSuperTypeOf, of, of, of, of, of, ofParameterOf, ofTypeOf, ofTypeParameterOf, resolve, resolve
-
-
-
-
Field Detail
-
type
protected final T extends Type type
-
-
Method Detail
-
of
public static <D extends GenericDeclaration> TypeVariableView<D> of(TypeVariable<D> variable)
Creates view over provided type.- Type Parameters:
D
- element type that is declaring this variable- Parameters:
variable
- construct to wrap- Returns:
- view wrapping specified type
-
erasure
public Class<?> erasure()
Description copied from class:TypeView
Finds exact class that would be erasure of wrapped type.This method is implemented according to JSL section 4.6 with following extensions:
- Erasure of wildcard type is erasure of its leftmost upper bound,
or
Object
if there isn't one
These extensions are needed, because these types are cannot be used in declaration, but can be obtained by reflections.
- Erasure of wildcard type is erasure of its leftmost upper bound,
or
-
upperBounds
public Collection<TypeView> upperBounds()
Extracts upper bounds for this variable.Realizations of this variable must extend/implement all specified types.
In actual code, there can be only one upper bound, it is impossible to declare multiple bounds. But synthetic types can have multiple as reflection system supports it.
If variable has no upper bound, this method will return singleton collection with
Object
class. This is following contract inTypeVariable.getBounds()
, which will return singleton array withObject
class.- Returns:
- upper bounds of this variable, wrapped in
TypeView
-
asParameterized
@Deprecated public ParameterizedTypeView asParameterized() throws IllegalStateException
Deprecated.the type system already knows this is a type variable, and this call will failAlways throwsIllegalStateException
, because it is statically provable that this instance cannot be converted to parameterized type.- Specified by:
asParameterized
in classTypeView
- Returns:
- never
- Throws:
IllegalStateException
- always
-
asClass
@Deprecated public ClassView<?> asClass() throws IllegalStateException
Deprecated.the type system already knows this is a type variable, and this call will failAlways throwsIllegalStateException
, because it is statically provable that this instance cannot be converted to class view.- Specified by:
asClass
in classTypeView
- Returns:
- never
- Throws:
IllegalStateException
- always
-
asVariable
@Deprecated public TypeVariableView<?> asVariable()
Deprecated.the type system already knows this is a variable, and this call does not change the typeTry to cast wrapped type toTypeVariable
.This method is useful if you know that underlying type is
Class
, then this is just a casting.For any other type, this throws
IllegalStateException
, because nothing else can be converted to type variable.- Specified by:
asVariable
in classTypeView
- Returns:
- this, as this is already variable view
-
asWildcard
@Deprecated public WildcardTypeView asWildcard() throws IllegalStateException
Deprecated.the type system already knows this is a type variable, and this call will failAlways throwsIllegalStateException
, because it is statically provable that this instance cannot be converted to wildcard type.- Specified by:
asWildcard
in classTypeView
- Returns:
- never
- Throws:
IllegalStateException
- always
-
asArray
@Deprecated public ArrayTypeView asArray() throws IllegalStateException
Deprecated.the type system already knows this is a type variable, and this call will failAlways throwsIllegalStateException
, because it is statically provable that this instance cannot be converted to array type.- Specified by:
asArray
in classTypeView
- Returns:
- never
- Throws:
IllegalStateException
- always
-
isSubTypeOf
public boolean isSubTypeOf(TypeView other)
Description copied from class:TypeView
Tests if type wrapped in this view is subtype of the provided one.This method tries to adhere to the spirit of subtyping: it answers the question: Having reference of type T, can value of type S be always assigned to it?
Subtyping is precisely defined for types that can be declared in source, but there are more types that can be constructed or extracted via reflections. This method follows JLS section 4.10 for every aspect it declares, but also defines sensible rule for subtyping wildcards: wildcard is a supertype of its lower bounds, i.e.
? super CharStream
is supertype of CharStream and- Specified by:
isSubTypeOf
in classTypeView
- Parameters:
other
- type to test subtype relation against- Returns:
- true if this type is subtype of provided argument
-
visit
public <T> T visit(TypeView.Visitor<T> visitor)
Description copied from class:TypeView
Visitor patter method dispatching method.This method calls specific method on provided
visitor
, depending on actual implementation of this type.It will return whatever the method returns.
-
unwrap
public final T unwrap()
Description copied from class:TypeView
Extracts native type from this view.This is inverse operation from
TypeView.of(Type)
-
-