本文整理汇总了Java中com.thoughtworks.paranamer.Paranamer类的典型用法代码示例。如果您正苦于以下问题:Java Paranamer类的具体用法?Java Paranamer怎么用?Java Paranamer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Paranamer类属于com.thoughtworks.paranamer包,在下文中一共展示了Paranamer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: shouldNotAllowModificationOfConfigurationElements
import com.thoughtworks.paranamer.Paranamer; //导入依赖的package包/类
@Test
public void shouldNotAllowModificationOfConfigurationElements() throws NoSuchMethodException,
IllegalAccessException {
Configuration delegate = new MostUsefulConfiguration();
Configuration unmodifiable = new UnmodifiableConfiguration(delegate);
assertThatNotAllowed(unmodifiable, "useKeywords", Keywords.class);
assertThatNotAllowed(unmodifiable, "doDryRun", Boolean.class);
assertThatNotAllowed(unmodifiable, "useStoryControls", StoryControls.class);
assertThatNotAllowed(unmodifiable, "useStoryLoader", StoryLoader.class);
assertThatNotAllowed(unmodifiable, "useStoryParser", StoryParser.class);
assertThatNotAllowed(unmodifiable, "useDefaultStoryReporter", StoryReporter.class);
assertThatNotAllowed(unmodifiable, "useStoryReporterBuilder", StoryReporterBuilder.class);
assertThatNotAllowed(unmodifiable, "useStoryPathResolver", StoryPathResolver.class);
assertThatNotAllowed(unmodifiable, "useFailureStrategy", FailureStrategy.class);
assertThatNotAllowed(unmodifiable, "usePendingStepStrategy", PendingStepStrategy.class);
assertThatNotAllowed(unmodifiable, "useParanamer", Paranamer.class);
assertThatNotAllowed(unmodifiable, "useParameterConverters", ParameterConverters.class);
assertThatNotAllowed(unmodifiable, "useParameterControls", ParameterControls.class);
assertThatNotAllowed(unmodifiable, "useStepCollector", StepCollector.class);
assertThatNotAllowed(unmodifiable, "useStepMonitor", StepMonitor.class);
assertThatNotAllowed(unmodifiable, "useStepPatternParser", StepPatternParser.class);
assertThatNotAllowed(unmodifiable, "useViewGenerator", ViewGenerator.class);
assertThatNotAllowed(unmodifiable, "useStoryPathResolver", StoryPathResolver.class);
}
示例4: 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);
}
}
}
示例5: 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;
}
示例6: 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 + ")";
}
}
示例7: MethodInvoker
import com.thoughtworks.paranamer.Paranamer; //导入依赖的package包/类
public MethodInvoker(Method method, ParameterConverters parameterConverters, Paranamer paranamer, Meta meta) {
this.method = method;
this.parameterConverters = parameterConverters;
this.paranamer = paranamer;
this.meta = meta;
this.methodArity = method.getParameterTypes().length;
}
示例8: buildConfiguration
import com.thoughtworks.paranamer.Paranamer; //导入依赖的package包/类
/**
* Builds a Configuration instance based on annotation {@link Configure}
* found in the annotated object instance
*
* @return A Configuration instance
*/
public Configuration buildConfiguration() throws AnnotationRequired {
if (!finder.isAnnotationPresent(Configure.class)) {
// not using annotation configuration, default to most useful
// configuration
return new MostUsefulConfiguration();
}
Configuration configuration = configurationElement(finder, "using", Configuration.class);
configuration.useKeywords(configurationElement(finder, "keywords", Keywords.class));
configuration.useFailureStrategy(configurationElement(finder, "failureStrategy", FailureStrategy.class));
configuration.usePendingStepStrategy(configurationElement(finder, "pendingStepStrategy",
PendingStepStrategy.class));
configuration.useParanamer(configurationElement(finder, "paranamer", Paranamer.class));
configuration.useStoryControls(configurationElement(finder, "storyControls", StoryControls.class));
configuration.useStepCollector(configurationElement(finder, "stepCollector", StepCollector.class));
configuration.useStepdocReporter(configurationElement(finder, "stepdocReporter", StepdocReporter.class));
configuration.useStepFinder(configurationElement(finder, "stepFinder", StepFinder.class));
configuration.useStepMonitor(configurationElement(finder, "stepMonitor", StepMonitor.class));
configuration.useStepPatternParser(configurationElement(finder, "stepPatternParser", StepPatternParser.class));
configuration.useStoryLoader(configurationElement(finder, "storyLoader", StoryLoader.class));
configuration.useStoryParser(configurationElement(finder, "storyParser", StoryParser.class));
configuration.useStoryPathResolver(configurationElement(finder, "storyPathResolver", StoryPathResolver.class));
configuration
.useDefaultStoryReporter(configurationElement(finder, "defaultStoryReporter", StoryReporter.class));
configuration.useStoryReporterBuilder(configurationElement(finder, "storyReporterBuilder",
StoryReporterBuilder.class));
configuration.useViewGenerator(configurationElement(finder, "viewGenerator", ViewGenerator.class));
configuration.useParameterConverters(parameterConverters(finder));
configuration.useParameterControls(configurationElement(finder, "parameterControls", ParameterControls.class));
configuration.usePathCalculator(configurationElement(finder, "pathCalculator", PathCalculator.class));
return configuration;
}
示例9: 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;
}
示例10: AopAwareParanamerParameterNameProvider
import com.thoughtworks.paranamer.Paranamer; //导入依赖的package包/类
public AopAwareParanamerParameterNameProvider(final Paranamer paranamer) {
super(paranamer);
}
示例11: ParameterNameResolverParanamerImpl
import com.thoughtworks.paranamer.Paranamer; //导入依赖的package包/类
public ParameterNameResolverParanamerImpl(final Paranamer paranamer) {
this.paranamer = paranamer;
}
示例12: 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);
}
示例13: create
import com.thoughtworks.paranamer.Paranamer; //导入依赖的package包/类
@Override
public Paranamer create() {
return new AdaptiveParanamer(new DefaultParanamer(), new BytecodeReadingParanamer(),new NamedAnnotationParanamer());
}
示例14: ViewParamsMerger
import com.thoughtworks.paranamer.Paranamer; //导入依赖的package包/类
public ViewParamsMerger(Paranamer paranamer) {
super();
this.paranamer = paranamer;
}
示例15: 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++;
}
}