public final class Types
extends java.lang.Object
WildcardTypes
, ParameterizedTypes
, and ArrayTypes
..Modifier and Type | Class and Description |
---|---|
static class |
Types.TypeParser
A parser for
Type s, and various related types. |
Modifier and Type | Method and Description |
---|---|
static <T> T |
assign(java.lang.Object object,
java.lang.Class<T> type)
If a given object is assignable to a given raw type, it will be converted to
that type.
|
static boolean |
equals(java.lang.reflect.Type a,
java.lang.reflect.Type b)
Test whether two types are equal to one another.
|
static java.lang.reflect.Type |
fromString(java.lang.String typeString)
Create a Type instance from a parsed String.
|
static java.util.stream.Stream<java.lang.reflect.Type> |
getAllMentionedBy(java.lang.reflect.Type type,
java.util.function.Predicate<java.lang.reflect.Type> condition)
Search through all types mentioned by a given type, whether by identity, or
through bound relationships, type parameterizations, type intersections, or
generic array components, and collect all types meeting a given condition.
|
static int |
getArrayDimensions(java.lang.reflect.Type type)
Determine the number of array dimensions exist on the given type.
|
static java.lang.reflect.Type |
getComponentType(java.lang.reflect.Type type)
Find the component type of the given type, if the given
Type instance
is an array Class or an instance of GenericArrayType . |
static java.lang.Class<?> |
getErasedType(java.lang.reflect.Type type)
Get the erasure of the given type.
|
static java.lang.reflect.Type |
getInnerComponentType(java.lang.reflect.Type type)
Find the innermost component type of the given type, if the given
Type instance is an array Class or an instance of
GenericArrayType with any number of dimensions. |
static java.util.stream.Stream<java.lang.reflect.Type> |
getLowerBounds(java.lang.reflect.Type type)
Find the lower bounds of a given type.
|
static Types.TypeParser |
getParser()
Get the default type parser.
|
static Types.TypeParser |
getParser(Imports imports)
Get a type parser with knowledge of the given imports.
|
static java.util.stream.Stream<java.lang.reflect.Type> |
getUpperBounds(java.lang.reflect.Type type)
Find the upper bounding classes and parameterized types of a given type.
|
static Visibility |
getVisibility(java.lang.Class<?> type)
Determine the visibility of the type
|
static boolean |
isAbstract(java.lang.Class<?> rawType)
Determine whether a given class is abstract.
|
static boolean |
isAssignable(java.lang.reflect.Type from,
java.lang.reflect.Type to)
Determine if a given type,
to , is assignable from another given type,
from . |
static boolean |
isCastable(java.lang.reflect.Type from,
java.lang.reflect.Type to)
Determine if a given type,
to , is legally castable from another given
type, from . |
static boolean |
isContainedBy(java.lang.reflect.Type from,
java.lang.reflect.Type to)
Determine if the given type,
from , contains the given type,
to . |
static boolean |
isFinal(java.lang.Class<?> rawType)
Determine whether a given class is final.
|
static boolean |
isGeneric(java.lang.Class<?> type)
Determine whether a
Class represents a generic class or an array with
a generic class as a component type. |
static boolean |
isInterface(java.lang.Class<?> rawType)
Determine whether a given class is an interface.
|
static boolean |
isLooseInvocationContextCompatible(java.lang.reflect.Type from,
java.lang.reflect.Type to)
Determine whether a given type,
from , is compatible with a given
type, to , within a loose invocation context. |
static boolean |
isRaw(java.lang.reflect.Type type)
Determine whether a type is raw, i.e.
|
static boolean |
isStatic(java.lang.Class<?> rawType)
Determine whether a given class is static.
|
static boolean |
isStrictInvocationContextCompatible(java.lang.reflect.Type from,
java.lang.reflect.Type to)
Determine whether a given type,
from , is compatible with a given
type, to , within a strict invocation context. |
static boolean |
isSubtype(java.lang.reflect.Type subtype,
java.lang.reflect.Type supertype)
Determine if a given type,
supertype , is a subtype of another given
type, subtype . |
static java.lang.String |
toString(java.lang.reflect.Type type)
Give a canonical String representation of a given type, which is intended to
be more easily human-readable than implementations of
Object.toString() for certain implementations of Type . |
static java.lang.String |
toString(java.lang.reflect.Type type,
Imports imports)
Give a canonical String representation of a given type, which is intended to
be more easily human-readable than implementations of
Object.toString() for certain implementations of Type . |
static java.lang.String |
toString(java.lang.reflect.Type type,
Imports imports,
Isomorphism isomorphism)
Give a canonical String representation of a given type, which is intended to
be more easily human-readable than implementations of
Object.toString() for certain implementations of Type . |
public static boolean isGeneric(java.lang.Class<?> type)
Class
represents a generic class or an array with
a generic class as a component type.type
- the type we wish to classifypublic static boolean isRaw(java.lang.reflect.Type type)
type
- the type we wish to classifypublic static java.lang.Class<?> getErasedType(java.lang.reflect.Type type)
type
- The type of which we wish to determine the raw type.public static java.util.stream.Stream<java.lang.reflect.Type> getUpperBounds(java.lang.reflect.Type type)
type
- The type whose bounds we wish to discover.public static java.util.stream.Stream<java.lang.reflect.Type> getLowerBounds(java.lang.reflect.Type type)
type
- The type whose bounds we wish to discover.public static boolean isAbstract(java.lang.Class<?> rawType)
rawType
- The type we wish to classify.public static boolean isFinal(java.lang.Class<?> rawType)
rawType
- The type we wish to classify.public static boolean isInterface(java.lang.Class<?> rawType)
rawType
- The type we wish to classify.public static Visibility getVisibility(java.lang.Class<?> type)
type
- the type whose visibility we wish to determineVisibility
object describing the typepublic static boolean isStatic(java.lang.Class<?> rawType)
rawType
- The type we wish to classify.public static java.lang.reflect.Type getComponentType(java.lang.reflect.Type type)
Type
instance
is an array Class
or an instance of GenericArrayType
.type
- The type of which we wish to determine the component type.public static java.lang.reflect.Type getInnerComponentType(java.lang.reflect.Type type)
Type
instance is an array Class
or an instance of
GenericArrayType
with any number of dimensions.type
- The type of which we wish to determine the component type.public static int getArrayDimensions(java.lang.reflect.Type type)
type
- A type which may or may not be an array.public static boolean isCastable(java.lang.reflect.Type from, java.lang.reflect.Type to)
to
, is legally castable from another given
type, from
.from
- The type from which we wish to determine castability.to
- The type to which we wish to determine castability.public static <T> T assign(java.lang.Object object, java.lang.Class<T> type)
T
- the type to which we wish to assignobject
- the type from which we wish to assigntype
- the type to which we wish to assignpublic static boolean equals(java.lang.reflect.Type a, java.lang.reflect.Type b)
a
- the first typeb
- the second typepublic static boolean isContainedBy(java.lang.reflect.Type from, java.lang.reflect.Type to)
from
, contains the given type,
to
. In other words, if either of the given types are wildcards,
determine if every possible instantiation of to
is also a valid
instantiation of from
. Or if neither type is a wildcard, determine
whether both types are assignable to each other as per
isSubtype(Type, Type)
.from
- the type within which we are determining containmentto
- the type of which we are determining containmentfrom
contains to
, false otherwisepublic static boolean isSubtype(java.lang.reflect.Type subtype, java.lang.reflect.Type supertype)
supertype
, is a subtype of another given
type, subtype
. Or in other words, if supertype
is a supertype
of subtype
. Types are considered assignable if they involve unchecked
generic casts.subtype
- the type from which we wish to determine assignabilitysupertype
- the type to which we wish to determine assignabilitypublic static boolean isAssignable(java.lang.reflect.Type from, java.lang.reflect.Type to)
to
, is assignable from another given type,
from
. Or in other words, if to
is a supertype of
from
. Types are considered assignable if they involve unchecked
generic casts.from
- the type from which we wish to determine assignabilityto
- the type to which we wish to determine assignabilitypublic static boolean isStrictInvocationContextCompatible(java.lang.reflect.Type from, java.lang.reflect.Type to)
Determine whether a given type, from
, is compatible with a given
type, to
, within a strict invocation context.
Types are considered so compatible if assignment is possible through application of the following conversions:
from
- The type from which to determine compatibility.to
- The type to which to determine compatibility.from
is compatible with the type to
,
false otherwise.public static boolean isLooseInvocationContextCompatible(java.lang.reflect.Type from, java.lang.reflect.Type to)
Determine whether a given type, from
, is compatible with a given
type, to
, within a loose invocation context.
Types are considered so compatible if assignment is possible through application of the following conversions:
from
- The type from which to determine compatibility.to
- The type to which to determine compatibility.from
is compatible with the type to
,
false otherwise.public static java.util.stream.Stream<java.lang.reflect.Type> getAllMentionedBy(java.lang.reflect.Type type, java.util.function.Predicate<java.lang.reflect.Type> condition)
type
- The type to search for mentions which match the given condition.condition
- The condition to classify matching types.public static java.lang.String toString(java.lang.reflect.Type type)
Object.toString()
for certain implementations of Type
.type
- The type for which we wish to determine a string representation.public static java.lang.String toString(java.lang.reflect.Type type, Imports imports)
Object.toString()
for certain implementations of Type
.
Provided class and package imports allow the names of some classes to be
output without full package qualification.imports
- classes and packages for which full package qualification may be
omitted from outputtype
- the type for which we wish to determine a string representationpublic static java.lang.String toString(java.lang.reflect.Type type, Imports imports, Isomorphism isomorphism)
Object.toString()
for certain implementations of Type
.
Provided class and package imports allow the names of some classes to be
output without full package qualification.imports
- classes and packages for which full package qualification may be
omitted from outputtype
- the type for which we wish to determine a string representationisomorphism
- a type to string isomorphic mapping to deal with recursionpublic static java.lang.reflect.Type fromString(java.lang.String typeString)
java.util.List<java.lang.Number & java.lang.Comparable<? extends java.lang.Number & java.lang.Comparable<? extends java.lang.Number & java.lang.Comparable
<...>>>>
Where "..." would be substituted, recursively, with the parameterization of
the an outer instance of the same raw class. TODO add clarity, and a proper
description of how ambiguity is resolved here.typeString
- The String to parse.public static Types.TypeParser getParser()
public static Types.TypeParser getParser(Imports imports)
imports
- A list of imports the type parser should be aware of