use of com.palantir.dialogue.annotations.processor.data.ReturnType in project dialogue by palantir.
the class ServiceImplementationGenerator method clientImpl.
private MethodSpec clientImpl(EndpointDefinition def) {
List<ParameterSpec> params = def.arguments().stream().map(arg -> ParameterSpec.builder(ArgumentTypes.caseOf(arg.argType()).primitive((javaTypeName, _parameterSerializerMethodName, _isList) -> javaTypeName).rawRequestBody(typeName -> typeName).optional((optionalJavaType, _unused) -> optionalJavaType).mapType(typeName -> typeName).customType(typeName -> typeName), arg.argName().get()).build()).collect(Collectors.toList());
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(def.endpointName().get()).addModifiers(Modifier.PUBLIC).addParameters(params).addAnnotation(Override.class);
methodBuilder.addCode("$T $L = $T.builder();", Request.Builder.class, REQUEST, Request.class);
def.arguments().forEach(arg -> methodBuilder.addCode(generateParam(arg)));
methodBuilder.returns(def.returns().returnType());
boolean isAsync = def.returns().asyncInnerType().isPresent();
String executeCode = isAsync ? "$L.clients().call($L, $L.build(), $L);" : "$L.clients().callBlocking($L, $L.build(), $L);";
CodeBlock execute = CodeBlock.of(executeCode, serviceDefinition.conjureRuntimeArgName(), def.channelFieldName(), REQUEST, def.returns().deserializerFieldName());
methodBuilder.addCode(!def.returns().isVoid() || isAsync ? "return $L" : "$L", execute);
return methodBuilder.build();
}
Aggregations