use of java.lang.reflect.Parameter in project SilverKing by Morgan-Stanley.
the class CPPWrapperGenerator method getMethodSignature.
private String getMethodSignature(Method m, Mode mode) {
StringBuffer sb;
boolean isFirst;
sb = new StringBuffer();
isFirst = true;
for (Parameter p : m.getParameters()) {
if (!isFirst) {
sb.append(", ");
}
sb.append(p.getType().getName());
sb.append(' ');
sb.append(p.getName());
isFirst = false;
}
return sb.toString();
}
use of java.lang.reflect.Parameter in project jdbi by jdbi.
the class ConstructorMapper method paramName.
private static String paramName(Parameter[] parameters, int position, ConstructorProperties parameterNames) {
final Parameter parameter = parameters[position];
ColumnName dbName = parameter.getAnnotation(ColumnName.class);
if (dbName != null) {
return dbName.value();
}
if (parameterNames != null) {
return parameterNames.value()[position];
}
return parameter.getName();
}
use of java.lang.reflect.Parameter in project wildfly-swarm by wildfly-swarm.
the class BuilderImpl method verifyInterface.
private <T> void verifyInterface(Class<T> typeDef) {
Method[] methods = typeDef.getMethods();
// multiple verbs
for (Method method : methods) {
boolean hasHttpMethod = false;
for (Annotation annotation : method.getAnnotations()) {
boolean isHttpMethod = (annotation.annotationType().getAnnotation(HttpMethod.class) != null);
if (!hasHttpMethod && isHttpMethod) {
hasHttpMethod = true;
} else if (hasHttpMethod && isHttpMethod) {
throw new RestClientDefinitionException("Ambiguous @Httpmethod defintion on type " + typeDef);
}
}
}
// invalid parameter
Path classPathAnno = typeDef.getAnnotation(Path.class);
final Set<String> classLevelVariables = new HashSet<>();
ResteasyUriBuilder classTemplate = null;
if (classPathAnno != null) {
classTemplate = (ResteasyUriBuilder) UriBuilder.fromUri(classPathAnno.value());
classLevelVariables.addAll(classTemplate.getPathParamNamesInDeclarationOrder());
}
ResteasyUriBuilder template;
for (Method method : methods) {
Path methodPathAnno = method.getAnnotation(Path.class);
if (methodPathAnno != null) {
template = classPathAnno == null ? (ResteasyUriBuilder) UriBuilder.fromUri(methodPathAnno.value()) : (ResteasyUriBuilder) UriBuilder.fromUri(classPathAnno.value() + "/" + methodPathAnno.value());
} else {
template = classTemplate;
}
if (template == null) {
continue;
}
// it's not executed, so this can be anything - but a hostname needs to present
template.host("localhost");
Set<String> allVariables = new HashSet<>(template.getPathParamNamesInDeclarationOrder());
Map<String, Object> paramMap = new HashMap<>();
for (Parameter p : method.getParameters()) {
PathParam pathParam = p.getAnnotation(PathParam.class);
if (pathParam != null) {
paramMap.put(pathParam.value(), "foobar");
}
}
if (allVariables.size() != paramMap.size()) {
throw new RestClientDefinitionException("Parameters and variables don't match on " + typeDef + "::" + method.getName());
}
try {
template.resolveTemplates(paramMap, false).build();
} catch (IllegalArgumentException ex) {
throw new RestClientDefinitionException("Parameter names don't match variable names on " + typeDef + "::" + method.getName(), ex);
}
}
}
use of java.lang.reflect.Parameter in project Flash by Minato262.
the class Annotation method annotation.
@SuppressWarnings("unchecked")
@Test
public void annotation() throws InvocationTargetException, IllegalAccessException {
Annotation annotationTest = new Annotation();
Class<Annotation> clazz = (Class<Annotation>) annotationTest.getClass();
RequestMapping annotation = clazz.getAnnotation(RequestMapping.class);
Assert.assertNotEquals(annotation.value(), null);
Assert.assertEquals(annotation.value(), "annotation");
Assert.assertNotEquals(annotation.method(), null);
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(RequestMapping.class)) {
RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
Assert.assertNotEquals(requestMapping, null);
Assert.assertNotEquals(requestMapping.value(), null);
Assert.assertNotEquals(requestMapping.method(), null);
Assert.assertNotEquals(requestMapping.params(), null);
Assert.assertNotEquals(requestMapping.headers(), null);
Assert.assertNotEquals(requestMapping.consumes(), null);
Assert.assertNotEquals(requestMapping.produces(), null);
}
if (method.isAnnotationPresent(ResponseBody.class)) {
ResponseBody responseBody = method.getAnnotation(ResponseBody.class);
Assert.assertNotEquals(responseBody, null);
}
Parameter[] params = method.getParameters();
if (params.length != 0) {
method.invoke(annotationTest, 1L);
}
for (Parameter param : params) {
if (param.isAnnotationPresent(RequestParam.class)) {
RequestParam requestParam = param.getAnnotation(RequestParam.class);
Assert.assertNotEquals(requestParam, null);
}
}
}
System.out.println(annotationTest.getGetId());
System.out.println(annotationTest.getPostId());
System.out.println(annotationTest.getPutId());
System.out.println(annotationTest.getDeleteId());
System.out.println(annotationTest.getHandler());
}
use of java.lang.reflect.Parameter in project markdown-doclet by Abnaxos.
the class ReflectedOptions method processorForMethod.
public static OptionProcessor processorForMethod(Object target, Method method) {
List<ArgumentConverter<?>> converters = new ArrayList<>(method.getParameterCount());
for (Parameter parameter : method.getParameters()) {
ArgumentConverter<?> converter;
OptionConsumer.Converter converterAnnotation = parameter.getAnnotation(OptionConsumer.Converter.class);
if (converterAnnotation != null) {
try {
converter = converterAnnotation.value().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new ReflectionException("Error instantiating converter for parameter " + parameter + " method " + method);
}
} else {
converter = StandardArgumentConverters.forType(parameter.getParameterizedType());
if (converter == null) {
throw new ReflectionException("No argument converter found for parameter " + parameter.getName() + " of " + method);
}
}
converters.add(converter);
}
return (name, arguments) -> {
if (arguments.size() != converters.size()) {
throw new InvalidOptionArgumentsException("Unexpected argument count: " + arguments.size() + "!=" + converters.size() + "(expeted)");
}
Object[] methodArguments = new Object[arguments.size()];
for (int i = 0; i < arguments.size(); i++) {
methodArguments[i] = converters.get(i).convert(arguments.get(i));
}
try {
method.invoke(target, methodArguments);
} catch (IllegalAccessException e) {
throw new ArgumentsProcessingException(e);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof InvalidOptionArgumentsException) {
throw (InvalidOptionArgumentsException) e.getTargetException();
} else {
throw new ArgumentsProcessingException(e);
}
}
};
}
Aggregations