コード例 #1
0
  protected String getClassType(Method method, List<Class<?>> alsoRead) {
    Field field = getFieldForMethod(method);
    if (field == null) {
      return "n/a";
    }

    if (List.class.isAssignableFrom(field.getType())) {
      Type generic = field.getGenericType();
      if (listWithSingleGenericType(generic)) {
        Type genericType = ((ParameterizedType) generic).getActualTypeArguments()[0];

        // if the generic type is not specified, we'll just return "list of T"
        if (!(genericType instanceof Class<?>)) {
          return "List of T";
        } else {
          Class genericClass = (Class) genericType;
          if (!skipForInspection(genericClass)) {
            alsoRead.add(genericClass);
          }
          return "List of ".concat(genericClass.getSimpleName());
        }
      } else {
        return "List";
      }
    } else {

      if (!skipForInspection(method.getReturnType())) {
        alsoRead.add(method.getReturnType());
      }

      return method.getReturnType().getSimpleName();
    }
  }
コード例 #2
0
 /**
  * Is this a simple type?
  *
  * @param type
  * @return
  */
 protected boolean skipForInspection(Class<?> type) {
   return type.isEnum()
       || type.isArray()
       || type.isPrimitive()
       || type == Integer.class
       || type == Double.class
       || type == Byte.class
       || type == Boolean.class
       || (String.class.isAssignableFrom(type))
       || type == Long.class
       || type == Map.class
       || type == Object.class;
 }
コード例 #3
0
  /**
   * Extract enumeration constraints
   *
   * @param method is the method to have a look at
   * @return a constraints string
   */
  protected String getConstraints(Method method) {
    Class<?> returnType = method.getReturnType();

    if (returnType.isEnum()) {
      return getEnumerationConstants(returnType);
    }

    Field field = this.getFieldForMethod(method);
    if (field != null && field.getDeclaredAnnotations().length > 0) {
      return getFieldAnnotationConstraints(field);
    }

    return null;
  }
コード例 #4
0
  /**
   * Extract the enumeration constants
   *
   * @param enumeration is the enumeration
   * @return is the string with constants
   */
  protected String getEnumerationConstants(Class<?> enumeration) {
    Object[] constants = enumeration.getEnumConstants();

    int idx = 0;
    StringBuffer strBuff = new StringBuffer();
    for (Object konst : constants) {
      strBuff.append(konst.toString());

      if (idx < constants.length - 1) {
        strBuff.append(", ");
      }

      ++idx;
    }

    return strBuff.toString();
  }