private A rewriteConstraint()

in bval-jsr/src/main/java/org/apache/bval/jsr/descriptor/MetadataReader.java [110:132]


        private <A extends Annotation> A rewriteConstraint(A constraint, Class<?> declaredBy) {
            boolean mustRewrite = false;
            Class<?>[] groups =
                ConstraintAnnotationAttributes.GROUPS.analyze(constraint.annotationType()).read(constraint);
            if (groups.length == 0) {
                mustRewrite = true;
                groups = GroupsComputer.DEFAULT_GROUP;
            }
            if (!(declaredBy.equals(beanClass) || beanClass.isInterface())) {
                if (ObjectUtils.arrayContains(groups, Default.class)
                    && !ObjectUtils.arrayContains(groups, declaredBy)) {
                    mustRewrite = true;
                    groups = ObjectUtils.arrayAdd(groups, declaredBy);
                }
            }
            if (mustRewrite) {
                final AnnotationProxyBuilder<A> builder =
                    validatorFactory.getAnnotationsManager().buildProxyFor(constraint);
                builder.setGroups(groups);
                return builder.createAnnotation();
            }
            return constraint;
        }