• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.86
today-context/src/main/java/infra/validation/annotation/ValidationAnnotationUtils.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.validation.annotation;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.lang.annotation.Annotation;
23

24
import infra.core.annotation.AnnotationUtils;
25

26
/**
27
 * Utility class for handling validation annotations.
28
 * Mainly for internal use within the framework.
29
 *
30
 * @author Christoph Dreis
31
 * @author Juergen Hoeller
32
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
33
 * @since 4.0
34
 */
35
public abstract class ValidationAnnotationUtils {
×
36

37
  private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
4✔
38

39
  /**
40
   * Determine any validation hints by the given annotation.
41
   * <p>This implementation checks for Infra
42
   * {@link Validated},
43
   * {@code @jakarta.validation.Valid}, and custom annotations whose
44
   * name starts with "Valid" which may optionally declare validation
45
   * hints through the "value" attribute.
46
   *
47
   * @param ann the annotation (potentially a validation annotation)
48
   * @return the validation hints to apply (possibly an empty array),
49
   * or {@code null} if this annotation does not trigger any validation
50
   */
51
  public static Object @Nullable [] determineValidationHints(Annotation ann) {
52
    // Direct presence of @Validated ?
53
    if (ann instanceof Validated validated) {
3!
54
      return validated.value();
×
55
    }
56
    // Direct presence of @Valid ?
57
    Class<? extends Annotation> annotationType = ann.annotationType();
3✔
58
    if ("jakarta.validation.Valid".equals(annotationType.getName())) {
5✔
59
      return EMPTY_OBJECT_ARRAY;
2✔
60
    }
61
    // Meta presence of @Validated ?
62
    Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
5✔
63
    if (validatedAnn != null) {
2!
64
      return validatedAnn.value();
×
65
    }
66
    // Custom validation annotation ?
67
    if (annotationType.getSimpleName().startsWith("Valid")) {
5✔
68
      return convertValidationHints(AnnotationUtils.getValue(ann));
4✔
69
    }
70
    // No validation triggered
71
    return null;
2✔
72
  }
73

74
  private static Object[] convertValidationHints(@Nullable Object hints) {
75
    if (hints == null) {
2!
76
      return EMPTY_OBJECT_ARRAY;
2✔
77
    }
78
    return (hints instanceof Object[] ? (Object[]) hints : new Object[] { hints });
×
79
  }
80

81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc