当前位置: 首页>>代码示例>>Java>>正文


Java TypeUtils.isArrayType方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.reflect.TypeUtils.isArrayType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils.isArrayType方法的具体用法?Java TypeUtils.isArrayType怎么用?Java TypeUtils.isArrayType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.reflect.TypeUtils的用法示例。


在下文中一共展示了TypeUtils.isArrayType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCollectionType

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
/**
 * Return the type of the content of the given collection type.
 *
 * @param type The collection type.
 * @return Collection type.
 */
public static Class<?> getCollectionType(Type type) {
    if (TypeUtils.isAssignable(type, Collection.class)) {
        if (type instanceof ParameterizedType) {
            Type genericType = ((ParameterizedType) type).getActualTypeArguments()[0];

            if (genericType instanceof Class) {
                return (Class<?>) genericType;
            }
        } else {
            throw new IllegalArgumentException("Cannot infer index type for non-parameterized type: " + type);
        }
    } else if (TypeUtils.isArrayType(type)) {
        return (Class<?>) TypeUtils.getArrayComponentType(type);
    }
    throw new IllegalArgumentException("Unsupported type: " + type);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:23,代码来源:MetadataUtils.java

示例2: get

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
@Override
public <T> Codec<T> get(Type type, TypeCodecRegistry typeCodecRegistry) {
    // byte arrays are handled well by the mongo java driver
    if (TypeUtils.isArrayType(type)) {
        return new ArrayCodec(type, typeCodecRegistry);
    } else if (type instanceof TypeVariable) {
        throw new IllegalArgumentException("This registry (and probably no other one as well) can not handle generic type variables.");
    } else if (type instanceof WildcardType) {
        LOGGER.error("WildcardTypes are not yet supported. {}", type);
        throw new NotImplementedException("WildcardTypes are not yet supported. " + type);
    }
    // the default codecs provided by the mongo driver lack the decode method, hence this redefinition
    else if (Float.class.equals(type)) {
        return (Codec<T>) FLOAT_CODEC;
    } else if (Short.class.equals(type)) {
        return (Codec<T>) SHORT_CODEC;
    } else if (Byte.class.equals(type)) {
        return (Codec<T>) BYTE_CODEC;
    }
    else if (TypeUtils.isAssignable(type, SpecialFieldsMap.class)) {
        return new SpecialFieldsMapCodec(type, typeCodecRegistry);
    }

    // List ?
    Codec<T> codec = ListTypeCodec.getCodecIfApplicable(type, typeCodecRegistry);
    if (codec != null) {
        return codec;
    }
    // Set ?
    codec = SetTypeCodec.getCodecIfApplicable(type, typeCodecRegistry);
    if (codec != null) {
        return codec;
    }
    // Map ?
    codec = MapTypeCodec.getCodecIfApplicable(type, typeCodecRegistry);
    if (codec != null) {
        return codec;
    }
    return null;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:41,代码来源:PojoContext.java

示例3: getMethodSpec

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
public static MethodTracepointSpec getMethodSpec(Class<?> cls, String methodName)
        throws ClassNotFoundException {
    MethodTracepointSpec.Builder b = MethodTracepointSpec.newBuilder();
    b.setClassName(cls.getName());
    b.setMethodName(methodName);

    Method m = getMethod(cls, methodName);
    for (Class<?> paramClass : m.getParameterTypes()) {
        b.addParamClass(paramClass.getCanonicalName());
    }

    int paramCount = 0;
    for (Type paramType : m.getGenericParameterTypes()) {
        String paramName = String.format("$%d", ++paramCount);
        if (TypeUtils.isArrayType(paramType)) {
            Type arrayOfType = TypeUtils.getArrayComponentType(paramType);
            String arrayOf = TypeUtils.toString(arrayOfType);
            b.addAdviceArgBuilder().getMultiBuilder().setLiteral(paramName).setPostProcess("{}")
                    .setType(arrayOf);
        } else if (TypeUtils.isAssignable(paramType, Collection.class)) {
            ParameterizedType pt = (ParameterizedType) paramType;
            Type collectionOfType = pt.getActualTypeArguments()[0]; // doesn't work if multiple type params, but
                                                                    // good enough
            String collectionOf = TypeUtils.toString(collectionOfType);
            b.addAdviceArgBuilder().getMultiBuilder().setLiteral(paramName).setPostProcess("{}")
                    .setType(collectionOf);
        } else {
            b.addAdviceArgBuilder().setLiteral(paramName);
        }
    }

    return b.build();
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:34,代码来源:TracepointsTestUtils.java

示例4: create

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
/** Create a tracepoint for the entry of the named method of the class.
 * The name of the tracepoint will be the short class name and the method name,
 * eg java.lang.String.format will have short name String.format
 * Parameter types will be looked up, and if the method is overloaded, returns one of the methods.
 * If any of the method arguments are arrays or collections, they will be exported as multi-variables
 */
public static MethodTracepoint create(Class<?> cls, String methodName, String... namesForMethodParameters) {
    Where where = Where.ENTRY;
    String tracepointName = String.format("%s.%s", cls.getSimpleName(), methodName);
    
    // Find the method
    Method m = getMethod(cls, methodName, namesForMethodParameters.length);
    
    // Create the tracepoint
    MethodTracepoint tracepoint = new MethodTracepoint(tracepointName, where, m);
    
    // Export the arguments as variables
    int paramCount = 0;
    for (Type paramType : m.getGenericParameterTypes()) {
        String exportAs = namesForMethodParameters[paramCount];
        String literal = String.format("$%d", ++paramCount);
        if (TypeUtils.isArrayType(paramType)) {
            Type arrayOfType = TypeUtils.getArrayComponentType(paramType);
            String arrayOf = TypeUtils.toString(arrayOfType);
            tracepoint.addMultiExport(exportAs, literal, arrayOf);
        } else if (TypeUtils.isAssignable(paramType, Collection.class)) {
            ParameterizedType pt = (ParameterizedType) paramType;
            Type collectionOfType = pt.getActualTypeArguments()[0];
            String collectionOf = TypeUtils.toString(collectionOfType);
            tracepoint.addMultiExport(exportAs, literal, collectionOf);
        } else {
            tracepoint.addExport(exportAs, literal);
        }
    }
    
    return tracepoint;
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:38,代码来源:Tracepoints.java

示例5: getParameterString

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
private String getParameterString(Type[] parameterTypes,
        List<VariableReference> parameters, boolean isGenericMethod,
        boolean isOverloaded, int startPos) {
	String parameterString = "";

	for (int i = startPos; i < parameters.size(); i++) {
		if (i > startPos) {
			parameterString += ", ";
		}
		Type declaredParamType = parameterTypes[i];
		Type actualParamType = parameters.get(i).getType();
		String name = getVariableName(parameters.get(i));
		Class<?> rawParamClass = declaredParamType instanceof WildcardType ? Object.class : GenericTypeReflector.erase(declaredParamType);
		if (rawParamClass.isPrimitive() && name.equals("null")) {
			parameterString += getPrimitiveNullCast(rawParamClass);
		} else if (isGenericMethod && !(declaredParamType instanceof WildcardType )) {
			if (!declaredParamType.equals(actualParamType) || name.equals("null")) {
				parameterString += "(" + getTypeName(declaredParamType) + ") ";
				if (name.contains("(short"))
					name = name.replace("(short)", "");
				if (name.contains("(byte"))
					name = name.replace("(byte)", "");

			}
		} else if (name.equals("null")) {
			parameterString += "(" + getTypeName(declaredParamType) + ") ";
		} else if (!GenericClass.isAssignable(declaredParamType, actualParamType)) {

			if (TypeUtils.isArrayType(declaredParamType)
			        && TypeUtils.isArrayType(actualParamType)) {
				Class<?> componentClass = GenericTypeReflector.erase(declaredParamType).getComponentType();
				if (componentClass.equals(Object.class)) {
					GenericClass genericComponentClass = new GenericClass(
					        componentClass);
					if (genericComponentClass.hasWildcardOrTypeVariables()) {
						// If we are assigning a generic array, then we don't need to cast

					} else {
						// If we are assigning a non-generic array, then we do need to cast
						parameterString += "(" + getTypeName(declaredParamType)
						        + ") ";
					}
				} else { //if (!GenericClass.isAssignable(GenericTypeReflector.getArrayComponentType(declaredParamType), GenericTypeReflector.getArrayComponentType(actualParamType))) {
					parameterString += "(" + getTypeName(declaredParamType) + ") ";
				}
			} else if (!(actualParamType instanceof ParameterizedType)) {
				parameterString += "(" + getTypeName(declaredParamType) + ") ";
			}
			if (name.contains("(short"))
				name = name.replace("(short)", "");
			if (name.contains("(byte"))
				name = name.replace("(byte)", "");
			//}
		} else {
			// We have to cast between wrappers and primitives in case there
			// are overloaded signatures. This could be optimized by checking
			// if there actually is a problem of overloaded signatures
			GenericClass parameterClass = new GenericClass(declaredParamType);
			if (parameterClass.isWrapperType() && parameters.get(i).isPrimitive()) {
				parameterString += "(" + getTypeName(declaredParamType) + ") ";
			} else if (parameterClass.isPrimitive()
			        && parameters.get(i).isWrapperType()) {
				parameterString += "(" + getTypeName(declaredParamType) + ") ";
			} else if (isOverloaded) {
				// If there is an overloaded method, we need to cast to make sure we use the right version
				if (!declaredParamType.equals(actualParamType)) {
					parameterString += "(" + getTypeName(declaredParamType) + ") ";
				}
			}
		}

		parameterString += name;
	}

	return parameterString;
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:77,代码来源:TestCodeVisitor.java

示例6: isCollectionType

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
/**
 * Return whether the given type is a collection type.
 * Arrays are considered a collection type.
 *
 * @param type The type.
 * @return Whether the given type is a collection.
 */
public static boolean isCollectionType(Type type) {
    return TypeUtils.isAssignable(type, Collection.class)
            || TypeUtils.isArrayType(type);
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:12,代码来源:MetadataUtils.java


注:本文中的org.apache.commons.lang3.reflect.TypeUtils.isArrayType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。