Search in sources :

Example 1 with Description

use of co.cask.cdap.api.annotation.Description in project cdap by caskdata.

the class ArtifactInspector method createPluginProperty.

/**
 * 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();
    Macro macroAnnotation = field.getAnnotation(Macro.class);
    boolean macroSupported = macroAnnotation != null;
    if (rawType.isPrimitive()) {
        return new PluginPropertyField(name, description, rawType.getName(), true, macroSupported);
    }
    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, macroSupported);
}
Also used : Description(co.cask.cdap.api.annotation.Description) Macro(co.cask.cdap.api.annotation.Macro) UnsupportedTypeException(co.cask.cdap.api.data.schema.UnsupportedTypeException) PluginPropertyField(co.cask.cdap.api.plugin.PluginPropertyField) Annotation(java.lang.annotation.Annotation) Name(co.cask.cdap.api.annotation.Name)

Aggregations

Description (co.cask.cdap.api.annotation.Description)1 Macro (co.cask.cdap.api.annotation.Macro)1 Name (co.cask.cdap.api.annotation.Name)1 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)1 PluginPropertyField (co.cask.cdap.api.plugin.PluginPropertyField)1 Annotation (java.lang.annotation.Annotation)1