Fix ErrorMessage annotation and ClassValidator never being present on Parameter
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-12-18 21:36:46 +01:00
Ursprung 19e4949048
Commit 2e9e4e2e49
2 geänderte Dateien mit 4 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -135,14 +135,6 @@ public class SWCommandUtils {
public static <T> AbstractValidator<T, ?> getValidator(Parameter parameter, Map<String, AbstractValidator<T, ?>> localValidator) { public static <T> AbstractValidator<T, ?> getValidator(Parameter parameter, Map<String, AbstractValidator<T, ?>> localValidator) {
Class<?> clazz = parameter.getType(); Class<?> clazz = parameter.getType();
AbstractSWCommand.ClassValidator classValidator = parameter.getAnnotation(AbstractSWCommand.ClassValidator.class);
if (classValidator != null) {
if (classValidator.value() != null) {
return getValidator(classValidator.value().getTypeName(), localValidator);
}
return getValidator(clazz.getTypeName(), localValidator);
}
AbstractSWCommand.Validator validator = parameter.getAnnotation(AbstractSWCommand.Validator.class); AbstractSWCommand.Validator validator = parameter.getAnnotation(AbstractSWCommand.Validator.class);
if (validator != null) { if (validator != null) {
if (validator.value() != null && !validator.value().isEmpty()) { if (validator.value() != null && !validator.value().isEmpty()) {
@ -150,7 +142,10 @@ public class SWCommandUtils {
} }
return getValidator(clazz.getTypeName(), localValidator); return getValidator(clazz.getTypeName(), localValidator);
} }
return null;
}
public static <T> AbstractValidator<T, ?> getErrorMessage(Parameter parameter) {
AbstractSWCommand.ErrorMessage errorMessage = parameter.getAnnotation(AbstractSWCommand.ErrorMessage.class); AbstractSWCommand.ErrorMessage errorMessage = parameter.getAnnotation(AbstractSWCommand.ErrorMessage.class);
if (errorMessage != null) { if (errorMessage != null) {
return (AbstractValidator<T, Object>) (sender, value, messageSender) -> { return (AbstractValidator<T, Object>) (sender, value, messageSender) -> {

Datei anzeigen

@ -155,6 +155,7 @@ public class SubCommand<T> {
commandPart.addValidator((AbstractValidator<T, Object>) STRING_SPACE_FILTER); commandPart.addValidator((AbstractValidator<T, Object>) STRING_SPACE_FILTER);
} }
commandPart.addValidator(validator); commandPart.addValidator(validator);
commandPart.addValidator((AbstractValidator<T, Object>) SWCommandUtils.getErrorMessage(parameter));
if (min != null) { if (min != null) {
commandPart.addValidator((AbstractValidator<T, Object>) createMinValidator(varArgType != null ? varArgType : parameter.getType(), min)); commandPart.addValidator((AbstractValidator<T, Object>) createMinValidator(varArgType != null ? varArgType : parameter.getType(), min));
} }