Search in sources :

Example 1 with ContainerElementTypeDescriptor

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;
}
Also used : ContainerElementTypeDescriptor(jakarta.validation.metadata.ContainerElementTypeDescriptor) ContainerElementTypeDescriptorImpl(org.hibernate.validator.internal.metadata.descriptor.ContainerElementTypeDescriptorImpl) TypeVariable(java.lang.reflect.TypeVariable) HashSet(java.util.HashSet) CollectionHelper.newHashSet(org.hibernate.validator.internal.util.CollectionHelper.newHashSet)

Example 2 with ContainerElementTypeDescriptor

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[]
}
Also used : ContainerElementTypeDescriptor(jakarta.validation.metadata.ContainerElementTypeDescriptor) PropertyDescriptor(jakarta.validation.metadata.PropertyDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) Test(org.junit.Test)

Example 3 with ContainerElementTypeDescriptor

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;
}
Also used : ContainerElementTypeDescriptor(jakarta.validation.metadata.ContainerElementTypeDescriptor) AnnotatedType(java.lang.reflect.AnnotatedType) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Aggregations

ContainerElementTypeDescriptor (jakarta.validation.metadata.ContainerElementTypeDescriptor)3 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)2 HashSet (java.util.HashSet)2 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)1 PropertyDescriptor (jakarta.validation.metadata.PropertyDescriptor)1 Annotation (java.lang.annotation.Annotation)1 AnnotatedType (java.lang.reflect.AnnotatedType)1 TypeVariable (java.lang.reflect.TypeVariable)1 ContainerElementTypeDescriptorImpl (org.hibernate.validator.internal.metadata.descriptor.ContainerElementTypeDescriptorImpl)1 CollectionHelper.newHashSet (org.hibernate.validator.internal.util.CollectionHelper.newHashSet)1 Test (org.junit.Test)1