use of java.lang.reflect.Parameter in project completable-reactor by ru-fix.
the class LambdaReflector method signature.
static String signature(Method method) {
StringBuilder signature = new StringBuilder();
Parameter[] parameters = method.getParameters();
signature.append("(");
for (Parameter parameter : parameters) {
signature.append(signatureMapType(parameter.getType()));
}
signature.append(")");
signature.append(signatureMapType(method.getReturnType()));
return signature.toString();
}
use of java.lang.reflect.Parameter in project herd by FINRAOS.
the class RestControllerProcessor method processRestControllerClass.
/**
* Processes a Spring MVC REST controller class that is annotated with RestController. Also collects any required model objects based on parameters and
* return types of each endpoint into the specified model classes set.
*
* @param clazz the class to process
*
* @throws MojoExecutionException if any errors were encountered.
*/
private void processRestControllerClass(Class<?> clazz) throws MojoExecutionException {
// Get the Java class source information.
JavaClassSource javaClassSource = sourceMap.get(clazz.getSimpleName());
if (javaClassSource == null) {
throw new MojoExecutionException("No source resource found for class \"" + clazz.getName() + "\".");
}
Api api = clazz.getAnnotation(Api.class);
boolean hidden = api != null && api.hidden();
if ((clazz.getAnnotation(RestController.class) != null) && (!hidden)) {
log.debug("Processing RestController class \"" + clazz.getName() + "\".");
// Default the tag name to the simple class name.
String tagName = clazz.getSimpleName();
// See if the "Api" annotation exists.
if (api != null && api.tags().length > 0) {
// The "Api" annotation was found so use it's configured tag.
tagName = api.tags()[0];
} else {
// No "Api" annotation so try to get the tag name from the class name. If not, we will stick with the default simple class name.
Matcher matcher = tagPattern.matcher(clazz.getSimpleName());
if (matcher.find()) {
// If our class has the form
tagName = matcher.group("tag");
}
}
log.debug("Using tag name \"" + tagName + "\".");
// Add the tag and process each method.
swagger.addTag(new Tag().name(tagName));
List<Method> methods = Lists.newArrayList(clazz.getDeclaredMethods());
// Based on the Java 8 doc, getDeclaredMethods() is not guaranteed sorted
// In order to be sure we generate stable API when the URL's don't change
// we can give it a sort order based on the first URI hit in the request mapping
List<Method> outMethods = methods.stream().filter((method) -> {
RequestMapping rm = method.getAnnotation(RequestMapping.class);
ApiOperation apiOp = method.getAnnotation(ApiOperation.class);
return // Has RequestMapping
rm != null && // has at least 1 URI
rm.value().length > 0 && // has at least 1 HttpMethod
rm.method().length > 0 && // marked as a hidden ApiOperation
(apiOp == null || !apiOp.hidden());
}).sorted(Comparator.comparing(a -> ((Method) a).getAnnotation(RequestMapping.class).value()[0]).thenComparing(a -> ((Method) a).getAnnotation(RequestMapping.class).method()[0])).collect(Collectors.toList());
for (Method method : outMethods) {
// Get the method source information.
List<Class<?>> methodParamClasses = new ArrayList<>();
for (Parameter parameter : method.getParameters()) {
methodParamClasses.add(parameter.getType());
}
MethodSource<JavaClassSource> methodSource = javaClassSource.getMethod(method.getName(), methodParamClasses.toArray(new Class<?>[methodParamClasses.size()]));
if (methodSource == null) {
throw new MojoExecutionException("No method source found for class \"" + clazz.getName() + "\" and method name \"" + method.getName() + "\".");
}
// Process the REST controller method along with its source information.
processRestControllerMethod(method, clazz.getAnnotation(RequestMapping.class), tagName, methodSource);
}
} else {
log.debug("Skipping class \"" + clazz.getName() + "\" because it is either not a RestController or it is hidden.");
}
}
use of java.lang.reflect.Parameter in project jdbi by jdbi.
the class BindBeanListFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
final BindBeanList bindBeanList = (BindBeanList) annotation;
final String name = ParameterUtil.findParameterName(bindBeanList.value(), param).orElseThrow(() -> new UnsupportedOperationException("A @BindBeanList parameter was not given a name, " + "and parameter name data is not present in the class file, for: " + param.getDeclaringExecutable() + "::" + param));
return (stmt, arg) -> {
if (arg == null) {
throw new IllegalArgumentException("argument is null; null was explicitly forbidden on BindBeanList");
}
stmt.bindBeanList(name, IterableLike.toList(arg), Arrays.asList(bindBeanList.propertyNames()));
};
}
use of java.lang.reflect.Parameter in project jdbi by jdbi.
the class BindMapFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation a, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
BindMap annotation = (BindMap) a;
List<String> keys = Arrays.asList(annotation.keys());
String prefix = annotation.value().isEmpty() ? "" : annotation.value() + ".";
return (stmt, arg) -> {
Map<?, ?> map = (Map<?, ?>) arg;
Map<String, Object> toBind = new HashMap<>();
map.forEach((k, v) -> {
if (annotation.convertKeys() || k instanceof String) {
String key = k.toString();
if (keys.isEmpty() || keys.contains(key)) {
toBind.put(prefix + key, v);
}
} else {
throw new IllegalArgumentException("Key " + k + " (of " + k.getClass() + ") must be a String");
}
});
keys.forEach(key -> toBind.putIfAbsent(prefix + key, null));
stmt.bindMap(toBind);
};
}
use of java.lang.reflect.Parameter in project jdbi by jdbi.
the class DefineFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
Define define = (Define) annotation;
final String name = ParameterUtil.findParameterName(define.value(), param).orElseThrow(() -> new UnsupportedOperationException("A @Define parameter was not given a name, " + "and parameter name data is not present in the class file, for: " + param.getDeclaringExecutable() + "::" + param));
return (stmt, arg) -> stmt.define(name, arg);
}
Aggregations