Java Code Examples for io.vertx.codegen.TypeParamInfo#Class

The following examples show how to use io.vertx.codegen.TypeParamInfo#Class . 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: ApiTypeInfo.java    From vertx-codegen with Apache License 2.0 5 votes vote down vote up
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 2
Source File: ClassTypeInfo.java    From vertx-codegen with Apache License 2.0 5 votes vote down vote up
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 3
Source File: TypeReflectionFactory.java    From vertx-codegen with Apache License 2.0 4 votes vote down vote up
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 4
Source File: ClassTypeInfo.java    From vertx-codegen with Apache License 2.0 4 votes vote down vote up
public List<TypeParamInfo.Class> getParams() {
  return params;
}