本文整理汇总了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);
}
示例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();
}
示例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;
}