use of jakarta.validation.metadata.ContainerElementTypeDescriptor in project hibernate-validator by hibernate.
the class AbstractConstraintMetaData method asContainerElementTypeDescriptors.
private Set<ContainerElementTypeDescriptor> asContainerElementTypeDescriptors(Type type, ContainerElementMetaDataTree containerElementMetaDataTree, boolean defaultGroupSequenceRedefined, List<Class<?>> defaultGroupSequence) {
Set<ContainerElementTypeDescriptor> containerElementTypeDescriptors = new HashSet<>();
for (Entry<TypeVariable<?>, ContainerElementMetaDataTree> entry : containerElementMetaDataTree.nodes.entrySet()) {
TypeVariable<?> childTypeParameter = entry.getKey();
ContainerElementMetaDataTree childContainerElementMetaDataTree = entry.getValue();
Set<ContainerElementTypeDescriptor> childrenDescriptors = asContainerElementTypeDescriptors(childContainerElementMetaDataTree.elementType, childContainerElementMetaDataTree, defaultGroupSequenceRedefined, defaultGroupSequence);
containerElementTypeDescriptors.add(new ContainerElementTypeDescriptorImpl(childContainerElementMetaDataTree.elementType, childContainerElementMetaDataTree.containerClass, TypeVariables.getTypeParameterIndex(childTypeParameter), asDescriptors(childContainerElementMetaDataTree.constraints), childrenDescriptors, childContainerElementMetaDataTree.cascading, defaultGroupSequenceRedefined, defaultGroupSequence, childContainerElementMetaDataTree.groupConversionDescriptors));
}
return containerElementTypeDescriptors;
}
use of jakarta.validation.metadata.ContainerElementTypeDescriptor in project hibernate-validator by hibernate.
the class LibraryTest method testContainerElementTypeDescriptor.
@Test
public void testContainerElementTypeDescriptor() {
BeanDescriptor libraryDescriptor = validator.getConstraintsForClass(Library.class);
// tag::testContainerElementTypeDescriptor[]
PropertyDescriptor booksDescriptor = libraryDescriptor.getConstraintsForProperty("books");
Set<ContainerElementTypeDescriptor> booksContainerElementTypeDescriptors = booksDescriptor.getConstrainedContainerElementTypes();
ContainerElementTypeDescriptor booksContainerElementTypeDescriptor = booksContainerElementTypeDescriptors.iterator().next();
assertTrue(booksContainerElementTypeDescriptor.hasConstraints());
assertTrue(booksContainerElementTypeDescriptor.isCascaded());
assertEquals(0, booksContainerElementTypeDescriptor.getTypeArgumentIndex().intValue());
assertEquals(List.class, booksContainerElementTypeDescriptor.getContainerClass());
Set<ConstraintDescriptor<?>> constraintDescriptors = booksContainerElementTypeDescriptor.getConstraintDescriptors();
ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
assertEquals(NotNull.class, constraintDescriptor.getAnnotation().annotationType());
// end::testContainerElementTypeDescriptor[]
}
use of jakarta.validation.metadata.ContainerElementTypeDescriptor in project minijax by minijax.
the class MinijaxContainerElementTypeDescriptor method build.
public static Set<ContainerElementTypeDescriptor> build(final Class<?> elementClass, final AnnotatedParameterizedType annotatedType) {
final Set<ContainerElementTypeDescriptor> result = new HashSet<>();
final Class<?> containerClass = ReflectionUtils.getRawType(annotatedType);
int argIndex = 0;
for (final AnnotatedType typeArg : annotatedType.getAnnotatedActualTypeArguments()) {
final Set<ConstraintDescriptor<?>> constraintDescriptors = new HashSet<>();
for (final Annotation annotation : typeArg.getAnnotations()) {
final MinijaxConstraintDescriptor<?> constraintDescriptor = MinijaxConstraintDescriptor.build(typeArg, annotation);
if (constraintDescriptor != null) {
constraintDescriptors.add(constraintDescriptor);
}
}
if (!constraintDescriptors.isEmpty()) {
result.add(new MinijaxContainerElementTypeDescriptor(elementClass, containerClass, argIndex, constraintDescriptors));
}
argIndex++;
}
return result;
}
Aggregations