io.vertx.codegen.type.PrimitiveTypeInfo Java Examples

The following examples show how to use io.vertx.codegen.type.PrimitiveTypeInfo. 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: JsonMapperTest.java    From vertx-codegen with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidMethodOverload() throws Exception {
  ClassModel model = new GeneratorHelper()
    .registerConverter(ZonedDateTime.class, APIInterfaceWithZonedDateTime.class.getName(), "deserialize")
    .generateClass(io.vertx.test.codegen.testjsonmapper.interfacewithoverloads.APIInterfaceWithZonedDateTime.class);
  assertTrue(model.getSuperTypes().isEmpty());
  assertEquals(2, model.getMethods().size());

  MethodInfo method1 = model.getMethods().get(0);
  checkMethod(method1, "doSomething", 1, "void", MethodKind.OTHER);
  List<ParamInfo> params1 = method1.getParams();
  assertNotNull(params1.get(0).getType().getDataObject());
  assertEquals(ZonedDateTime.class.getName(), params1.get(0).getType().getName());

  MethodInfo method2 = model.getMethods().get(1);
  checkMethod(method2, "doSomething", 1, "void", MethodKind.OTHER);
  List<ParamInfo> params2 = method2.getParams();
  assertTrue(params2.get(0).getType() instanceof PrimitiveTypeInfo);
  assertEquals(long.class.getName(), params2.get(0).getType().getName());
}
 
Example #2
Source File: KotlinCodeBuilder.java    From vertx-codetrans with Apache License 2.0 5 votes vote down vote up
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 #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;
}