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


Java TypeUtils.getArrayComponentType方法代码示例

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


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

示例3: 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


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