Search in sources :

Example 1 with ResolvedTypeWithMembers

use of com.fasterxml.classmate.ResolvedTypeWithMembers in project hibernate-orm by hibernate.

the class AttributeConverterDescriptorImpl method resolveMember.

private ResolvedMember resolveMember(XProperty xProperty, MetadataBuildingContext buildingContext) {
    final ClassmateContext classmateContext = buildingContext.getMetadataCollector().getClassmateContext();
    final ReflectionManager reflectionManager = buildingContext.getBuildingOptions().getReflectionManager();
    final ResolvedType declaringClassType = classmateContext.getTypeResolver().resolve(reflectionManager.toClass(xProperty.getDeclaringClass()));
    final ResolvedTypeWithMembers declaringClassWithMembers = classmateContext.getMemberResolver().resolve(declaringClassType, null, null);
    final Member member = toMember(xProperty);
    if (member instanceof Method) {
        for (ResolvedMethod resolvedMember : declaringClassWithMembers.getMemberMethods()) {
            if (resolvedMember.getName().equals(member.getName())) {
                return resolvedMember;
            }
        }
    } else if (member instanceof Field) {
        for (ResolvedField resolvedMember : declaringClassWithMembers.getMemberFields()) {
            if (resolvedMember.getName().equals(member.getName())) {
                return resolvedMember;
            }
        }
    } else {
        throw new HibernateException("Unexpected java.lang.reflect.Member type from org.hibernate.annotations.common.reflection.java.JavaXMember : " + member);
    }
    throw new HibernateException("Could not locate resolved type information for attribute [" + member.getName() + "] from Classmate");
}
Also used : Field(java.lang.reflect.Field) ResolvedField(com.fasterxml.classmate.members.ResolvedField) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) ResolvedField(com.fasterxml.classmate.members.ResolvedField) ReflectionManager(org.hibernate.annotations.common.reflection.ReflectionManager) HibernateException(org.hibernate.HibernateException) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) Method(java.lang.reflect.Method) Member(java.lang.reflect.Member) ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) ResolvedType(com.fasterxml.classmate.ResolvedType) ResolvedTypeWithMembers(com.fasterxml.classmate.ResolvedTypeWithMembers)

Example 2 with ResolvedTypeWithMembers

use of com.fasterxml.classmate.ResolvedTypeWithMembers in project hibernate-orm by hibernate.

the class AutoApplicableConverterDescriptorStandardImpl method resolveMember.

private ResolvedMember resolveMember(XProperty xProperty, MetadataBuildingContext buildingContext) {
    final ClassmateContext classmateContext = buildingContext.getBootstrapContext().getClassmateContext();
    final ReflectionManager reflectionManager = buildingContext.getBootstrapContext().getReflectionManager();
    final ResolvedType declaringClassType = classmateContext.getTypeResolver().resolve(reflectionManager.toClass(xProperty.getDeclaringClass()));
    final ResolvedTypeWithMembers declaringClassWithMembers = classmateContext.getMemberResolver().resolve(declaringClassType, null, null);
    final Member member = toMember(xProperty);
    if (member instanceof Method) {
        for (ResolvedMethod resolvedMember : declaringClassWithMembers.getMemberMethods()) {
            if (resolvedMember.getName().equals(member.getName())) {
                return resolvedMember;
            }
        }
    } else if (member instanceof Field) {
        for (ResolvedField resolvedMember : declaringClassWithMembers.getMemberFields()) {
            if (resolvedMember.getName().equals(member.getName())) {
                return resolvedMember;
            }
        }
    } else {
        throw new HibernateException("Unexpected java.lang.reflect.Member type from org.hibernate.annotations.common.reflection.java.JavaXMember : " + member);
    }
    throw new HibernateException("Could not locate resolved type information for attribute [" + member.getName() + "] from Classmate");
}
Also used : Field(java.lang.reflect.Field) ResolvedField(com.fasterxml.classmate.members.ResolvedField) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) ResolvedField(com.fasterxml.classmate.members.ResolvedField) ReflectionManager(org.hibernate.annotations.common.reflection.ReflectionManager) HibernateException(org.hibernate.HibernateException) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) Method(java.lang.reflect.Method) Member(java.lang.reflect.Member) ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) ResolvedType(com.fasterxml.classmate.ResolvedType) ClassmateContext(org.hibernate.boot.internal.ClassmateContext) ResolvedTypeWithMembers(com.fasterxml.classmate.ResolvedTypeWithMembers)

Example 3 with ResolvedTypeWithMembers

use of com.fasterxml.classmate.ResolvedTypeWithMembers 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 4 with ResolvedTypeWithMembers

use of com.fasterxml.classmate.ResolvedTypeWithMembers in project chassis by Kixeye.

the class CustomAccessorsProvider method constructorsIn.

/**
 * Finds the constructors in the given type
 *
 * @param resolvedType the type to search
 */
public com.google.common.collect.ImmutableList<ResolvedConstructor> constructorsIn(ResolvedType resolvedType) {
    MemberResolver resolver = new MemberResolver(typeResolver);
    resolver.setIncludeLangObject(false);
    if (resolvedType.getErasedType() == Object.class) {
        return ImmutableList.of();
    }
    ResolvedTypeWithMembers typeWithMembers = resolver.resolve(resolvedType, null, null);
    return FluentIterable.from(newArrayList(typeWithMembers.getConstructors())).toList();
}
Also used : MemberResolver(com.fasterxml.classmate.MemberResolver) ResolvedTypeWithMembers(com.fasterxml.classmate.ResolvedTypeWithMembers)

Example 5 with ResolvedTypeWithMembers

use of com.fasterxml.classmate.ResolvedTypeWithMembers 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

ResolvedTypeWithMembers (com.fasterxml.classmate.ResolvedTypeWithMembers)5 ResolvedMethod (com.fasterxml.classmate.members.ResolvedMethod)4 MemberResolver (com.fasterxml.classmate.MemberResolver)3 Method (java.lang.reflect.Method)3 AnnotationConfiguration (com.fasterxml.classmate.AnnotationConfiguration)2 ResolvedType (com.fasterxml.classmate.ResolvedType)2 TypeResolver (com.fasterxml.classmate.TypeResolver)2 ResolvedField (com.fasterxml.classmate.members.ResolvedField)2 ResolvedMember (com.fasterxml.classmate.members.ResolvedMember)2 Field (java.lang.reflect.Field)2 Member (java.lang.reflect.Member)2 HibernateException (org.hibernate.HibernateException)2 ReflectionManager (org.hibernate.annotations.common.reflection.ReflectionManager)2 AnnotationInclusion (com.fasterxml.classmate.AnnotationInclusion)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