Search in sources :

Example 1 with Description

use of io.cdap.cdap.api.annotation.Description in project cdap by caskdata.

the class DefaultArtifactInspector method createPluginProperties.

/**
 * Creates a collection of {@link PluginPropertyField} based on the given field.
 */
private Collection<PluginPropertyField> createPluginProperties(Field field, TypeToken<?> resolvingType, boolean inspectNested) 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 Collections.singleton(new PluginPropertyField(name, description, rawType.getName(), true, macroSupported));
    }
    rawType = Primitives.unwrap(rawType);
    boolean required = true;
    for (Annotation annotation : field.getAnnotations()) {
        if (annotation.annotationType().getName().endsWith(".Nullable")) {
            required = false;
            break;
        }
    }
    Map<String, PluginPropertyField> properties = new HashMap<>();
    if (PluginConfig.class.isAssignableFrom(rawType)) {
        if (!inspectNested) {
            throw new IllegalArgumentException("Plugin config with name " + name + " is a subclass of PluginGroupConfig and can " + "only be defined within PluginConfig.");
        }
        // don't inspect if the field is already nested
        inspectConfigField(fieldType, properties, false);
    }
    PluginPropertyField curField = new PluginPropertyField(name, description, rawType.getSimpleName().toLowerCase(), required, macroSupported, false, new HashSet<>(properties.keySet()));
    properties.put(name, curField);
    return properties.values();
}
Also used : Description(io.cdap.cdap.api.annotation.Description) HashMap(java.util.HashMap) Macro(io.cdap.cdap.api.annotation.Macro) PluginPropertyField(io.cdap.cdap.api.plugin.PluginPropertyField) Annotation(java.lang.annotation.Annotation) Name(io.cdap.cdap.api.annotation.Name)

Aggregations

Description (io.cdap.cdap.api.annotation.Description)1 Macro (io.cdap.cdap.api.annotation.Macro)1 Name (io.cdap.cdap.api.annotation.Name)1 PluginPropertyField (io.cdap.cdap.api.plugin.PluginPropertyField)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1