Dieser Commit ist enthalten in:
Ursprung
a8880e53db
Commit
d0150a2335
@ -236,22 +236,23 @@ public abstract class AbstractSWCommand<T> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Annotation> void addGuard(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, AbstractGuardChecker<?>> consumer) {
|
private <T extends Annotation> void addValidator(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, AbstractValidator<T, ?>> consumer) {
|
||||||
add(annotation, method, parameterTester, firstParameter, returnType, (anno, parameters) -> {
|
add(annotation, method, parameterTester, firstParameter, returnType, (anno, parameters) -> {
|
||||||
try {
|
try {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
consumer.accept(anno, (AbstractGuardChecker<T>) method.invoke(this));
|
consumer.accept(anno, (AbstractValidator<T, ?>) method.invoke(this));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SecurityException(e.getMessage(), e);
|
throw new SecurityException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Annotation> void addValidator(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, AbstractValidator<T, ?>> consumer) {
|
@Deprecated
|
||||||
|
private <T extends Annotation> void addGuard(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, AbstractGuardChecker<?>> consumer) {
|
||||||
add(annotation, method, parameterTester, firstParameter, returnType, (anno, parameters) -> {
|
add(annotation, method, parameterTester, firstParameter, returnType, (anno, parameters) -> {
|
||||||
try {
|
try {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
consumer.accept(anno, (AbstractValidator<T, ?>) method.invoke(this));
|
consumer.accept(anno, (AbstractGuardChecker<T>) method.invoke(this));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SecurityException(e.getMessage(), e);
|
throw new SecurityException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,7 @@ public class SWCommandUtils {
|
|||||||
return validator;
|
return validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static <T> AbstractGuardChecker<T> getGuardChecker(Parameter parameter, Map<String, AbstractGuardChecker<T>> localGuardChecker) {
|
public static <T> AbstractGuardChecker<T> getGuardChecker(Parameter parameter, Map<String, AbstractGuardChecker<T>> localGuardChecker) {
|
||||||
Class<?> clazz = parameter.getType();
|
Class<?> clazz = parameter.getType();
|
||||||
if (parameter.isVarArgs()) {
|
if (parameter.isVarArgs()) {
|
||||||
@ -231,6 +232,7 @@ public class SWCommandUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private static <T> AbstractGuardChecker<T> getGuardChecker(String s, Map<String, AbstractGuardChecker<T>> localGuardChecker) {
|
private static <T> AbstractGuardChecker<T> getGuardChecker(String s, Map<String, AbstractGuardChecker<T>> localGuardChecker) {
|
||||||
AbstractGuardChecker<T> guardChecker = localGuardChecker.getOrDefault(s, (AbstractGuardChecker<T>) GUARD_FUNCTIONS.getOrDefault(s, null));
|
AbstractGuardChecker<T> guardChecker = localGuardChecker.getOrDefault(s, (AbstractGuardChecker<T>) GUARD_FUNCTIONS.getOrDefault(s, null));
|
||||||
if (guardChecker == null) {
|
if (guardChecker == null) {
|
||||||
@ -247,10 +249,20 @@ public class SWCommandUtils {
|
|||||||
MAPPER_FUNCTIONS.putIfAbsent(name, mapper);
|
MAPPER_FUNCTIONS.putIfAbsent(name, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> void addValidator(Class<T> clazz, AbstractValidator<T, ?> validator) {
|
||||||
|
addValidator(clazz.getTypeName(), validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void addValidator(String name, AbstractValidator<T, ?> validator) {
|
||||||
|
VALIDATOR_FUNCTIONS.putIfAbsent(name, validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static <T> void addGuard(Class<?> clazz, AbstractGuardChecker<T> guardChecker) {
|
public static <T> void addGuard(Class<?> clazz, AbstractGuardChecker<T> guardChecker) {
|
||||||
addGuard(clazz.getTypeName(), guardChecker);
|
addGuard(clazz.getTypeName(), guardChecker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static <T> void addGuard(String name, AbstractGuardChecker<T> guardChecker) {
|
public static <T> void addGuard(String name, AbstractGuardChecker<T> guardChecker) {
|
||||||
GUARD_FUNCTIONS.putIfAbsent(name, guardChecker);
|
GUARD_FUNCTIONS.putIfAbsent(name, guardChecker);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren