io.vertx.codegen.ParamInfo Java Examples
The following examples show how to use
io.vertx.codegen.ParamInfo.
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: RxJavaGenerator.java From vertx-rx with Apache License 2.0 | 6 votes |
@Override protected void genRxMethod(ClassModel model, MethodInfo method, List<String> cacheDecls, boolean genBody, PrintWriter writer) { ClassTypeInfo type = model.getType(); String packageName = type.getPackageName(); writer.print(" "); MethodInfo futMethod = genFutureMethod(method); startMethodTemplate(type, futMethod, "", writer); if (genBody) { writer.println(" { "); writer.println(" return Single.create(new SingleOnSubscribeAdapter<>(fut -> {"); writer.print(" "); writer.print(method.getName()); writer.print("("); writer.print(futMethod.getParams().stream().map(ParamInfo::getName).collect(Collectors.joining(", "))); if (futMethod.getParams().size() > 0) { writer.print(", "); } writer.println("fut);"); writer.println(" }));"); writer.println(" }"); } else { writer.println(";"); } writer.println(); }
Example #2
Source File: RxJavaGenerator.java From vertx-rx with Apache License 2.0 | 6 votes |
private MethodInfo genFutureMethod(MethodInfo method) { String futMethodName = genFutureMethodName(method); List<ParamInfo> futParams = new ArrayList<>(); int count = 0; int size = method.getParams().size() - 1; while (count < size) { ParamInfo param = method.getParam(count); /* Transform ReadStream -> Observable */ futParams.add(param); count = count + 1; } ParamInfo futParam = method.getParam(size); TypeInfo futType = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) futParam.getType()).getArg(0)).getArg(0); ParameterizedTypeInfo futReturnType = new io.vertx.codegen.type.ParameterizedTypeInfo(io.vertx.codegen.type.TypeReflectionFactory.create(rx.Single.class).getRaw(), false, java.util.Collections.singletonList(futType)); return method.copy().setName(futMethodName).setParams(futParams).setReturnType(futReturnType); }
Example #3
Source File: RxJava2Generator.java From vertx-rx with Apache License 2.0 | 6 votes |
private MethodInfo genFutureMethod(MethodInfo method) { String futMethodName = genFutureMethodName(method); List<ParamInfo> futParams = new ArrayList<>(); int count = 0; int size = method.getParams().size() - 1; while (count < size) { ParamInfo param = method.getParam(count); /* Transform ReadStream -> Flowable */ futParams.add(param); count = count + 1; } ParamInfo futParam = method.getParam(size); TypeInfo futType = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) futParam.getType()).getArg(0)).getArg(0); TypeInfo futUnresolvedType = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) futParam.getUnresolvedType()).getArg(0)).getArg(0); TypeInfo futReturnType; if (futUnresolvedType.getKind() == VOID) { futReturnType = io.vertx.codegen.type.TypeReflectionFactory.create(io.reactivex.Completable.class); } else if (futUnresolvedType.isNullable()) { futReturnType = new io.vertx.codegen.type.ParameterizedTypeInfo(io.vertx.codegen.type.TypeReflectionFactory.create(io.reactivex.Maybe.class).getRaw(), false, Collections.singletonList(futType)); } else { futReturnType = new io.vertx.codegen.type.ParameterizedTypeInfo(io.vertx.codegen.type.TypeReflectionFactory.create(io.reactivex.Single.class).getRaw(), false, Collections.singletonList(futType)); } return method.copy().setName(futMethodName).setReturnType(futReturnType).setParams(futParams); }
Example #4
Source File: RxJavaGenerator.java From vertx-rx with Apache License 2.0 | 5 votes |
private MethodInfo genOverloadedMethod(MethodInfo method) { List<ParamInfo> params = null; int count = 0; for (ParamInfo param : method.getParams()) { if (param.getType().isParameterized() && param.getType().getRaw().getName().equals("io.vertx.core.streams.ReadStream")) { if (params == null) { params = new java.util.ArrayList<>(method.getParams()); } ParameterizedTypeInfo paramType = new io.vertx.codegen.type.ParameterizedTypeInfo( io.vertx.codegen.type.TypeReflectionFactory.create(rx.Observable.class).getRaw(), false, java.util.Collections.singletonList(((ParameterizedTypeInfo) param.getType()).getArg(0)) ); params.set(count, new io.vertx.codegen.ParamInfo( param.getIndex(), param.getName(), param.getDescription(), paramType )); } count = count + 1; } if (params != null) { return method.copy().setParams(params); } return null; }
Example #5
Source File: RxJava2Generator.java From vertx-rx with Apache License 2.0 | 5 votes |
@Override protected void genRxMethod(ClassModel model, MethodInfo method, List<String> cacheDecls, boolean genBody, PrintWriter writer) { MethodInfo futMethod = genFutureMethod(method); ClassTypeInfo raw = futMethod.getReturnType().getRaw(); String methodSimpleName = raw.getSimpleName(); String adapterType = "AsyncResult" + methodSimpleName + ".to" + methodSimpleName; String rxType = raw.getName(); startMethodTemplate(model.getType(), futMethod, "", writer); if (genBody) { writer.println(" { "); writer.print(" return "); writer.print(adapterType); writer.println("($handler -> {"); writer.print(" "); writer.print(method.getName()); writer.print("("); List<ParamInfo> params = futMethod.getParams(); writer.print(params.stream().map(ParamInfo::getName).collect(Collectors.joining(", "))); if (params.size() > 0) { writer.print(", "); } writer.println("$handler);"); writer.println(" });"); writer.println(" }"); } else { writer.println(";"); } writer.println(); }
Example #6
Source File: RxJava2Generator.java From vertx-rx with Apache License 2.0 | 5 votes |
private MethodInfo genOverloadedMethod(MethodInfo method, Class streamType) { List<ParamInfo> params = null; int count = 0; for (ParamInfo param : method.getParams()) { if (param.getType().isParameterized() && param.getType().getRaw().getName().equals("io.vertx.core.streams.ReadStream")) { if (params == null) { params = new ArrayList<>(method.getParams()); } ParameterizedTypeInfo paramType = new io.vertx.codegen.type.ParameterizedTypeInfo( io.vertx.codegen.type.TypeReflectionFactory.create(streamType).getRaw(), false, java.util.Collections.singletonList(((ParameterizedTypeInfo) param.getType()).getArg(0)) ); params.set(count, new io.vertx.codegen.ParamInfo( param.getIndex(), param.getName(), param.getDescription(), paramType )); } count = count + 1; } if (params != null) { return method.copy().setParams(params); } return null; }
Example #7
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 #8
Source File: ProxyMethodInfo.java From vertx-service-proxy with Apache License 2.0 | 5 votes |
public ProxyMethodInfo(Set<ClassTypeInfo> ownerTypes, String name, TypeInfo returnType, Text returnDescription, boolean fluent, boolean cacheReturn, List<ParamInfo> params, String comment, Doc doc, boolean staticMethod, boolean defaultMethod, List<TypeParamInfo.Method> typeParams, boolean proxyIgnore, boolean proxyClose, boolean deprecated, Text deprecatedDesc) { super(ownerTypes, name, returnType, returnDescription, fluent, cacheReturn, params, comment, doc, staticMethod, defaultMethod, typeParams, deprecated, deprecatedDesc); this.proxyIgnore = proxyIgnore; this.proxyClose = proxyClose; }
Example #9
Source File: ServiceProxyGen.java From vertx-service-proxy with Apache License 2.0 | 5 votes |
private void generateMethodBody(ProxyMethodInfo method, CodeWriter writer) { ParamInfo lastParam = !method.getParams().isEmpty() ? method.getParam(method.getParams().size() - 1) : null; boolean hasResultHandler = utils.isResultHandler(lastParam); if (hasResultHandler) { writer.code("if (closed) {\n"); writer.indent(); writer.stmt(lastParam.getName() + ".handle(Future.failedFuture(new IllegalStateException(\"Proxy is closed\")))"); if (method.isFluent()) writer.stmt("return this"); else writer.stmt("return"); writer.unindent(); writer.code("}\n"); } else { writer.code("if (closed) throw new IllegalStateException(\"Proxy is closed\");\n"); } if (method.isProxyClose()) writer.stmt("closed = true"); writer.stmt("JsonObject _json = new JsonObject()"); List<ParamInfo> paramsExcludedHandler = (method.getParams().isEmpty()) ? new ArrayList<>() : (hasResultHandler) ? method.getParams().subList(0, method.getParams().size() - 1) : method.getParams(); paramsExcludedHandler.forEach(p -> generateAddToJsonStmt(p, writer)); writer.newLine(); writer.stmt("DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions()"); writer.stmt("_deliveryOptions.addHeader(\"action\", \"" + method.getName() + "\")"); if (hasResultHandler) { generateSendCallWithResultHandler(lastParam, writer); } else { writer.stmt("_vertx.eventBus().send(_address, _json, _deliveryOptions)"); } }
Example #10
Source File: WebApiProxyMethodInfo.java From vertx-web with Apache License 2.0 | 4 votes |
public WebApiProxyMethodInfo(Set<ClassTypeInfo> ownerTypes, String name, TypeInfo returnType, Text returnDescription, boolean fluent, boolean cacheReturn, List<ParamInfo> params, String comment, Doc doc, boolean staticMethod, boolean defaultMethod, List<TypeParamInfo.Method> typeParams, boolean proxyIgnore, boolean proxyClose, boolean deprecated, Text deprecatedDesc) { super(ownerTypes, name, returnType, returnDescription, fluent, cacheReturn, params, comment, doc, staticMethod, defaultMethod, typeParams, proxyIgnore, proxyClose, deprecated, deprecatedDesc); paramsToExtract = params.subList(0, params.size() - 2); requestContextName = params.get(params.size() - 2).getName(); }
Example #11
Source File: WebApiProxyMethodInfo.java From vertx-web with Apache License 2.0 | 4 votes |
public List<ParamInfo> getParamsToExtract() { return paramsToExtract; }
Example #12
Source File: GeneratorUtils.java From vertx-service-proxy with Apache License 2.0 | 4 votes |
public boolean isResultHandler(ParamInfo param) { return param != null && param.getType().getKind() == ClassKind.HANDLER && ((ParameterizedTypeInfo)param.getType()).getArg(0).getKind() == ClassKind.ASYNC_RESULT; }
Example #13
Source File: ServiceProxyHandlerGen.java From vertx-service-proxy with Apache License 2.0 | 4 votes |
public String generateHandler(ParamInfo param) { TypeInfo typeArg = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) param.getType()).getArg(0)).getArg(0); return generateHandler(typeArg); }
Example #14
Source File: ServiceProxyGen.java From vertx-service-proxy with Apache License 2.0 | 4 votes |
private void generateSendCallWithResultHandler(ParamInfo lastParam, CodeWriter writer) { String name = lastParam.getName(); TypeInfo t = ((ParameterizedTypeInfo)((ParameterizedTypeInfo)lastParam.getType()).getArg(0)).getArg(0); wrapResult(t, name, false, writer); }