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);
}
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);
}
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);
}
Aggregations