Search in sources :

Example 1 with ResolvedType

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

the class AttributeConverterDescriptorImpl method shouldAutoApplyToCollectionElement.

@Override
public boolean shouldAutoApplyToCollectionElement(XProperty xProperty, MetadataBuildingContext context) {
    if (!autoApply) {
        return false;
    }
    final ResolvedMember collectionMember = resolveMember(xProperty, context);
    final ResolvedType elementType;
    if (Map.class.isAssignableFrom(collectionMember.getType().getErasedType())) {
        elementType = collectionMember.getType().typeParametersFor(Map.class).get(1);
    } else if (Collection.class.isAssignableFrom(collectionMember.getType().getErasedType())) {
        elementType = collectionMember.getType().typeParametersFor(Collection.class).get(0);
    } else {
        throw new HibernateException("Attribute was neither a Collection nor a Map : " + collectionMember.getType().getErasedType());
    }
    return typesMatch(domainType, elementType);
}
Also used : ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) HibernateException(org.hibernate.HibernateException) Collection(java.util.Collection) ResolvedType(com.fasterxml.classmate.ResolvedType)

Example 2 with ResolvedType

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

the class AttributeConverterDescriptorImpl method shouldAutoApplyToMapKey.

@Override
public boolean shouldAutoApplyToMapKey(XProperty xProperty, MetadataBuildingContext context) {
    if (!autoApply) {
        return false;
    }
    final ResolvedMember collectionMember = resolveMember(xProperty, context);
    final ResolvedType keyType;
    if (Map.class.isAssignableFrom(collectionMember.getType().getErasedType())) {
        keyType = collectionMember.getType().typeParametersFor(Map.class).get(0);
    } else {
        throw new HibernateException("Attribute was not a Map : " + collectionMember.getType().getErasedType());
    }
    return typesMatch(domainType, keyType);
}
Also used : ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) HibernateException(org.hibernate.HibernateException) ResolvedType(com.fasterxml.classmate.ResolvedType)

Example 3 with ResolvedType

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

use of com.fasterxml.classmate.ResolvedType 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 5 with ResolvedType

use of com.fasterxml.classmate.ResolvedType in project thingsboard by thingsboard.

the class SwaggerConfiguration method thingsboardApi.

@Bean
public Docket thingsboardApi() {
    TypeResolver typeResolver = new TypeResolver();
    final ResolvedType jsonNodeType = typeResolver.resolve(JsonNode.class);
    final ResolvedType stringType = typeResolver.resolve(String.class);
    return new Docket(DocumentationType.SWAGGER_2).groupName("thingsboard").apiInfo(apiInfo()).alternateTypeRules(new AlternateTypeRule(jsonNodeType, stringType)).select().paths(apiPaths()).build().securitySchemes(newArrayList(jwtTokenKey())).securityContexts(newArrayList(securityContext()));
}
Also used : TypeResolver(com.fasterxml.classmate.TypeResolver) Docket(springfox.documentation.spring.web.plugins.Docket) ResolvedType(com.fasterxml.classmate.ResolvedType) AlternateTypeRule(springfox.documentation.schema.AlternateTypeRule) Bean(org.springframework.context.annotation.Bean)

Aggregations

ResolvedType (com.fasterxml.classmate.ResolvedType)9 ResolvedMember (com.fasterxml.classmate.members.ResolvedMember)6 HibernateException (org.hibernate.HibernateException)6 ResolvedTypeWithMembers (com.fasterxml.classmate.ResolvedTypeWithMembers)2 ResolvedField (com.fasterxml.classmate.members.ResolvedField)2 ResolvedMethod (com.fasterxml.classmate.members.ResolvedMethod)2 Field (java.lang.reflect.Field)2 Member (java.lang.reflect.Member)2 Method (java.lang.reflect.Method)2 Collection (java.util.Collection)2 ReflectionManager (org.hibernate.annotations.common.reflection.ReflectionManager)2 TypeResolver (com.fasterxml.classmate.TypeResolver)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 AnnotationMap (com.fasterxml.jackson.databind.introspect.AnnotationMap)1 Builder (com.google.common.collect.ImmutableList.Builder)1 AttributeConverter (javax.persistence.AttributeConverter)1 AnnotationException (org.hibernate.AnnotationException)1 ClassmateContext (org.hibernate.boot.internal.ClassmateContext)1 Bean (org.springframework.context.annotation.Bean)1 AlternateTypeRule (springfox.documentation.schema.AlternateTypeRule)1