Search in sources :

Example 1 with AnnotationConfiguration

use of com.fasterxml.classmate.AnnotationConfiguration in project dropwizard by dropwizard.

the class SelfValidatingValidatorTest method getMethod.

private ResolvedMethod getMethod(String name, Class<?>... params) {
    AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration.StdConfiguration(AnnotationInclusion.INCLUDE_AND_INHERIT_IF_INHERITED);
    TypeResolver typeResolver = new TypeResolver();
    MemberResolver memberResolver = new MemberResolver(typeResolver);
    ResolvedTypeWithMembers annotatedType = memberResolver.resolve(typeResolver.resolve(InvalidExample.class), annotationConfiguration, null);
    for (ResolvedMethod m : annotatedType.getMemberMethods()) {
        if (hasSignature(m, name, params)) {
            return m;
        }
    }
    throw new IllegalStateException("Could not resolve method " + name + Arrays.toString(params) + " in " + InvalidExample.class);
}
Also used : ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) TypeResolver(com.fasterxml.classmate.TypeResolver) AnnotationConfiguration(com.fasterxml.classmate.AnnotationConfiguration) MemberResolver(com.fasterxml.classmate.MemberResolver) ResolvedTypeWithMembers(com.fasterxml.classmate.ResolvedTypeWithMembers)

Example 2 with AnnotationConfiguration

use of com.fasterxml.classmate.AnnotationConfiguration in project dropwizard by dropwizard.

the class SelfValidatingValidator method findMethods.

/**
 * This method generates <code>ValidationCaller</code>s for each method annotated
 * with <code>@SelfValidation</code> that adheres to required signature.
 */
@SuppressWarnings({ "rawtypes" })
private <T> List<ValidationCaller> findMethods(Class<T> annotated) {
    ResolvedTypeWithMembers annotatedType = memberResolver.resolve(typeResolver.resolve(annotated), annotationConfiguration, null);
    final List<ValidationCaller> callers = Arrays.stream(annotatedType.getMemberMethods()).filter(this::isValidationMethod).filter(this::isMethodCorrect).map(m -> new ProxyValidationCaller<>(annotated, m)).collect(Collectors.toList());
    if (callers.isEmpty()) {
        log.warn("The class {} is annotated with @SelfValidating but contains no valid methods that are annotated " + "with @SelfValidation", annotated);
    }
    return callers;
}
Also used : MemberResolver(com.fasterxml.classmate.MemberResolver) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) ConstraintValidator(javax.validation.ConstraintValidator) ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) AnnotationConfiguration(com.fasterxml.classmate.AnnotationConfiguration) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TypeResolver(com.fasterxml.classmate.TypeResolver) ResolvedTypeWithMembers(com.fasterxml.classmate.ResolvedTypeWithMembers) Collectors(java.util.stream.Collectors) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) ConcurrentMap(java.util.concurrent.ConcurrentMap) AnnotationInclusion(com.fasterxml.classmate.AnnotationInclusion) List(java.util.List) Method(java.lang.reflect.Method) ResolvedTypeWithMembers(com.fasterxml.classmate.ResolvedTypeWithMembers)

Aggregations

AnnotationConfiguration (com.fasterxml.classmate.AnnotationConfiguration)2 MemberResolver (com.fasterxml.classmate.MemberResolver)2 ResolvedTypeWithMembers (com.fasterxml.classmate.ResolvedTypeWithMembers)2 TypeResolver (com.fasterxml.classmate.TypeResolver)2 ResolvedMethod (com.fasterxml.classmate.members.ResolvedMethod)2 AnnotationInclusion (com.fasterxml.classmate.AnnotationInclusion)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Collectors (java.util.stream.Collectors)1 ConstraintValidator (javax.validation.ConstraintValidator)1 ConstraintValidatorContext (javax.validation.ConstraintValidatorContext)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1