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();
}
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));
}
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;
}
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;
}
Aggregations