io.vertx.codegen.type.ClassTypeInfo Java Examples
The following examples show how to use
io.vertx.codegen.type.ClassTypeInfo.
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: GeneratorUtils.java From vertx-service-proxy with Apache License 2.0 | 6 votes |
public static String generateSerializeDataObject(String stmt, ClassTypeInfo doTypeInfo) { MapperInfo serializer = doTypeInfo.getDataObject().getSerializer(); StringBuilder sb = new StringBuilder(); serializer.getSelectors().forEach(selector -> { sb.append('.').append(selector); }); String s; switch (serializer.getKind()) { case SELF: s = stmt + sb + "()"; break; case STATIC_METHOD: s = serializer.getQualifiedName() + sb + "(" + stmt + ")"; break; default: throw new AssertionError(); } return String.format("%s != null ? %s : null", stmt, s); }
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: GeneratorUtils.java From vertx-service-proxy with Apache License 2.0 | 6 votes |
public static String generateDeserializeDataObject(String stmt, ClassTypeInfo doTypeInfo) { MapperInfo deserializer = doTypeInfo.getDataObject().getDeserializer(); String s; switch (deserializer.getKind()) { case SELF: s = String.format("new %s((%s)%s)", doTypeInfo.getName(), doTypeInfo.getDataObject().getJsonType().getSimpleName(), stmt); break; case STATIC_METHOD: StringBuilder sb = new StringBuilder(deserializer.getQualifiedName()); deserializer.getSelectors().forEach(selector -> { sb.append('.').append(selector); }); sb.append("((").append(deserializer.getJsonType().getSimpleName()).append(')').append(stmt).append(')'); s = sb.toString(); break; default: throw new AssertionError(); } return String.format("%s != null ? %s : null", stmt, s); }
Example #4
Source File: DataObjectHelperGen.java From vertx-codegen with Apache License 2.0 | 6 votes |
private Case getCase(DataObjectModel model) { AnnotationValueInfo abc = model .getAnnotations() .stream().filter(ann -> ann.getName().equals(DataObject.class.getName())) .findFirst().get(); ClassTypeInfo cti = (ClassTypeInfo) abc.getMember("jsonPropertyNameFormatter"); switch (cti.getName()) { case "io.vertx.codegen.format.CamelCase": return CamelCase.INSTANCE; case "io.vertx.codegen.format.SnakeCase": return SnakeCase.INSTANCE; case "io.vertx.codegen.format.LowerCamelCase": return LowerCamelCase.INSTANCE; default: throw new UnsupportedOperationException("Todo"); } }
Example #5
Source File: MethodInfo.java From vertx-codegen with Apache License 2.0 | 6 votes |
public MethodInfo(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 deprecated, Text deprecatedDesc) { this.comment = comment; this.name = name; this.returnType = returnType; this.returnDescription = returnDescription; this.fluent = fluent; this.cacheReturn = cacheReturn; this.doc = doc; this.staticMethod = staticMethod; this.defaultMethod = defaultMethod; this.params = params; this.typeParams = typeParams; this.ownerTypes = ownerTypes; this.deprecated = deprecated; this.deprecatedDesc = deprecatedDesc; }
Example #6
Source File: KotlinCodeWriter.java From vertx-codetrans with Apache License 2.0 | 6 votes |
@Override public void renderJavaType(ClassTypeInfo javaType) { switch (javaType.getKind()) { case STRING: append("String"); break; case VOID: append("Unit"); break; case BOXED_PRIMITIVE: renderBasicType(javaType); break; default: append(javaType.getName()); } }
Example #7
Source File: KotlinCodeBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
private void addImport(ClassTypeInfo importedType) { String fqn = importedType.getName(); /* if (importedType instanceof ApiTypeInfo) { fqn = importedType.translateName("kotlin"); } */ imports.add(fqn); }
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: GeneratorUtils.java From vertx-service-proxy with Apache License 2.0 | 5 votes |
public Stream<String> additionalImports(ProxyModel model) { return Stream .concat( model.getImportedTypes().stream(), model.getReferencedDataObjectTypes() .stream() .filter(t -> t.isDataObjectHolder() && t.getDataObject().getJsonType() instanceof ClassTypeInfo) .map(t -> (ClassTypeInfo) t.getDataObject().getJsonType()) ) .filter(c -> !c.getPackageName().equals("java.lang") && !c.getPackageName().equals("io.vertx.core.json")) .map(ClassTypeInfo::toString) .distinct(); }
Example #10
Source File: MapperGenBase.java From vertx-sql-client with Apache License 2.0 | 5 votes |
private Case getCase(DataObjectModel model, String name) { AnnotationValueInfo abc = getAnnotation(model).get(); ClassTypeInfo cti = (ClassTypeInfo) abc.getMember(name); switch (cti.getName()) { case "io.vertx.codegen.format.CamelCase": return CamelCase.INSTANCE; case "io.vertx.codegen.format.SnakeCase": return SnakeCase.INSTANCE; case "io.vertx.codegen.format.LowerCamelCase": return LowerCamelCase.INSTANCE; default: throw new UnsupportedOperationException(); } }
Example #11
Source File: KotlinCodeBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
private void renderType(TypeInfo type, KotlinCodeWriter renderer) { if (type instanceof ApiTypeInfo) { renderer.renderApiType((ApiTypeInfo) type); } else if (type instanceof ClassTypeInfo) { renderer.renderJavaType((ClassTypeInfo) type); } else if (type instanceof PrimitiveTypeInfo) { renderer.renderBasicType(type); } else { renderer.append(type.getName()); } }
Example #12
Source File: KotlinCodeWriter.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public void renderToDataObject(JsonObjectModel model, ClassTypeInfo type) { append(type.getSimpleName()); append("("); model.render(this); append(")"); }
Example #13
Source File: RowMapperGen.java From vertx-sql-client with Apache License 2.0 | 5 votes |
private static Function<String, String> getter_(TypeInfo type, boolean isArray) { String getter = getter(type); if (getter != null) { return col -> "row." + getter + (isArray ? "Array" : "") + "(\"" + col + "\")"; } if (type.getKind() == ClassKind.ENUM || type instanceof ClassTypeInfo) { if (isArray) { return col -> "row.get(" + type.getName() + "[].class, \"" + col + "\")"; } else { return col -> "row.get(" + type.getName() + ".class, \"" + col + "\")"; } } return null; }
Example #14
Source File: GroovyCodeBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public String render(RunnableCompilationUnit unit, RenderMode renderMode) { GroovyWriter writer = newWriter(); if (renderMode != RenderMode.SNIPPET) { if (unit.getFields().size() > 0) { writer.append("import groovy.transform.Field\n"); } for (ClassTypeInfo importedType : imports) { String fqn = importedType.getName(); writer.append("import ").append(fqn).append('\n'); } for (Map.Entry<String, StatementModel> field : unit.getFields().entrySet()) { writer.append("@Field "); field.getValue().render(writer); writer.append("\n"); } for (Map.Entry<String, MethodModel> method : unit.getMethods().entrySet()) { writer.append("def ").append(method.getKey()).append("("); for (Iterator<String> it = method.getValue().getParameterNames().iterator(); it.hasNext(); ) { String paramName = it.next(); writer.append(paramName); if (it.hasNext()) { writer.append(", "); } } writer.append(") {\n"); writer.indent(); method.getValue().render(writer); writer.unindent(); writer.append("}\n"); } } unit.getMain().render(writer); return writer.getBuffer().toString(); }
Example #15
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 #16
Source File: WebApiProxyModel.java From vertx-web with Apache License 2.0 | 5 votes |
@Override protected MethodInfo createMethodInfo(Set<ClassTypeInfo> ownerTypes, String methodName, String comment, Doc doc, TypeInfo returnType, Text returnDescription, boolean isFluent, boolean isCacheReturn, List<ParamInfo> mParams, ExecutableElement methodElt, boolean isStatic, boolean isDefault, ArrayList<TypeParamInfo.Method> typeParams, TypeElement declaringElt, boolean methodDeprecated, Text deprecatedDesc) { ProxyMethodInfo baseInfo = (ProxyMethodInfo) super.createMethodInfo(ownerTypes, methodName, comment, doc, returnType, returnDescription, isFluent, isCacheReturn, mParams, methodElt, isStatic, isDefault, typeParams, declaringElt, methodDeprecated, deprecatedDesc); if (!isStatic && !baseInfo.isProxyClose()) { // Check signature constraints TypeInfo ret; if (baseInfo.getKind() == MethodKind.FUTURE) { ret = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) mParams.get(mParams.size() - 1).getType()).getArg(0)).getArg(0); } else { throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR); } if (!ServiceResponse.class.getName().equals(ret.getName())) { throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR); } TypeInfo shouldBeServiceRequest; if (baseInfo.getKind() == MethodKind.FUTURE) { if (mParams.size() <= 1) { throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR); } shouldBeServiceRequest = mParams.get(mParams.size() - 2).getType(); } else { if (mParams.size() == 0) { throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR); } shouldBeServiceRequest = mParams.get(mParams.size() - 1).getType(); } if (!ServiceRequest.class.getName().equals(shouldBeServiceRequest.getName())) { throw new GenException(methodElt, SIGNATURE_CONSTRAINT_ERROR); } return new WebApiProxyMethodInfo(baseInfo); } else { return baseInfo; } }
Example #17
Source File: DataObjectClassModel.java From vertx-codetrans with Apache License 2.0 | 4 votes |
public DataObjectClassModel(CodeBuilder builder, ClassTypeInfo type) { super(builder); this.type = type; }
Example #18
Source File: RowMapperGen.java From vertx-sql-client with Apache License 2.0 | 4 votes |
private static String getter(TypeInfo type) { switch (type.getKind()) { case PRIMITIVE: PrimitiveTypeInfo pt = (PrimitiveTypeInfo) type; return getter(pt.getBoxed()); case BOXED_PRIMITIVE: return "get" + type.getSimpleName(); case STRING: return "getString"; case JSON_OBJECT: return "getJsonObject"; case JSON_ARRAY: return "getJsonArray"; } if (type instanceof ClassTypeInfo) { DataObjectInfo dataObject = type.getDataObject(); if (dataObject != null) { return getter(dataObject.getJsonType()); } ClassTypeInfo ct = (ClassTypeInfo) type; switch (ct.getName()) { case "java.time.LocalDateTime": return "getLocalDateTime"; case "java.time.LocalDate": return "getLocalDate"; case "java.time.LocalTime": return "getLocalTime"; case "java.time.OffsetTime": return "getOffsetTime"; case "java.time.OffsetDateTime": return "getOffsetDateTime"; case "java.time.temporal.Temporal": return "getTemporal"; case "java.util.UUID": return "getUUID"; case "io.vertx.core.buffer.Buffer": return "getBuffer"; } } return null; }
Example #19
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 #20
Source File: MethodInfo.java From vertx-codegen with Apache License 2.0 | 4 votes |
public void collectImports(Collection<ClassTypeInfo> imports) { params.stream().map(ParamInfo::getType).forEach(a -> a.collectImports(imports)); }
Example #21
Source File: MethodInfo.java From vertx-codegen with Apache License 2.0 | 4 votes |
public MethodInfo setOwnerTypes(Set<ClassTypeInfo> ownerTypes) { this.ownerTypes = ownerTypes; return this; }
Example #22
Source File: MethodInfo.java From vertx-codegen with Apache License 2.0 | 4 votes |
public Set<ClassTypeInfo> getOwnerTypes() { return ownerTypes; }
Example #23
Source File: CodeBuilder.java From vertx-codetrans with Apache License 2.0 | 4 votes |
default DataObjectClassModel dataObjectClass(ClassTypeInfo type) { return new DataObjectClassModel(this, type); }
Example #24
Source File: GroovyWriter.java From vertx-codetrans with Apache License 2.0 | 4 votes |
@Override public void renderToDataObject(JsonObjectModel model, ClassTypeInfo type) { model.render(this); }
Example #25
Source File: JavaClassModel.java From vertx-codetrans with Apache License 2.0 | 4 votes |
public JavaClassModel(CodeBuilder builder, ClassTypeInfo type) { super(builder); this.type = type; }
Example #26
Source File: ThrowableClassModel.java From vertx-codetrans with Apache License 2.0 | 4 votes |
public ThrowableClassModel(CodeBuilder builder, ClassTypeInfo type) { super(builder); this.type = type; }
Example #27
Source File: DataObjectLiteralModel.java From vertx-codetrans with Apache License 2.0 | 4 votes |
public ClassTypeInfo getType() { return type; }
Example #28
Source File: DataObjectLiteralModel.java From vertx-codetrans with Apache License 2.0 | 4 votes |
public DataObjectLiteralModel(CodeBuilder builder, ClassTypeInfo type, Map<String, Member> members) { super(builder); this.type = type; this.members = members; }
Example #29
Source File: DataObjectLiteralModel.java From vertx-codetrans with Apache License 2.0 | 4 votes |
public DataObjectLiteralModel(CodeBuilder builder, ClassTypeInfo type) { this(builder, type, Collections.emptyMap()); }
Example #30
Source File: KotlinCodeBuilder.java From vertx-codetrans with Apache License 2.0 | 4 votes |
@Override public DataObjectClassModel dataObjectClass(ClassTypeInfo type) { addImport(type); imports.add(type.translatePackageName("kotlin") + ".*"); return CodeBuilder.super.dataObjectClass(type); }