Search in sources :

Example 1 with JavaType

use of com.github.ljtfreitas.julian.JavaType in project julian-http-client by ljtfreitas.

the class JavaMethodParameter method create.

static JavaMethodParameter create(int position, Parameter javaParameter, Class<?> declaredOn) {
    Scannotation scannotation = new Scannotation(nonNull(javaParameter));
    Annotation definition = isTrue(scannotation.meta(ParameterDefinition.class).toArray(Annotation[]::new), a -> a.length == 1, () -> format("Method parameter [{0}] must have a @ParameterDefinition annotation!", javaParameter))[0];
    JavaType parameterType = JavaType.valueOf(declaredOn, javaParameter.getParameterizedType());
    ParameterDefinitionReader reader = new ParameterDefinitionReader(definition);
    String name = reader.name().orElseGet(javaParameter::getName);
    return new JavaMethodParameter(position, name, parameterType, reader);
}
Also used : Endpoint(com.github.ljtfreitas.julian.Endpoint) Preconditions.nonNull(com.github.ljtfreitas.julian.Preconditions.nonNull) Parameter(java.lang.reflect.Parameter) Annotation(java.lang.annotation.Annotation) Message.format(com.github.ljtfreitas.julian.Message.format) JavaType(com.github.ljtfreitas.julian.JavaType) Preconditions.isTrue(com.github.ljtfreitas.julian.Preconditions.isTrue) JavaType(com.github.ljtfreitas.julian.JavaType) Annotation(java.lang.annotation.Annotation)

Example 2 with JavaType

use of com.github.ljtfreitas.julian.JavaType in project julian-http-client by ljtfreitas.

the class CompletableResponseTTest method adapted.

@Test
void adapted() {
    JavaType adapted = subject.adapted(null);
    assertEquals(JavaType.none(), adapted);
}
Also used : JavaType(com.github.ljtfreitas.julian.JavaType) Test(org.junit.jupiter.api.Test)

Example 3 with JavaType

use of com.github.ljtfreitas.julian.JavaType 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

JavaType (com.github.ljtfreitas.julian.JavaType)3 Message.format (com.github.ljtfreitas.julian.Message.format)2 Preconditions.nonNull (com.github.ljtfreitas.julian.Preconditions.nonNull)2 Endpoint (com.github.ljtfreitas.julian.Endpoint)1 Parameters (com.github.ljtfreitas.julian.Endpoint.Parameters)1 Except (com.github.ljtfreitas.julian.Except)1 Preconditions.isTrue (com.github.ljtfreitas.julian.Preconditions.isTrue)1 Preconditions.state (com.github.ljtfreitas.julian.Preconditions.state)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)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 Test (org.junit.jupiter.api.Test)1