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


Java Type.getTypeName方法代碼示例

本文整理匯總了Java中java.lang.reflect.Type.getTypeName方法的典型用法代碼示例。如果您正苦於以下問題:Java Type.getTypeName方法的具體用法?Java Type.getTypeName怎麽用?Java Type.getTypeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Type的用法示例。


在下文中一共展示了Type.getTypeName方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import java.lang.reflect.Type; //導入方法依賴的package包/類
private static JavaType create(final ImplementClass implementClass, final Type type) {
	if (type instanceof Class<?>) {
		return new ClassJavaType(implementClass, (Class<?>) type);
	} else if (type instanceof TypeVariable<?>) {
		TypeVariable<?> variable = (TypeVariable<?>) type;
		return createByParamName(implementClass, variable);
	} else if (type instanceof GenericArrayType) {
		GenericArrayType arrayType = (GenericArrayType) type;
		return new ArrayJavaType(implementClass, arrayType);
	} else if (type instanceof ParameterizedType) {
		ParameterizedType parameterizedType = (ParameterizedType) type;
		return new ParameterizedJavaType(implementClass, parameterizedType);
	} else if (type instanceof WildcardType) {
		WildcardType wildcardType = (WildcardType) type;
		return new WildcardJavaType(implementClass, wildcardType);
	}

	throw new IllegalArgumentException(type.getTypeName());

}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:21,代碼來源:JavaType.java

示例2: getReturnTypeParameters

import java.lang.reflect.Type; //導入方法依賴的package包/類
/**
 * @param method {@link Method} object
 * @return the actual type parameters used in the source code. Return <strong>empty</strong> list if no parametrized type
 */
public static List<String> getReturnTypeParameters(Method method) {
    List<String> typeParameters = new ArrayList<>();

    Type type = method.getGenericReturnType();
    String typeName = type.getTypeName(); // ex: java.util.List<com.timeyang.search.entity.Person>, java.lang.Long
    Pattern p = Pattern.compile("<((\\S+\\.?),?\\s*)>");
    Matcher m = p.matcher(typeName);
    while (m.find()) {
        typeParameters.add(m.group(2));
    }

    return typeParameters;
}
 
開發者ID:chaokunyang,項目名稱:jkes,代碼行數:18,代碼來源:ReflectionUtils.java

示例3: toString

import java.lang.reflect.Type; //導入方法依賴的package包/類
@Override
public String toString() {
    Type type = getParameterizedType();
    String typename = type.getTypeName();
    if (isVarArgs()) {
        typename = typename.replaceFirst("\\[\\]$", "...");
    }

    final StringBuilder sb = new StringBuilder(Modifier.toString(getModifiers()));
    if (sb.length() != 0) {
        sb.append(' ');
    }
    return sb.append(typename).append(' ').append(getName()).toString();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:ResolvedJavaMethod.java

示例4: matchType

import java.lang.reflect.Type; //導入方法依賴的package包/類
protected Result matchType(Object obj, Property prop, String path) throws ValidationException {
    String expectedType = prop.getType();
    if ("array".equals(expectedType)) {
        expectedType = JSONArray.class.getName();
    }
    else if ("ref".equals(expectedType) || "object".equals(expectedType)) {
        expectedType = JSONObject.class.getName();
    }
    else {
        PrimitiveType type = PrimitiveType.fromName(prop.getType());
        if (type != null) {
            expectedType = type.getKeyClass().getName();
            if (BigDecimal.class.getName().equals(expectedType))
                expectedType = Double.class.getName();
        }
        else {
            Type refType = ReflectionUtils.typeFromString(prop.getType());
            if (refType != null)
                expectedType = refType.getTypeName();
        }
    }
        
    String foundType = obj.getClass().getName();
    boolean match = foundType.equals(expectedType);
    if (!match) {
        // forgive rounded numeric types
        if (BigDecimal.class.getName().equals(expectedType)) {
            if (foundType.equals(Double.class.getName()) || foundType.equals(Integer.class.getName()))
                match = true;
        }
        else if (Double.class.getName().equals(expectedType)) {
            if (foundType.equals(Integer.class.getName()))
                match = true;
        }
        else if (Integer.class.getName().equals(expectedType)) {
            if (foundType.equals(Long.class.getName()) && "int64".equals(prop.getFormat()))
                match = true;
        }
    }
    
    if (match)
        return new Result();
    else
        return new Result(BAD_REQUEST, path + ": expected " + expectedType + " but found " + foundType);
}
 
開發者ID:limberest,項目名稱:limberest,代碼行數:46,代碼來源:BodyParameterValidator.java

示例5: of

import java.lang.reflect.Type; //導入方法依賴的package包/類
public static MessageType of(Type t) {
    return new MessageType(t.getTypeName());
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:4,代碼來源:MessageType.java

示例6: getTypeName

import java.lang.reflect.Type; //導入方法依賴的package包/類
public static String getTypeName(Method method) {
    Type type = method.getGenericReturnType();

    String typeName = type.getTypeName(); // ex: java.util.List<com.timeyang.search.entity.Person>, java.lang.Long

    return typeName;
}
 
開發者ID:chaokunyang,項目名稱:jkes,代碼行數:8,代碼來源:ReflectionUtils.java

示例7: getInnermostType

import java.lang.reflect.Type; //導入方法依賴的package包/類
/**
 * If return type is genetic type, then return last parameterized type, else return the formal return type name of the method represented by this {@code Method}  object.
 * @param method {@link Method} method
 * @return If return type is genetic type, then return last parameterized type, else return the formal return type name of the method represented by this {@code Method}  object.
 */
public static String getInnermostType(Method method) {
    Type type = method.getGenericReturnType();

    String typeName = type.getTypeName(); // ex: java.util.List<com.timeyang.search.entity.Person>, java.lang.Long

    String[] types = typeName.split(",\\s*|<|<|>+");

    return types[types.length - 1];
}
 
開發者ID:chaokunyang,項目名稱:jkes,代碼行數:15,代碼來源:ReflectionUtils.java


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