Java Code Examples for io.vertx.codegen.type.TypeInfo#getSimpleName()

The following examples show how to use io.vertx.codegen.type.TypeInfo#getSimpleName() . 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: RxJava2Generator.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
private void genToXXXEr(TypeInfo streamType, String rxType, String rxName, PrintWriter writer) {
  writer.format("  public synchronized WriteStream%s<%s> to%s() {%n", rxType, genTranslatedTypeName(streamType), rxType);

  writer.format("    if (%s == null) {%n", rxName);

  if (streamType.getKind() == ClassKind.API) {
    writer.format("      Function<%s, %s> conv = %s::getDelegate;%n", genTranslatedTypeName(streamType.getRaw()), streamType.getName(), genTranslatedTypeName(streamType));

    writer.format("      %s = RxHelper.to%s(getDelegate(), conv);%n", rxName, rxType);
  } else if (streamType.isVariable()) {
    String typeVar = streamType.getSimpleName();
    writer.format("      Function<%s, %s> conv = (Function<%s, %s>) __typeArg_0.unwrap;%n", typeVar, typeVar, typeVar, typeVar);

    writer.format("      %s = RxHelper.to%s(getDelegate(), conv);%n", rxName, rxType);
  } else {
    writer.format("      %s = RxHelper.to%s(getDelegate());%n", rxName, rxType);
  }

  writer.println("    }");
  writer.format("    return %s;%n", rxName);
  writer.println("  }");
  writer.println();
}
 
Example 2
Source File: RxJavaGenerator.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected void genToSubscriber(TypeInfo streamType, PrintWriter writer) {
  writer.format("  private WriteStreamSubscriber<%s> subscriber;%n", genTranslatedTypeName(streamType));
  writer.println();

  writer.format("  public synchronized WriteStreamSubscriber<%s> toSubscriber() {%n", genTranslatedTypeName(streamType));

  writer.println("    if (subscriber == null) {");

  if (streamType.getKind() == ClassKind.API) {
    writer.format("      Function<%s, %s> conv = %s::getDelegate;%n", genTranslatedTypeName(streamType.getRaw()), streamType.getName(), genTranslatedTypeName(streamType));

    writer.println("      subscriber = RxHelper.toSubscriber(getDelegate(), conv);");
  } else if (streamType.isVariable()) {
    String typeVar = streamType.getSimpleName();
    writer.format("      Function<%s, %s> conv = (Function<%s, %s>) __typeArg_0.unwrap;%n", typeVar, typeVar, typeVar, typeVar);

    writer.println("      subscriber = RxHelper.toSubscriber(getDelegate(), conv);");
  } else {
    writer.println("      subscriber = RxHelper.toSubscriber(getDelegate());");
  }

  writer.println("    }");
  writer.println("    return subscriber;");
  writer.println("  }");
  writer.println();
}
 
Example 3
Source File: RowMapperGen.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
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 4
Source File: RxJavaGenerator.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
@Override
protected void genToObservable(TypeInfo streamType, PrintWriter writer) {
  writer.print("  private Observable<");
  writer.print(genTranslatedTypeName(streamType));
  writer.println("> observable;");
  writer.println();

  writer.print("  public synchronized Observable<");
  writer.print(genTranslatedTypeName(streamType));
  writer.println("> toObservable() {");

  writer.print("    ");
  writer.println("if (observable == null) {");

  if (streamType.getKind() == ClassKind.API) {
    writer.print("      Function<");
    writer.print(streamType.getName());
    writer.print(", ");
    writer.print(genTranslatedTypeName(streamType));
    writer.print("> conv = ");
    writer.print(genTranslatedTypeName(streamType.getRaw()));
    writer.println("::newInstance;");

    writer.println("      observable = RxHelper.toObservable(delegate, conv);");
  } else if (streamType.isVariable()) {
    String typeVar = streamType.getSimpleName();
    writer.print("      Function<");
    writer.print(typeVar);
    writer.print(", ");
    writer.print(typeVar);
    writer.print("> conv = (Function<");
    writer.print(typeVar);
    writer.print(", ");
    writer.print(typeVar);
    writer.println(">) __typeArg_0.wrap;");

    writer.println("      observable = RxHelper.toObservable(delegate, conv);");
  } else {
    writer.println("      observable = RxHelper.toObservable(this.getDelegate());");
  }

  writer.println("    }");
  writer.println("    return observable;");
  writer.println("  }");
  writer.println();
}
 
