io.vertx.codegen.TypeParamInfo Java Examples
The following examples show how to use
io.vertx.codegen.TypeParamInfo.
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: RxJava2Generator.java From vertx-rx with Apache License 2.0 | 5 votes |
protected void genReadStream(List<? extends TypeParamInfo> typeParams, PrintWriter writer){ writer.print(" Observable<"); writer.print(typeParams.get(0).getName()); writer.println("> toObservable();"); writer.println(); writer.print(" Flowable<"); writer.print(typeParams.get(0).getName()); writer.println("> toFlowable();"); writer.println(); }
Example #3
Source File: ApiTypeInfo.java From vertx-codegen with Apache License 2.0 | 5 votes |
public ApiTypeInfo( String fqcn, boolean concrete, List<TypeParamInfo.Class> params, TypeInfo handlerArg, ModuleInfo module, boolean nullable, boolean proxyGen, DataObjectInfo dataObject) { super(ClassKind.API, fqcn, module, nullable, params, dataObject); this.concrete = concrete; this.proxyGen = proxyGen; this.handlerArg = handlerArg; }
Example #4
Source File: ClassTypeInfo.java From vertx-codegen with Apache License 2.0 | 5 votes |
public ClassTypeInfo(ClassKind kind, String name, ModuleInfo module, boolean nullable, List<TypeParamInfo.Class> params, DataObjectInfo dataObject) { this.kind = kind; this.name = name; this.simpleName = Helper.getSimpleName(name); this.packageName = Helper.getPackageName(name); this.module = module; this.nullable = nullable; this.params = params; this.dataObject = dataObject; }
Example #5
Source File: TypeInfoTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testApi() throws Exception { doTest(ApiHolder.class, map -> { ApiTypeInfo api = assertApi(map.get("api"), ApiObject.class.getName()); assertEquals(ApiObject.class.getName(), api.getName()); ParameterizedTypeInfo apiParameterizedByClass = assertParameterized(map.get("apiParameterizedByClass"), GenericInterface.class.getName() + "<java.lang.String>", ClassKind.API); assertClass(apiParameterizedByClass.getArg(0), "java.lang.String", ClassKind.STRING); ParameterizedTypeInfo apiParameterizedByClassTypeParam = assertParameterized(map.get("apiParameterizedByClassTypeParam"), GenericInterface.class.getName() + "<ClassTypeParam>", ClassKind.API); TypeParamInfo.Class classTypeParam = (TypeParamInfo.Class) assertTypeVariable(apiParameterizedByClassTypeParam.getArg(0), "ClassTypeParam").getParam(); assertEquals("ClassTypeParam", classTypeParam.getName()); ParameterizedTypeInfo apiParameterizedByMethodTypeParam = assertParameterized(map.get("apiParameterizedByMethodTypeParam"), GenericInterface.class.getName() + "<MethodTypeParam>", ClassKind.API); TypeParamInfo.Method methodTypeParam = (TypeParamInfo.Method) assertTypeVariable(apiParameterizedByMethodTypeParam.getArg(0), "MethodTypeParam").getParam(); assertEquals("MethodTypeParam", methodTypeParam.getName()); }); }
Example #6
Source File: TypeInfoTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testTypeParam() throws Exception { doTest(TypeParamHolder.class, map -> { TypeParamInfo.Class classTypeParam = (TypeParamInfo.Class) assertTypeVariable(map.get("classTypeParam"), "ClassTypeParam").getParam(); assertEquals("ClassTypeParam", classTypeParam.getName()); TypeParamInfo.Method methodTypeParam = (TypeParamInfo.Method) assertTypeVariable(map.get("methodTypeParam"), "MethodTypeParam").getParam(); assertEquals("MethodTypeParam", methodTypeParam.getName()); }); }
Example #7
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 #8
Source File: RxJavaGenerator.java From vertx-rx with Apache License 2.0 | 4 votes |
protected void genReadStream(List<? extends TypeParamInfo> typeParams, PrintWriter writer) { writer.print(" rx.Observable<"); writer.print(typeParams.get(0).getName()); writer.println("> toObservable();"); writer.println(); }
Example #9
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 #10
Source File: TypeReflectionFactory.java From vertx-codegen with Apache License 2.0 | 4 votes |
public static TypeInfo create(Type type) { if (type == void.class) { return VoidTypeInfo.INSTANCE; } else if (type instanceof Class) { String fqcn = type.getTypeName(); Class<?> classType = (Class<?>) type; if (classType.isPrimitive()) { return PrimitiveTypeInfo.PRIMITIVES.get(classType.getName()); } else { Package pkg = classType.getPackage(); ModuleInfo module = null; ClassLoader loader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classType.getClassLoader()); try { while (pkg != null) { ModuleGen annotation = pkg.getAnnotation(ModuleGen.class); if (annotation != null) { module = new ModuleInfo(pkg.getName(), annotation.name(), annotation.groupPackage()); break; } else { int pos = pkg.getName().lastIndexOf('.'); if (pos == -1) { break; } else { pkg = Package.getPackage(pkg.getName().substring(0, pos)); } } } } finally { Thread.currentThread().setContextClassLoader(loader); } if (classType.isEnum()) { return new EnumTypeInfo( fqcn, classType.getDeclaredAnnotation(VertxGen.class) != null, Stream.of(classType.getEnumConstants()).map(Object::toString).collect(Collectors.toList()), module, false ); } else { ClassKind kind = ClassKind.getKind(fqcn, classType.getAnnotation(VertxGen.class) != null); List<TypeParamInfo.Class> typeParams = new ArrayList<>(); int index = 0; for (java.lang.reflect.TypeVariable<? extends Class<?>> var : classType.getTypeParameters()) { typeParams.add(new TypeParamInfo.Class(classType.getName(), index++, var.getName())); } if (kind == ClassKind.API) { java.lang.reflect.TypeVariable<Class<Handler>> classTypeVariable = Handler.class.getTypeParameters()[0]; Type handlerArg = Helper.resolveTypeParameter(type, classTypeVariable); return new ApiTypeInfo(fqcn, true, typeParams, handlerArg != null ? create(handlerArg) : null, module, false, false, null); } else { boolean serializable = isDataObjectAnnotatedSerializable(classType); boolean deserializable = isDataObjectAnnotatedDeserializable(classType); MapperInfo serializer = null; if (serializable) { serializer = new MapperInfo(); serializer.setQualifiedName(fqcn); serializer.setKind(MapperKind.SELF); } MapperInfo deserializer = null; if (deserializable) { deserializer = new MapperInfo(); deserializer.setQualifiedName(fqcn); deserializer.setKind(MapperKind.SELF); } DataObjectInfo dataObject = null; if (serializable || serializable) { dataObject = new DataObjectInfo(serializer, deserializer); } return new ClassTypeInfo(kind, fqcn, module, false, typeParams, dataObject); } } } } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; List<TypeInfo> args = Arrays.asList(parameterizedType.getActualTypeArguments()). stream(). map(TypeReflectionFactory::create). collect(Collectors.toList()); Type raw = parameterizedType.getRawType(); return new ParameterizedTypeInfo((ClassTypeInfo) create(raw), false, args); } else if (type instanceof java.lang.reflect.TypeVariable) { java.lang.reflect.TypeVariable typeVar = (java.lang.reflect.TypeVariable) type; TypeParamInfo param = TypeParamInfo.create(typeVar); return new TypeVariableInfo(param, false, ((java.lang.reflect.TypeVariable) type).getName()); } else { throw new IllegalArgumentException("Unsupported type " + type); } }
Example #11
Source File: TypeVariableInfo.java From vertx-codegen with Apache License 2.0 | 4 votes |
public TypeVariableInfo(TypeParamInfo param, boolean nullable, String name) { this.param = param; this.nullable = nullable; this.name = name; }
Example #12
Source File: TypeVariableInfo.java From vertx-codegen with Apache License 2.0 | 4 votes |
public TypeParamInfo getParam() { return param; }
Example #13
Source File: ClassTypeInfo.java From vertx-codegen with Apache License 2.0 | 4 votes |
public List<TypeParamInfo.Class> getParams() { return params; }
Example #14
Source File: TypeInfoTest.java From vertx-codegen with Apache License 2.0 | 4 votes |
@Test public void testCollection() throws Exception { doTest(CollectionHolder.class, map -> { String[] colTypes = { "list", "set", "map" }; ClassKind[] colKinds = { ClassKind.LIST, ClassKind.SET, ClassKind.MAP }; List<List<String>> colTypeParams = Arrays.asList( Collections.singletonList("E"), Collections.singletonList("E"), Arrays.asList("K", "V")); int[] typeParamIndexes = {0, 0, 1}; for (int idx = 0;idx < colKinds.length;idx++) { String colType = colTypes[idx]; ClassKind colKind = colKinds[idx]; ClassTypeInfo col = (ClassTypeInfo) map.get(colType); int typeParamIndex = typeParamIndexes[idx]; assertEquals(colKind, col.getKind()); assertEquals(ClassTypeInfo.class, col.getClass()); assertEquals(colTypeParams.get(idx), col.getParams().stream().map(TypeParamInfo::getName).collect(Collectors.toList())); ParameterizedTypeInfo ofString = (ParameterizedTypeInfo) map.get(colType + "OfString"); assertEquals(colKind, ofString.getKind()); assertEquals(ParameterizedTypeInfo.class, ofString.getClass()); assertEquals(col, ofString.getRaw()); assertEquals(map.get("String"), ofString.getArg(typeParamIndex)); ParameterizedTypeInfo ofClassTypeParam = (ParameterizedTypeInfo) map.get(colType + "OfClassTypeParam"); assertEquals(colKind, ofClassTypeParam.getKind()); assertEquals(ParameterizedTypeInfo.class, ofClassTypeParam.getClass()); assertEquals(col, ofClassTypeParam.getRaw()); assertEquals(map.get("ClassTypeParam"), ofClassTypeParam.getArg(typeParamIndex)); ParameterizedTypeInfo ofMethodTypeParam = (ParameterizedTypeInfo) map.get(colType + "OfMethodTypeParam"); assertEquals(colKind, ofMethodTypeParam.getKind()); assertEquals(ParameterizedTypeInfo.class, ofMethodTypeParam.getClass()); assertEquals(col, ofMethodTypeParam.getRaw()); assertEquals(1 + typeParamIndex, ofMethodTypeParam.getArgs().size()); TypeParamInfo.Method methodTypeParam = (TypeParamInfo.Method) ((TypeVariableInfo) ofMethodTypeParam.getArg(typeParamIndex)).getParam(); assertEquals("MethodTypeParam", methodTypeParam.getName()); ParameterizedTypeInfo ofDataObject = (ParameterizedTypeInfo) map.get(colType + "OfDataObject"); assertEquals(colKind, ofDataObject.getKind()); assertEquals(ParameterizedTypeInfo.class, ofDataObject.getClass()); assertEquals(map.get("DataObject"), ofDataObject.getArg(typeParamIndex)); ParameterizedTypeInfo ofJsonObject = (ParameterizedTypeInfo) map.get(colType + "OfJsonObject"); assertEquals(colKind, ofJsonObject.getKind()); assertEquals(ParameterizedTypeInfo.class, ofJsonObject.getClass()); assertEquals(map.get("JsonObject"), ofJsonObject.getArg(typeParamIndex)); ParameterizedTypeInfo ofJsonArray = (ParameterizedTypeInfo) map.get(colType + "OfJsonArray"); assertEquals(colKind, ofJsonArray.getKind()); assertEquals(ParameterizedTypeInfo.class, ofJsonArray.getClass()); assertEquals(map.get("JsonArray"), ofJsonArray.getArg(typeParamIndex)); ParameterizedTypeInfo ofEnum = (ParameterizedTypeInfo) map.get(colType + "OfEnum"); assertEquals(colKind, ofEnum.getKind()); assertEquals(ParameterizedTypeInfo.class, ofEnum.getClass()); assertEquals(map.get("Enum"), ofEnum.getArg(typeParamIndex)); } }); }