Java Code Examples for io.vertx.codegen.writer.CodeWriter#writeSeq()
The following examples show how to use
io.vertx.codegen.writer.CodeWriter#writeSeq() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceProxyGen.java From vertx-service-proxy with Apache License 2.0 | 6 votes |
private void generateMethods(ProxyModel model, CodeWriter writer) { for (MethodInfo m : model.getMethods()) { if (!m.isStaticMethod()) { writer.code("@Override\n"); writer.code("public"); if (!m.getTypeParams().isEmpty()) { writer.write(" <"); writer.writeSeq(m.getTypeParams().stream().map(TypeParamInfo::getName), ", "); writer.write(">"); } writer.write(" " + m.getReturnType().getSimpleName() + " " + m.getName() + "("); writer.writeSeq(m.getParams().stream().map(p -> p.getType().getSimpleName() + " " + p.getName()), ", "); writer.write("){\n"); writer.indent(); if (!((ProxyMethodInfo) m).isProxyIgnore()) generateMethodBody((ProxyMethodInfo) m, writer); if (m.isFluent()) writer.stmt("return this"); writer.unindent(); writer.code("}\n"); } } }
Example 2
Source File: ServiceProxyHandlerGen.java From vertx-service-proxy with Apache License 2.0 | 5 votes |
public void generateActionSwitchEntry(ProxyMethodInfo m, CodeWriter writer) { ParamInfo lastParam = !m.getParams().isEmpty() ? m.getParam(m.getParams().size() - 1) : null; boolean hasResultHandler = utils.isResultHandler(lastParam); writer .code("case \"" + m.getName() + "\": {\n") .indent() .code("service." + m.getName() + "(") .indent(); if (hasResultHandler) { writer.writeSeq( Stream.concat( m.getParams().subList(0, m.getParams().size() - 1).stream().map(this::generateJsonParamExtract), Stream.of(generateHandler(lastParam)) ), ",\n" + writer.indentation() ); } else { writer.writeSeq( m.getParams().stream().map(this::generateJsonParamExtract), ",\n" + writer.indentation() ); } writer.unindent(); writer.write(");\n"); if (m.isProxyClose()) writer.stmt("close()"); writer.stmt("break"); writer.unindent(); writer.code("}\n"); }
Example 3
Source File: WebApiProxyHandlerGen.java From vertx-web with Apache License 2.0 | 4 votes |
public void generateActionSwitchEntry(ProxyMethodInfo m, CodeWriter writer) { if (m.isProxyClose()) { super.generateActionSwitchEntry(m, writer); return; } TypeInfo returnType = m.getReturnType(); writer .codeln(String.format("case \"%s\": {", m.getName())) .indent() .stmt("JsonObject contextSerialized = json.getJsonObject(\"context\")") .codeln("if (contextSerialized == null)") .indent() .stmt("throw new IllegalStateException(\"Received action \" + action + \" without ServiceRequest \\\"context\\\"\")") .unindent() .stmt("ServiceRequest context = new ServiceRequest(contextSerialized)") .stmt("JsonObject params = context.getParams()") .codeln("try {") .indent() .code(String.format("service.%s(", m.getName())) .indent(); Stream<String> methodParamsTail = Stream.of("context", serviceCallHandler); writer.writeSeq( Stream.concat( ((WebApiProxyMethodInfo) m).getParamsToExtract().stream().map(this::generateJsonParamExtractFromContext), methodParamsTail ), ",\n" + writer.indentation() ); writer.unindent(); writer.write(");\n"); writer.unindent() .codeln("} catch (Exception e) {") .indent() .stmt("HelperUtils.manageFailure(msg, e, includeDebugInfo)") .unindent() .codeln("}"); if (m.isProxyClose()) writer.stmt("close()"); writer.stmt("break"); writer.unindent(); writer.codeln("}"); }