public final class TypeToStringUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
toStringConstructor(java.lang.reflect.Constructor constructor,
java.util.Map<java.lang.String,java.lang.reflect.Type> generics)
class B extends A<Long> {}
class A<T> {
A(T arg);
}
Constructor method = A.class.getConstructor(Object.class);
Map<String, Type> generics = (context of B).method().visibleGenericsMap();
TypeToStringUtils.toStringConstructor(constructor, generics) == "A(Long)"
. |
static java.lang.String |
toStringMethod(java.lang.reflect.Method method,
java.util.Map<java.lang.String,java.lang.reflect.Type> generics)
class B extends A<Long> {}
class A<T> {
List<T> get(T one);
}
Method method = A.class.getMethod("get", Object.class);
Map<String, Type> generics = (context of B).method().visibleGenericsMap();
TypeToStringUtils.toStringMethod(method, generics) == "List<Long> get(Long)"
. |
static java.lang.String |
toStringType(java.lang.reflect.Type type,
java.util.Map<java.lang.String,java.lang.reflect.Type> generics)
Prints type as string.
|
static java.lang.String |
toStringWithGenerics(java.lang.Class<?> type,
java.util.Map<java.lang.String,java.lang.reflect.Type> generics)
Formats class as
Class<generics>. |
static java.lang.String |
toStringWithNamedGenerics(java.lang.Class<?> type)
Print class with generic variables.
|
public static java.lang.String toStringType(java.lang.reflect.Type type,
java.util.Map<java.lang.String,java.lang.reflect.Type> generics)
toStringType(ParameterizedType(List, String), [:]) == "List<String>",
toStringType(WildcardType(String), [:]) == "? extends String" .
If ParameterizedType is inner class and contains information about outer generics, it will be printed
as Outer<Generics>.Inner<Generics> in order to indicate all available information.
In other cases outer class is not indicated.
type - type to convert to stringgenerics - type class generics typeUnknownGenericException - when found generic not declared on type (e.g. method generic)to print not known generic names,
to print Object instead of not known genericpublic static java.lang.String toStringWithNamedGenerics(java.lang.Class<?> type)
List<T>.type - class to printpublic static java.lang.String toStringWithGenerics(java.lang.Class<?> type,
java.util.Map<java.lang.String,java.lang.reflect.Type> generics)
Class<generics>. Only actual class generics are rendered.
Intended to be used for error reporting.type - class class to print with genericsgenerics - known generics map class generics mapto print not known generic names,
to print Object instead of not known genericpublic static java.lang.String toStringMethod(java.lang.reflect.Method method,
java.util.Map<java.lang.String,java.lang.reflect.Type> generics)
class B extends A<Long> {}
class A<T> {
List<T> get(T one);
}
Method method = A.class.getMethod("get", Object.class);
Map<String, Type> generics = (context of B).method().visibleGenericsMap();
TypeToStringUtils.toStringMethod(method, generics) == "List<Long> get(Long)"
.method - methodgenerics - required generics (type generics and possible method generics)to print not known generic names,
to print Object instead of not known genericpublic static java.lang.String toStringConstructor(java.lang.reflect.Constructor constructor,
java.util.Map<java.lang.String,java.lang.reflect.Type> generics)
class B extends A<Long> {}
class A<T> {
A(T arg);
}
Constructor method = A.class.getConstructor(Object.class);
Map<String, Type> generics = (context of B).method().visibleGenericsMap();
TypeToStringUtils.toStringConstructor(constructor, generics) == "A(Long)"
.constructor - constructorgenerics - required generics (type generics and possible constructor generics)to print not known generic names,
to print Object instead of not known generic