本文整理匯總了Java中java.lang.reflect.Type.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java Type.toString方法的具體用法?Java Type.toString怎麽用?Java Type.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Type
的用法示例。
在下文中一共展示了Type.toString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialze
import java.lang.reflect.Type; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
ParameterizedType paramType = (ParameterizedType) type;
Type itemType = paramType.getActualTypeArguments()[0];
Object itemObject = parser.parseObject(itemType);
Type rawType = paramType.getRawType();
if (rawType == AtomicReference.class) {
return (T) new AtomicReference(itemObject);
}
if (rawType == WeakReference.class) {
return (T) new WeakReference(itemObject);
}
if (rawType == SoftReference.class) {
return (T) new SoftReference(itemObject);
}
throw new UnsupportedOperationException(rawType.toString());
}
示例2: format
import java.lang.reflect.Type; //導入方法依賴的package包/類
private static String format(Type type) {
if (type instanceof Class) {
Class<?> aClass = (Class) type;
return aClass.getSimpleName();
} else if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
StringBuilder builder = new StringBuilder();
builder.append(format(parameterizedType.getRawType()));
builder.append("<");
for (int i = 0; i < parameterizedType.getActualTypeArguments().length; i++) {
Type typeParam = parameterizedType.getActualTypeArguments()[i];
if (i > 0) {
builder.append(", ");
}
builder.append(format(typeParam));
}
builder.append(">");
return builder.toString();
}
return type.toString();
}
示例3: checkExceptionChain
import java.lang.reflect.Type; //導入方法依賴的package包/類
private static void checkExceptionChain(
String what, Throwable e, Type[] expectedTypes) {
System.out.println("Exceptions in chain for " + what + ":");
for (Throwable t = e; t != null; t = t.getCause())
System.out.println(".." + t);
String messageChain = messageChain(e);
// Now check that each of the classes is mentioned in those messages
for (Type type : expectedTypes) {
String name = (type instanceof Class) ?
((Class<?>) type).getName() : type.toString();
if (!messageChain.contains(name)) {
fail("Exception chain for " + what + " does not mention " +
name);
System.out.println("Full stack trace:");
e.printStackTrace(System.out);
}
}
System.out.println();
}
示例4: makeTabularConverter
import java.lang.reflect.Type; //導入方法依賴的package包/類
private static OpenTypeConverter makeTabularConverter(Type objType, boolean sortedMap,
Type keyType, Type valueType) throws OpenDataException {
final String objTypeName = objType.toString();
final OpenTypeConverter keyConverter = toConverter(keyType);
final OpenTypeConverter valueConverter = toConverter(valueType);
final OpenType keyOpenType = keyConverter.getOpenType();
final OpenType valueOpenType = valueConverter.getOpenType();
final CompositeType rowType = new CompositeType(objTypeName, objTypeName, keyValueArray,
keyValueArray, new OpenType[] {keyOpenType, valueOpenType});
final TabularType tabularType = new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TableConverter(objType, sortedMap, tabularType, keyConverter, valueConverter);
}
示例5: getClassName
import java.lang.reflect.Type; //導入方法依賴的package包/類
public static String getClassName(Type type)
{
if (type == null)
{
return null;
}
String className = type.toString();
if (className.startsWith(TYPE_NAME_PREFIX))
{
className = className.substring(TYPE_NAME_PREFIX.length());
}
return className;
}
示例6: getClassName
import java.lang.reflect.Type; //導入方法依賴的package包/類
public static String getClassName(Type type) {
if (type == null) {
return "";
}
String className = type.toString();
if (className.startsWith(TYPE_CLASS_NAME_PREFIX)) {
className = className.substring(TYPE_CLASS_NAME_PREFIX.length());
} else if (className.startsWith(TYPE_INTERFACE_NAME_PREFIX)) {
className = className.substring(TYPE_INTERFACE_NAME_PREFIX.length());
}
return className;
}
示例7: getElementType
import java.lang.reflect.Type; //導入方法依賴的package包/類
public static Class<?> getElementType(Type type) {
if (type instanceof Class) {
return (Class<?>) type;
} else if (type instanceof ParameterizedType) {
ParameterizedType paramType = (ParameterizedType) type;
if (paramType.getRawType() instanceof Class && Map.class.isAssignableFrom((Class<?>) paramType.getRawType())) {
return getElementType(paramType.getActualTypeArguments()[1]);
}
if (paramType.getRawType() instanceof Class && Collection.class.isAssignableFrom((Class<?>) paramType.getRawType())) {
return getElementType(paramType.getActualTypeArguments()[0]);
}
}
throw new IllegalArgumentException(type.toString());
}
示例8: getClassName
import java.lang.reflect.Type; //導入方法依賴的package包/類
/**
* Gets class name (module name) from Java class type.
*
* @param type The Java type.
* @return Class name.
*/
public static String getClassName(Type type) {
if (type == null) {
return StringUtils.EMPTY;
}
String typeToString = type.toString();
typeToString = typeToString.trim();
String[] splitArray = typeToString.split("\\.");
if (splitArray.length > 0) {
return splitArray[splitArray.length - 1];
}
return StringUtils.EMPTY;
}
示例9: apply
import java.lang.reflect.Type; //導入方法依賴的package包/類
@Override
public String apply(Type from) {
if (from instanceof Class) {
return ((Class<?>) from).getSimpleName();
}
return from.toString();
}
示例10: getTargetTypeName
import java.lang.reflect.Type; //導入方法依賴的package包/類
private static String getTargetTypeName(Type targetType) {
if (targetType instanceof Class) {
Class<?> c = (Class<?>) targetType;
return c.getCanonicalName();
}
return targetType.toString();
}
示例11: build
import java.lang.reflect.Type; //導入方法依賴的package包/類
@Override
public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
if (!(type instanceof ParameterizedType)) {
throw new IllegalArgumentException(MessageFormat.format("[Jaket] Unexpected type {0}.",
new Object[]{type}));
}
ParameterizedType parameterizedType = (ParameterizedType) type;
Type[] actualTypeArgs = parameterizedType.getActualTypeArguments();
if (actualTypeArgs == null || actualTypeArgs.length != 1) {
throw new IllegalArgumentException(MessageFormat.format(
"[Jaket] Collection type [{0}] with unexpected amount of arguments [{1}]." + actualTypeArgs,
new Object[] { type, actualTypeArgs }));
}
Type actualType = actualTypeArgs[0];
if (actualType instanceof ParameterizedType) {
// Nested collection or map.
Class<?> rawType = (Class<?>) ((ParameterizedType) actualType).getRawType();
JaketTypeBuilder.build(actualType, rawType, typeCache);
} else if (actualType instanceof Class<?>) {
Class<?> actualClass = (Class<?>) actualType;
if (actualClass.isArray() || actualClass.isEnum()) {
JaketTypeBuilder.build(null, actualClass, typeCache);
} else {
DefaultTypeBuilder.build(actualClass, typeCache);
}
}
TypeDefinition td = new TypeDefinition(type.toString());
return td;
}
示例12: typeName
import java.lang.reflect.Type; //導入方法依賴的package包/類
private String typeName(Type type) {
if (type == null) {
return null;
}
return type instanceof Class ? Cast.cast(Class.class, type).getName() : type.toString();
}
示例13: typeToString
import java.lang.reflect.Type; //導入方法依賴的package包/類
static String typeToString(Type type) {
return type instanceof Class ? ((Class<?>) type).getName() : type.toString();
}
示例14: typeToString
import java.lang.reflect.Type; //導入方法依賴的package包/類
public static String typeToString(Type type) {
return type instanceof Class ? ((Class) type).getName() : type.toString();
}
示例15: typeToString
import java.lang.reflect.Type; //導入方法依賴的package包/類
public static String typeToString(Type type) {
return type instanceof Class ? ((Class) type).getName() : type.toString();
}