Example 5
Source File: RxJava2Generator.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
private void genToXXXAble(TypeInfo streamType, String rxType, String rxName, PrintWriter writer) {
  writer.print("  public synchronized ");
  writer.print(rxType);
  writer.print("<");
  writer.print(genTranslatedTypeName(streamType));
  writer.print("> to");
  writer.print(rxType);
  writer.println("() {");

  writer.print("    ");
  writer.print("if (");
  writer.print(rxName);
  writer.println(" == null) {");

  if (streamType.getKind() == ClassKind.API) {
    writer.print("      Function<");
    writer.print(streamType.getName());
    writer.print(", ");
    writer.print(genTranslatedTypeName(streamType));
    writer.print("> conv = ");
    writer.print(genTranslatedTypeName(streamType.getRaw()));
    writer.println("::newInstance;");

    writer.print("      ");
    writer.print(rxName);
    writer.print(" = ");
    writer.print(rxType);
    writer.print("Helper.to");
    writer.print(rxType);
    writer.println("(delegate, conv);");
  } else if (streamType.isVariable()) {
    String typeVar = streamType.getSimpleName();
    writer.print("      Function<");
    writer.print(typeVar);
    writer.print(", ");
    writer.print(typeVar);
    writer.print("> conv = (Function<");
    writer.print(typeVar);
    writer.print(", ");
    writer.print(typeVar);
    writer.println(">) __typeArg_0.wrap;");

    writer.print("      ");
    writer.print(rxName);
    writer.print(" = ");
    writer.print(rxType);
    writer.print("Helper.to");
    writer.print(rxType);
    writer.println("(delegate, conv);");
  } else {
    writer.print("      ");
    writer.print(rxName);
    writer.print(" = ");
    writer.print(rxType);
    writer.print("Helper.to");
    writer.print(rxType);
    writer.println("(this.getDelegate());");
  }

  writer.println("    }");
  writer.print("    return ");
  writer.print(rxName);
  writer.println(";");
  writer.println("  }");
  writer.println();
}
 
Example 6
Source File: DataObjectCheatsheetGen.java    From vertx-codegen with Apache License 2.0 4 votes vote down vote up
private String getDataType(TypeInfo type) {
    ClassKind kind = type.getKind();
    if (kind.basic) {
      if (kind == ClassKind.STRING) {
        return "String";
      }
      String typeName = type.getName();
      switch (typeName) {
        case "java.lang.Boolean":
        case "boolean":
          return "Boolean";
        case "java.lang.Character":
        case "char":
          return "Char";
        case "java.lang.Byte":
        case "byte":
        case "java.lang.Short":
        case "short":
        case "java.lang.Integer":
        case "int":
        case "java.lang.Long":
        case "long":
        case "java.lang.Float":
        case "float":
        case "java.lang.Double":
        case "double":
          return "Number (" + type.getSimpleName() + ")";
      }
    } else {
      switch (kind) {
        case JSON_OBJECT:
          return "Json object";
        case JSON_ARRAY:
          return "Json array";
//        case DATA_OBJECT:
//          return "link:dataobjects.html#" + type.getRaw().getSimpleName() + '[' + type.getRaw().getSimpleName() + ']';
        case ENUM:
          return "link:enums.html#" + type.getRaw().getSimpleName() + '[' + type.getRaw().getSimpleName() + ']';
        case API:
          if (type.getName().equals("io.vertx.core.buffer.Buffer")) {
            return "Buffer";
          }
          break;
        case OTHER:
          if (type.getName().equals(Instant.class.getName())) {
            return "Instant";
          }
          break;
      }
    }
    System.out.println("unhandled type " + type);
    return null;
  }