Ejemplo n.º 1
0
 private boolean isPrimitiveWrapper(TypeMirror type) {
   Types types = context.getEnvironment().getTypeUtils();
   for (TypeKind kind : TypeKind.values()) {
     if (!kind.isPrimitive()) {
       continue;
     }
     if (ElementUtils.typeEquals(type, types.boxedClass(types.getPrimitiveType(kind)).asType())) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 2
0
  /**
   * Returns the Type that represents the declared Class type of the given type. For primitive
   * types, the boxed class will be used. Examples:
   *
   * <ul>
   *   <li>If type represents {@code java.lang.Integer}, it will return the type that represents
   *       {@code Class<Integer>}.
   *   <li>If type represents {@code int}, it will return the type that represents {@code
   *       Class<Integer>}.
   * </ul>
   *
   * @param type the type to return the declared class type for
   * @return the type representing {@code Class<type>}.
   */
  public Type classTypeOf(Type type) {
    TypeMirror typeToUse;
    if (type.isVoid()) {
      return null;
    } else if (type.isPrimitive()) {
      typeToUse = typeUtils.boxedClass((PrimitiveType) type.getTypeMirror()).asType();
    } else {
      typeToUse = type.getTypeMirror();
    }

    return getType(
        typeUtils.getDeclaredType(elementUtils.getTypeElement("java.lang.Class"), typeToUse));
  }