Search in sources :

Example 6 with Validator

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));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Validator(org.apache.ignite.configuration.validation.Validator)

Aggregations

Validator (org.apache.ignite.configuration.validation.Validator)6 ValidationContext (org.apache.ignite.configuration.validation.ValidationContext)5 ValidationIssue (org.apache.ignite.configuration.validation.ValidationIssue)5 Set (java.util.Set)4 Test (org.junit.jupiter.api.Test)4 Annotation (java.lang.annotation.Annotation)3 SuperRoot (org.apache.ignite.internal.configuration.SuperRoot)3 NamedListView (org.apache.ignite.configuration.NamedListView)2 ConfigValue (org.apache.ignite.configuration.annotation.ConfigValue)2 Value (org.apache.ignite.configuration.annotation.Value)2 TestConfigurationStorage (org.apache.ignite.internal.configuration.storage.TestConfigurationStorage)2 Serializable (java.io.Serializable)1 FIELD (java.lang.annotation.ElementType.FIELD)1 Retention (java.lang.annotation.Retention)1 RUNTIME (java.lang.annotation.RetentionPolicy.RUNTIME)1 Target (java.lang.annotation.Target)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Arrays (java.util.Arrays)1 List (java.util.List)1