Search in sources :

Example 1 with Parameters

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);
}
Also used : Arrays(java.util.Arrays) Collection(java.util.Collection) Except(com.github.ljtfreitas.julian.Except) Message.format(com.github.ljtfreitas.julian.Message.format) Preconditions.state(com.github.ljtfreitas.julian.Preconditions.state) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) Stream(java.util.stream.Stream) Preconditions.nonNull(com.github.ljtfreitas.julian.Preconditions.nonNull) Map(java.util.Map) Entry(java.util.Map.Entry) Optional(java.util.Optional) Predicate.not(java.util.function.Predicate.not) Method(java.lang.reflect.Method) Parameters(com.github.ljtfreitas.julian.Endpoint.Parameters) JavaType(com.github.ljtfreitas.julian.JavaType) Parameters(com.github.ljtfreitas.julian.Endpoint.Parameters) JavaType(com.github.ljtfreitas.julian.JavaType)

Aggregations

Parameters (com.github.ljtfreitas.julian.Endpoint.Parameters)1 Except (com.github.ljtfreitas.julian.Except)1 JavaType (com.github.ljtfreitas.julian.JavaType)1 Message.format (com.github.ljtfreitas.julian.Message.format)1 Preconditions.nonNull (com.github.ljtfreitas.julian.Preconditions.nonNull)1 Preconditions.state (com.github.ljtfreitas.julian.Preconditions.state)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Predicate.not (java.util.function.Predicate.not)1 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)1 Stream (java.util.stream.Stream)1