Search in sources :

Example 6 with ResolvedType

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

the class ConstructorParameterModelProperty method getModelProperties.

/**
 * Creates a collection of ConstructorParameterModelProperty objects from the arguments of the given ResolvedConstructor.
 * Only args annotated with @JsonProperty are included. Scala Case Classes are a special case and do not require the annotation.
 *
 * @param resolvedConstructor the constructor to get
 * @param alternateTypeProvider for resolving alternative types for the found arguments
 * @return the collection of ConstructorParameterModelProperty objects
 */
public static ImmutableList<ConstructorParameterModelProperty> getModelProperties(ResolvedConstructor resolvedConstructor, AlternateTypeProvider alternateTypeProvider) {
    Builder<ConstructorParameterModelProperty> listBuilder = new Builder<>();
    if (resolvedConstructor.getRawMember().getAnnotation(JsonCreator.class) != null || scala.Product.class.isAssignableFrom(resolvedConstructor.getDeclaringType().getErasedType())) {
        // constructor for normal classes must be annotated with @JsonCreator. Scala Case Classes are a special case
        for (int i = 0; i < resolvedConstructor.getArgumentCount(); i++) {
            AnnotationMap annotationMap = annotationMap(resolvedConstructor.getRawMember().getParameterAnnotations()[i]);
            ResolvedType parameterType = resolvedConstructor.getArgumentType(i);
            if (annotationMap.get(JsonProperty.class) != null) {
                listBuilder.add(new ConstructorParameterModelProperty(parameterType, alternateTypeProvider, annotationMap));
            }
        }
    }
    return listBuilder.build();
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) AnnotationMap(com.fasterxml.jackson.databind.introspect.AnnotationMap) Builder(com.google.common.collect.ImmutableList.Builder) ResolvedType(com.fasterxml.classmate.ResolvedType)

Example 7 with ResolvedType

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

the class AttributeConverterDescriptorImpl method create.

public static AttributeConverterDescriptor create(AttributeConverterDefinition definition, ClassmateContext classmateContext) {
    final AttributeConverter converter = definition.getAttributeConverter();
    final Class converterClass = converter.getClass();
    final ResolvedType converterType = classmateContext.getTypeResolver().resolve(converterClass);
    final List<ResolvedType> converterParamTypes = converterType.typeParametersFor(AttributeConverter.class);
    if (converterParamTypes == null) {
        throw new AnnotationException("Could not extract type parameter information from AttributeConverter implementation [" + converterClass.getName() + "]");
    } else if (converterParamTypes.size() != 2) {
        throw new AnnotationException("Unexpected type parameter information for AttributeConverter implementation [" + converterClass.getName() + "]; expected 2 parameter types, but found " + converterParamTypes.size());
    }
    return new AttributeConverterDescriptorImpl(converter, definition.isAutoApply(), converterParamTypes.get(0), converterParamTypes.get(1));
}
Also used : AttributeConverter(javax.persistence.AttributeConverter) AnnotationException(org.hibernate.AnnotationException) ResolvedType(com.fasterxml.classmate.ResolvedType)

Example 8 with ResolvedType

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

the class AutoApplicableConverterDescriptorStandardImpl method getAutoAppliedConverterDescriptorForCollectionElement.

@Override
public ConverterDescriptor getAutoAppliedConverterDescriptorForCollectionElement(XProperty xProperty, MetadataBuildingContext context) {
    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(linkedConverterDescriptor.getDomainValueResolvedType(), elementType) ? linkedConverterDescriptor : null;
}
Also used : ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) HibernateException(org.hibernate.HibernateException) Collection(java.util.Collection) ResolvedType(com.fasterxml.classmate.ResolvedType)

Example 9 with ResolvedType

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

the class AutoApplicableConverterDescriptorStandardImpl method getAutoAppliedConverterDescriptorForMapKey.

@Override
public ConverterDescriptor getAutoAppliedConverterDescriptorForMapKey(XProperty xProperty, MetadataBuildingContext context) {
    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(linkedConverterDescriptor.getDomainValueResolvedType(), keyType) ? linkedConverterDescriptor : null;
}
Also used : ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) HibernateException(org.hibernate.HibernateException) ResolvedType(com.fasterxml.classmate.ResolvedType)

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