use of com.github.ljtfreitas.julian.Endpoint.Parameters in project julian-http-client by ljtfreitas.
the class JavaMethod method create.
static JavaMethod create(Class<?> declaredOn, Method javaMethod, Collection<Class<?>> unhandledParameterTypes) {
nonNull(declaredOn);
nonNull(javaMethod);
Scannotation scannotation = new Scannotation(javaMethod);
HTTPMethodDefinition httpMethodDefinition = scannotation.find(HTTPMethodDefinition.class).or(() -> state(scannotation.meta(HTTPMethodDefinition.class).collect(toUnmodifiableList()), s -> s.size() <= 1, () -> "Method {0} is invalid; it's allowed just one HTTP method annotation.").stream().findFirst().map(m -> m.annotationType().getAnnotation(HTTPMethodDefinition.class))).orElseThrow(() -> new IllegalStateException(format("Method {0} must be annotated with some HTTP method.", javaMethod)));
String httpMethod = httpMethodDefinition.value();
Optional<String> path = scannotation.find(Path.class).map(Path::value).or(() -> scannotation.meta(HTTPMethodDefinition.class).findFirst().map(a -> Except.run(() -> a.annotationType().getMethod("value")).map(m -> m.invoke(a).toString()).unsafe()));
Stream<Header> headers = scannotation.scan(Header.class);
Stream<Cookie> cookies = scannotation.scan(Cookie.class);
Stream<QueryParameter> queryParameters = scannotation.scan(QueryParameter.class);
Parameters parameters = new JavaMethodParameters(declaredOn, javaMethod).read(unhandledParameterTypes);
JavaType returnType = JavaType.valueOf(declaredOn, javaMethod.getGenericReturnType());
return new JavaMethod(javaMethod, path, httpMethod, headers, cookies, queryParameters, parameters, returnType);
}
Aggregations