use of com.bladecoder.engine.actions.ActionPropertyDescription in project bladecoder-adventure-engine by bladecoder.
the class ActionUtils method getParams.
public static Param[] getParams(Action action) {
List<Param> params = new ArrayList<>();
Class<?> clazz = action.getClass();
while (clazz != null && clazz != Object.class) {
for (Field field : clazz.getDeclaredFields()) {
final ActionProperty property = field.getAnnotation(ActionProperty.class);
if (property == null) {
continue;
}
final ActionPropertyDescription propertyDescription = field.getAnnotation(ActionPropertyDescription.class);
// saved in the model.
if (propertyDescription == null)
continue;
final String name = field.getName();
Param.Type type = property.type();
Enum<?>[] options = null;
if (field.getType().isEnum()) {
final boolean accessible = field.isAccessible();
field.setAccessible(true);
options = (Enum[]) field.getType().getEnumConstants();
field.setAccessible(accessible);
type = Param.Type.OPTION;
} else if (property.type() == Param.Type.NOT_SET) {
type = getType(field);
}
params.add(new Param(name, propertyDescription != null ? propertyDescription.value() : "", type, property.required(), property.defaultValue(), options));
}
clazz = clazz.getSuperclass();
}
return params.toArray(new Param[params.size()]);
}
Aggregations