Ejemplo n.º 1
0
  /** Creates a {@link PluginPropertyField} based on the given field. */
  private PluginPropertyField createPluginProperty(Field field, TypeToken<?> resolvingType)
      throws UnsupportedTypeException {
    TypeToken<?> fieldType = resolvingType.resolveType(field.getGenericType());
    Class<?> rawType = fieldType.getRawType();

    Name nameAnnotation = field.getAnnotation(Name.class);
    Description descAnnotation = field.getAnnotation(Description.class);
    String name = nameAnnotation == null ? field.getName() : nameAnnotation.value();
    String description = descAnnotation == null ? "" : descAnnotation.value();

    if (rawType.isPrimitive()) {
      return new PluginPropertyField(name, description, rawType.getName(), true);
    }

    rawType = Primitives.unwrap(rawType);
    if (!rawType.isPrimitive() && !String.class.equals(rawType)) {
      throw new UnsupportedTypeException("Only primitive and String types are supported");
    }

    boolean required = true;
    for (Annotation annotation : field.getAnnotations()) {
      if (annotation.annotationType().getName().endsWith(".Nullable")) {
        required = false;
        break;
      }
    }

    return new PluginPropertyField(
        name, description, rawType.getSimpleName().toLowerCase(), required);
  }
Ejemplo n.º 2
0
 /** Returns description for the plugin. */
 private String getPluginDescription(Class<?> cls) {
   Description annotation = cls.getAnnotation(Description.class);
   return annotation == null ? "" : annotation.value();
 }