當前位置: 首頁>>代碼示例>>Java>>正文


Java Type.toString方法代碼示例

本文整理匯總了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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:ReferenceCodec.java

示例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();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:23,代碼來源:DefaultServiceRegistry.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:ExceptionDiagnosisTest.java

示例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);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:14,代碼來源:OpenTypeConverter.java

示例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;
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:14,代碼來源:Porter.java

示例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;
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:13,代碼來源:ReflectUtils.java

示例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());
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:15,代碼來源:JpaMetaUtils.java

示例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;
}
 
開發者ID:mattkol,項目名稱:SugarOnRest,代碼行數:20,代碼來源:ModuleInfo.java

示例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();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:8,代碼來源:FauxveridesTest.java

示例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();
}
 
開發者ID:Yoio,項目名稱:X4J,代碼行數:8,代碼來源:Util.java

示例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;
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:33,代碼來源:CollectionTypeBuilder.java

示例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();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:7,代碼來源:MethodDescription.java

示例13: typeToString

import java.lang.reflect.Type; //導入方法依賴的package包/類
static String typeToString(Type type) {
  return type instanceof Class ? ((Class<?>) type).getName() : type.toString();
}
 
開發者ID:hzsweers,項目名稱:inspector,代碼行數:4,代碼來源:Types.java

示例14: typeToString

import java.lang.reflect.Type; //導入方法依賴的package包/類
public static String typeToString(Type type) {
  return type instanceof Class ? ((Class) type).getName() : type.toString();
}
 
開發者ID:maetrive,項目名稱:businessworks,代碼行數:4,代碼來源:MoreTypes.java

示例15: typeToString

import java.lang.reflect.Type; //導入方法依賴的package包/類
public static String typeToString(Type type) {
    return type instanceof Class ? ((Class) type).getName() : type.toString();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:4,代碼來源:C$Gson$Types.java


注:本文中的java.lang.reflect.Type.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。