Java Code Examples for io.vertx.codegen.type.ClassKind#STRING

The following examples show how to use io.vertx.codegen.type.ClassKind#STRING . 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: Helper.java    From vertx-codegen with Apache License 2.0 6 votes vote down vote up
public static ClassKind getAnnotatedDataObjectDeserialisationType(Elements elementUtils, Types typeUtils, TypeElement dataObjectElt) {
  if (isConcreteClass(dataObjectElt)) {
    Set<String> types = elementUtils
      .getAllMembers(dataObjectElt)
      .stream()
      .filter(e -> e.getKind() == ElementKind.CONSTRUCTOR)
      .map(e -> (ExecutableElement) e)
      .filter(constructor ->
        constructor.getParameters().size() == 1 &&
          constructor.getModifiers().contains(Modifier.PUBLIC) &&
          dataObjectTypes.contains(constructor.getParameters().get(0).asType().toString()))
      .map(ctor -> ctor.getParameters().get(0).asType().toString())
      .collect(Collectors.toSet());
    // Order matter
    if (types.contains("io.vertx.core.json.JsonObject")) {
      return ClassKind.JSON_OBJECT;
    } else if (types.contains("java.lang.String")) {
      return ClassKind.STRING;
    }
  }
  return null;
}
 
Example 2
Source File: TypeValidator.java    From vertx-codegen with Apache License 2.0 5 votes vote down vote up
private static boolean isValidContainer(TypeInfo type, boolean allowAnyJavaType) {
  TypeInfo argument = null;
  if (rawTypeIs(type, List.class, Set.class, Map.class)) {
    ParameterizedTypeInfo parameterizedType = (ParameterizedTypeInfo) type;
    if (type.getKind() != ClassKind.MAP) {
      argument = parameterizedType.getArgs().get(0);
    } else if (parameterizedType.getArgs().get(0).getKind() == ClassKind.STRING) { // Only allow Map's with String's for keys
      argument= parameterizedType.getArgs().get(1);
    }
  }
  return argument != null && isValidContainerComponent(argument, allowAnyJavaType);
}
 
Example 3
Source File: ModuleModel.java    From vertx-codegen with Apache License 2.0 5 votes vote down vote up
private static boolean isLegalJsonType(TypeMirror type) {
  ClassKind kind = ClassKind.getKind(type.toString(), type.getAnnotation(VertxGen.class) != null);
  return kind.json ||
    type.toString().equals("java.lang.Boolean") ||
    type.toString().equals("java.lang.Number") ||
    kind == ClassKind.STRING;
}
 
Example 4
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;
  }