use of com.github.davidmoten.odata.client.generator.model.Action.ReturnType in project odata-client by davidmoten.
the class Generator method writeAction.
private void writeAction(Imports imports, Indent indent, PrintWriter p, Action action, Set<String> methodNames) {
//
p.format(//
"\n%s@%s(name = \"%s\")\n", //
indent, //
imports.add(com.github.davidmoten.odata.client.annotation.Action.class), action.getName());
p.format("%s@%s\n", indent, imports.add(JsonIgnore.class));
List<Parameter> parameters = action.getParametersUnbound(imports);
String paramsDeclaration = //
parameters.stream().map(//
x -> String.format("%s %s", x.importedFullClassName, x.nameJava())).collect(Collectors.joining(", "));
String methodName = disambiguateMethodName(action.getActionMethodName(), methodNames, "_Action");
if (action.hasReturnType()) {
ReturnType returnType = action.getReturnType(imports);
boolean isNonCollectionEdm = !returnType.isCollection && returnType.innerType.startsWith("Edm.");
final String typ;
if (returnType.isStream()) {
typ = imports.add(FunctionRequestReturningStream.class);
} else {
typ = (returnType.isCollection ? imports.add(CollectionPageNonEntityRequest.class) : isNonCollectionEdm ? //
imports.add(ActionRequestReturningNonCollection.class) : //
imports.add(ActionRequestReturningNonCollectionUnwrapped.class)) + //
"<" + //
action.getReturnType(imports).innerImportedFullClassName + ">";
}
//
p.format(//
"%spublic %s %s(%s) {\n", //
indent, //
typ, //
methodName, paramsDeclaration);
writeActionParameterMapAndNullChecksAndAsciiChecks(imports, indent, p, parameters);
if (returnType.isCollection) {
p.format(//
"%sreturn %s.forAction(this.contextPath.addActionOrFunctionSegment(\"%s\"), %s.class, _parameters);\n", //
indent, //
imports.add(CollectionPageNonEntityRequest.class), //
action.getFullType(), returnType.innerImportedFullClassName);
} else if (returnType.isStream()) {
p.format(//
"%sthrow new %s(\"Actions that return a stream are not supported yet. If you want this raise an issue at the project home\");\n", //
indent, //
imports.add(UnsupportedOperationException.class), action.getFullType());
} else
p.format(//
"%sreturn new %s<%s>(this.contextPath.addActionOrFunctionSegment(\"%s\"), %s.class, _parameters);\n", //
indent, isNonCollectionEdm ? imports.add(ActionRequestReturningNonCollection.class) : //
imports.add(ActionRequestReturningNonCollectionUnwrapped.class), //
returnType.innerImportedFullClassName, //
action.getFullType(), returnType.innerImportedFullClassName);
} else {
//
p.format(//
"%spublic %s %s(%s) {\n", //
indent, //
imports.add(ActionRequestNoReturn.class), methodName, paramsDeclaration);
writeActionParameterMapAndNullChecksAndAsciiChecks(imports, indent, p, parameters);
p.format(//
"%sreturn new %s(this.contextPath.addActionOrFunctionSegment(\"%s\"), _parameters);\n", //
indent, //
imports.add(ActionRequestNoReturn.class), action.getFullType());
}
p.format("%s}\n", indent.left());
}
Aggregations