io.vertx.codegen.MethodInfo Java Examples
The following examples show how to use
io.vertx.codegen.MethodInfo.
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: 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 #3
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 #4
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 #5
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 6 votes |
@Test public void testMethodWithOverloadedNullableParam() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(2, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 2, "void", MethodKind.OTHER); assertEquals(ClassKind.STRING, mi1.getParams().get(0).getType().getKind()); checkParam(mi1.getParams().get(0), "s", String.class); assertTrue(mi1.getParams().get(0).isNullable()); checkParam(mi1.getParams().get(1), "i", Integer.class); assertFalse(mi1.getParams().get(1).isNullable()); MethodInfo mi2 = methods.get(1); checkMethod(mi2, "method", 2, "void", MethodKind.OTHER); checkParam(mi2.getParams().get(0), "i", Integer.class); assertFalse(mi2.getParams().get(0).isNullable()); checkParam(mi2.getParams().get(1), "s", String.class); assertTrue(mi2.getParams().get(1).isNullable()); }, MethodWithOverloadedNullableParam.class); }
Example #6
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithHandlerNullable() throws Exception { for (Class<?> clazz : Arrays.asList( MethodWithHandlerNullable.class, MethodWithNullableTypeVariableHandler.class, MethodWithHandlerNullableVoid.class)) { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); assertTrue(((ParameterizedTypeInfo) mi1.getParams().get(0).getType()).getArg(0).isNullable()); }, clazz); } }
Example #7
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableNonAnnotatedTypeVariableParam() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.OTHER); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableNonAnnotatedTypeVariableParam.class); }
Example #8
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableNonAnnotatedTypeVariableHandler() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.HANDLER); assertFalse(mi1.getParams().get(0).isNullableCallback()); }, MethodWithNullableNonAnnotatedTypeVariableHandler.class); }
Example #9
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithHandlerAsyncResultNullable() throws Exception { for (Class<?> clazz : Arrays.asList( MethodWithNullableTypeVariableHandlerAsyncResult.class, MethodWithNullableStringHandlerAsyncResult.class, MethodWithHandlerAsyncResultNullableVoid.class)) { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.FUTURE); assertTrue(mi1.getParams().get(0).isNullableCallback()); }, clazz); } }
Example #10
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableStringHandlerAsyncResult() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.FUTURE); assertTrue(mi1.getParams().get(0).isNullableCallback()); }, MethodWithNullableStringHandlerAsyncResult.class); }
Example #11
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableNonAnnotatedTypeVariableHandlerAsyncResult() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.FUTURE); assertFalse(mi1.getParams().get(0).isNullableCallback()); }, MethodWithNullableNonAnnotatedTypeVariableHandlerAsyncResult.class); }
Example #12
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testInterfaceWithNullableReturnOverride() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi3 = methods.get(0); assertTrue(mi3.getReturnType().isNullable()); }, InterfaceWithNullableReturnOverride.class, InterfaceWithNullableReturnMethod.class); }
Example #13
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableTypeVariableReturn() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 0, "T", MethodKind.OTHER); assertTrue(mi1.isNullableReturn()); }, MethodWithNullableTypeVariableReturn.class); }
Example #14
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableNonAnnotatedTypeVariableReturn() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 0, "T", MethodKind.OTHER); assertFalse(mi1.isNullableReturn()); }, MethodWithNullableNonAnnotatedTypeVariableReturn.class); }
Example #15
Source File: DocTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testLinkToMethodInSameType() throws Exception { ClassModel model = new GeneratorHelper().generateClass(LinkToMethodInSameType.class); MethodInfo method = model.getMethodMap().get("m").get(0); Doc doc = method.getDoc(); List<Token> tokens = doc.getTokens(); assertEquals(4, tokens.size()); for (Token token : tokens) { Tag.Link link = (Tag.Link) ((Token.InlineTag) token).getTag(); assertEquals(ElementKind.METHOD, link.getTargetElement().getKind()); assertEquals("method(java.lang.String,int)", link.getTargetElement().toString()); } }
Example #16
Source File: DocTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testLinkToSameType() throws Exception { ClassModel model = new GeneratorHelper().generateClass(LinkToSameType.class); MethodInfo method = model.getMethodMap().get("m").get(0); Doc doc = method.getDoc(); List<Token> tokens = doc.getTokens(); assertEquals(2, tokens.size()); for (Token token : tokens) { Tag.Link link = (Tag.Link) ((Token.InlineTag) token).getTag(); assertEquals(LinkToSameType.class.getName(), link.getTargetElement().toString()); } }
Example #17
Source File: DocTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testLinkToEnum() throws Exception { ClassModel model = new GeneratorHelper().generateClass(LinkToEnum.class); MethodInfo method = model.getMethodMap().get("m").get(0); Doc doc = method.getDoc(); List<Token> tokens = doc.getTokens(); assertEquals(2, tokens.size()); for (Token token : tokens) { Tag.Link link = (Tag.Link) ((Token.InlineTag) token).getTag(); assertEquals(FooEnum.class.getName(), link.getTargetElement().toString()); } }
Example #18
Source File: DocTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testLinkLabel() throws Exception { ClassModel model = new GeneratorHelper().generateClass(LinkLabel.class); MethodInfo method = model.getMethodMap().get("m").get(0); Doc doc = method.getDoc(); List<Token> tokens = doc.getTokens(); String[] expectedLabels = {""," "," the label value"}; assertEquals(expectedLabels.length, tokens.size()); for (int i = 0;i < tokens.size();i++) { Tag.Link link = (Tag.Link) ((Token.InlineTag) tokens.get(i)).getTag(); assertEquals("" + i,expectedLabels[i], link.getLabel()); } }
Example #19
Source File: RxJavaGenerator.java From vertx-rx with Apache License 2.0 | 5 votes |
@Override protected void genMethods(ClassModel model, MethodInfo method, List<String> cacheDecls, boolean genBody, PrintWriter writer) { genMethod(model, method, cacheDecls, genBody, writer); MethodInfo overloaded = genOverloadedMethod(method); if (overloaded != null) { genMethod(model, overloaded, cacheDecls, genBody, writer); } }
Example #20
Source File: RxJavaGenerator.java From vertx-rx with Apache License 2.0 | 5 votes |
private boolean foo(MethodInfo m1, MethodInfo m2) { int numParams = m1.getParams().size(); if (m1.getName().equals(m2.getName()) && numParams == m2.getParams().size()) { for (int index = 0; index < numParams; index++) { TypeInfo t1 = unwrap(m1.getParam(index).getType()); TypeInfo t2 = unwrap(m2.getParam(index).getType()); if (!t1.equals(t2)) { return false; } } return true; } return false; }
Example #21
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 #22
Source File: RxJava2Generator.java From vertx-rx with Apache License 2.0 | 5 votes |
@Override protected void genMethods(ClassModel model, MethodInfo method, List<String> cacheDecls, boolean genBody, PrintWriter writer) { genMethod(model, method, cacheDecls, genBody, writer); MethodInfo flowableOverload = genOverloadedMethod(method, io.reactivex.Flowable.class); MethodInfo observableOverload = genOverloadedMethod(method, io.reactivex.Observable.class); if (flowableOverload != null) { genMethod(model, flowableOverload, cacheDecls, genBody, writer); } if (observableOverload != null) { genMethod(model, observableOverload, cacheDecls, genBody, writer); } }
Example #23
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 #24
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 #25
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableParam() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.OTHER); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableParam.class); }
Example #26
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableHandler() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.HANDLER); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableHandler.class); }
Example #27
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableHandlerAsyncResult() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.FUTURE); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableHandlerAsyncResult.class); }
Example #28
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testInterfaceWithNullableParamOverride() throws Exception { Consumer<ClassModel> test = model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); assertTrue(mi1.getParams().get(0).isNullable()); }; // generateClass(test, MethodWithNullableParamOverride.class, MethodWithNullableParam.class); generateClass(test, MethodWithNullableParamOverride.class); }
Example #29
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testInterfaceWithListNullableParamOverride() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi2 = methods.get(0); assertTrue(((ParameterizedTypeInfo) mi2.getParams().get(0).getType()).getArg(0).isNullable()); }, MethodWithListNullableParamOverride.class, MethodWithListNullableParam.class); }
Example #30
Source File: ClassNullableTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testMethodWithNullableInheritedParams() throws Exception { Consumer<ClassModel> check = model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi2 = methods.get(0); assertTrue(mi2.getParams().get(0).getType().isNullable()); assertTrue(((ParameterizedTypeInfo) mi2.getParams().get(1).getType()).getArg(0).isNullable()); assertTrue(((ParameterizedTypeInfo) ((ParameterizedTypeInfo) mi2.getParams().get(2).getType()).getArg(0)).getArg(0).isNullable()); }; generateClass(check, MethodWithNullableInheritedParams.class, MethodWithNullableParams.class); generateClass(check, MethodWithNullableInheritedParams.class); }