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();
}
Aggregations