use of org.apache.ignite.configuration.validation.Validator in project ignite-3 by apache.
the class ValidationUtil method assertValidatorTypesCoherence.
private static boolean assertValidatorTypesCoherence(Class<?> validatorClass, Class<? extends Annotation> annotationType, Object val) {
// Find superclass that directly extends Validator.
if (!Arrays.asList(validatorClass.getInterfaces()).contains(Validator.class)) {
return assertValidatorTypesCoherence(validatorClass.getSuperclass(), annotationType, val);
}
Type genericSuperClass = Arrays.stream(validatorClass.getGenericInterfaces()).filter(i -> i instanceof ParameterizedType && ((ParameterizedType) i).getRawType() == Validator.class).findAny().get();
if (!(genericSuperClass instanceof ParameterizedType)) {
return false;
}
ParameterizedType parameterizedSuperClass = (ParameterizedType) genericSuperClass;
Type[] actualTypeParameters = parameterizedSuperClass.getActualTypeArguments();
if (actualTypeParameters.length != 2) {
return false;
}
if (actualTypeParameters[0] != annotationType) {
return false;
}
Type sndParam = actualTypeParameters[1];
if (sndParam instanceof ParameterizedType) {
sndParam = ((ParameterizedType) sndParam).getRawType();
}
return (sndParam instanceof Class) && (val == null || ((Class<?>) sndParam).isInstance(val));
}
Aggregations