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