本文整理汇总了Java中com.thoughtworks.paranamer.Paranamer.lookupParameterNames方法的典型用法代码示例。如果您正苦于以下问题:Java Paranamer.lookupParameterNames方法的具体用法?Java Paranamer.lookupParameterNames怎么用?Java Paranamer.lookupParameterNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thoughtworks.paranamer.Paranamer
的用法示例。
在下文中一共展示了Paranamer.lookupParameterNames方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CodeGeneratorMethod
import com.thoughtworks.paranamer.Paranamer; //导入方法依赖的package包/类
public CodeGeneratorMethod(Method m) {
this.underlyingMethod = m;
this.methodName = m.getName();
this.returnType = m.getReturnType();
// Paranamer para = new BytecodeReadingParanamer();
Paranamer para = new AnnotationParanamer();
String[] parameterNames = para.lookupParameterNames(m, true);
if (parameterNames == null) {
throw new RuntimeException(String.format("Unable to read the parameter names for method %s. This is likely due to the class files not including the appropriate debugging information. Look up java -g for more information.", m));
}
Class<?>[] types = m.getParameterTypes();
if (parameterNames.length != types.length) {
throw new RuntimeException(String.format("Unexpected number of parameter names %s. Expected %s on method %s.", Arrays.toString(parameterNames), Arrays.toString(types), m.toGenericString()));
}
arguments = new CodeGeneratorArgument[parameterNames.length];
for (int i = 0 ; i < parameterNames.length; i++) {
arguments[i] = new CodeGeneratorArgument(parameterNames[i], types[i]);
}
exs = m.getExceptionTypes();
}
示例2: signature
import com.thoughtworks.paranamer.Paranamer; //导入方法依赖的package包/类
/**
* Extract {@link MBeanParameterInfo} signature for given method.
*/
private MBeanParameterInfo[] signature(final Method method) {
// NOTE: when NX is based on Java8 we can replace Paranamer usage with JDK api
Paranamer paranamer = new BytecodeReadingParanamer();
String[] names = paranamer.lookupParameterNames(method);
Class[] types = method.getParameterTypes();
Annotation[][] annotations = method.getParameterAnnotations();
MBeanParameterInfo[] result = new MBeanParameterInfo[names.length];
for (int i=0; i< names.length; i++) {
Descriptor descriptor = DescriptorHelper.build(annotations[i]);
String description = DescriptorHelper.stringValue(descriptor, "description");
result[i] = new MBeanParameterInfo(
names[i],
types[i].getName(),
description,
descriptor
);
}
return result;
}
示例3: generate
import com.thoughtworks.paranamer.Paranamer; //导入方法依赖的package包/类
@Test
public void generate() {
Class<SakaiPortalLogin> clazz = SakaiPortalLogin.class;
for (Method method : clazz.getMethods()) {
if (!method.getDeclaringClass().getName().equals(clazz.getName())) {
continue;
}
log.info("@WebMethod");
log.info("@Path(\"/" + method.getName() + "\")");
log.info("@Produces(\"text/plain\")");
log.info("@GET");
log.info("public " + method.getReturnType().getSimpleName() + " " + method.getName() + "(");
Paranamer paranamer = new BytecodeReadingParanamer();
try {
String[] parameterNames = paranamer.lookupParameterNames(method);
Class<?>[] types = method.getParameterTypes();
int i = 0;
for (String name : parameterNames) {
log.info("@WebParam(name = \"" + name + "\", partName = \"" + name + "\") @QueryParam(\"" + name + "\") " + types[i].getSimpleName() + " " + name);
if (i + 1 != parameterNames.length) {
log.info(",");
} else {
log.info(") {\n");
}
i++;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
示例4: createErrorController
import com.thoughtworks.paranamer.Paranamer; //导入方法依赖的package包/类
protected HttpHandler createErrorController(String error , Class<?> clazz , Class defaultClass){
clazz = clazz == null ? defaultClass : clazz;
ControllerMapping controllerMapping = new ControllerMapping( error , error);
controllerMapping.setControllerClass( clazz );
try {
Method handlerError = clazz.getMethod("handleError", OvertownRequest.class);
PathMapping methodMapping = new PathMapping( error , null , handlerError , getTemplate(handlerError) , handlerError.getAnnotation(JSONResponse.class) != null );
Paranamer paranamer = new CachingParanamer(new BytecodeReadingParanamer());
return new MainHttpHandler( controllerMapping , methodMapping , paranamer.lookupParameterNames( handlerError ) );
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
示例5: getMethodParamName
import com.thoughtworks.paranamer.Paranamer; //导入方法依赖的package包/类
public static String getMethodParamName(Method method, int i) {
Paranamer pn = new BytecodeReadingParanamer();
method.setAccessible(true);
try {
String[] paramNames = pn.lookupParameterNames(method, true);
return paramNames[i];
} catch (Exception e) {
return "@arg(" + i + ")";
}
}
示例6: getName
import com.thoughtworks.paranamer.Paranamer; //导入方法依赖的package包/类
public String getName() {
Param param = getAnnotation(Param.class);
if (param != null) {
return param.value();
}
if (parameter.isNamePresent()) {
return parameter.getName();
}
Paranamer paranamer = getTypeDescriptors().getParanamer();
String[] names = paranamer.lookupParameterNames(getAccessibleObject());
return names.length > index ? names[index] : "arg" + index;
}
示例7: build
import com.thoughtworks.paranamer.Paranamer; //导入方法依赖的package包/类
public MBeanOperation build()
{
if (target == null) {
throw new IllegalArgumentException("JmxOperation must have a target object");
}
// We must have a method to invoke
if (concreteMethod == null) {
throw new IllegalArgumentException("JmxOperation must have a concrete method");
}
String operationName = name;
if (operationName == null) {
operationName = concreteMethod.getName();
}
//
// Build Parameter Infos
// Extract parameter names from debug symbols
Paranamer paranamer = new BytecodeReadingParanamer();
String[] parameterNames = paranamer.lookupParameterNames(concreteMethod);
Class<?>[] types = concreteMethod.getParameterTypes();
// Parameter annotations used form descriptor come from the annotated method, not the public method
Annotation[][] parameterAnnotations;
if (annotatedMethod != null) {
parameterAnnotations = annotatedMethod.getParameterAnnotations();
}
else {
parameterAnnotations = new Annotation[annotatedMethod.getParameterTypes().length][];
}
MBeanParameterInfo[] parameterInfos = new MBeanParameterInfo[parameterNames.length];
for (int i = 0; i < parameterNames.length; ++i) {
// Parameter Descriptor
Descriptor parameterDescriptor = AnnotationUtils.buildDescriptor(parameterAnnotations[i]);
// Parameter Description
String parameterDescription = AnnotationUtils.getDescription(parameterDescriptor, parameterAnnotations[i]);
parameterInfos[i] = new MBeanParameterInfo(
parameterNames[i],
types[i].getName(),
parameterDescription,
parameterDescriptor);
}
// Descriptor
Descriptor descriptor = null;
if (annotatedMethod != null) {
descriptor = AnnotationUtils.buildDescriptor(annotatedMethod);
}
// Description
String description = AnnotationUtils.getDescription(descriptor, annotatedMethod);
MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(
operationName,
description,
parameterInfos,
concreteMethod.getReturnType().getName(),
MBeanOperationInfo.UNKNOWN,
descriptor);
return new ReflectionMBeanOperation(mbeanOperationInfo, target, concreteMethod);
}
示例8: initialMethod
import com.thoughtworks.paranamer.Paranamer; //导入方法依赖的package包/类
/**
* 初始化 方法参数定义
*/
private void initialMethod() {
isvoid = method.getReturnType().getName().equals("void");
if (method.getParameterTypes().length == 0) {
return;
}
methodParamMap = new LinkedHashMap<String, MethodParam>();
methodParamList = new ArrayList<MethodParam>();
Paranamer paranamer = new BytecodeReadingParanamer();
String[] parameterNames = paranamer.lookupParameterNames(method);
Annotation[][] pas = method.getParameterAnnotations();
int i = 0;
for (Class<?> typeClass : method.getParameterTypes()) {
MethodParam mp = new MethodParam();
String name = parameterNames[i];
Convert convert = CONVERT_MAP.get(typeClass);
if (typeClass.equals(BModelMap.class)) {
if (modelMapParamIndex != null) {
logger.error("view block only set one BModelMap");
}
modelMapParamIndex = i;
} else if (convert == null) {
convert = CONVERT_MAP.get(BRequestParam.class);
for (Annotation a : pas[i]) {
if (a.annotationType().equals(BRequestParam.class)) {
BRequestParam p = (BRequestParam) a;
boolean required = false;
Object defValue = null;
// RequestParam 注解
if (p != null) {
if (!"".equals(p.value())) {
name = p.value();
}
if (!p.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
if (ConvertUtils.lookup(typeClass) != null) {
defValue = ConvertUtils.convert(p.defaultValue(), typeClass);
}
}
required = p.required();
}
// others param
mp.setRequired(required);
mp.setDefValue(defValue);
break;
} else if (a.annotationType().equals(BModelAttribute.class)) {
mp.setModelAttribute(true);
break;
}
}
}
mp.setName(name);
mp.setIndex(i);
mp.setConvert(convert);
mp.setTypeClass(typeClass);
methodParamMap.put(mp.getName(), mp);
methodParamList.add(mp);
i++;
}
}