2
2
3
3
import static io .avaje .validation .generator .APContext .typeElement ;
4
4
import static io .avaje .validation .generator .PrimitiveUtil .isPrimitiveValidationAnnotations ;
5
- import static java .util .function .Predicate .not ;
6
5
import static java .util .stream .Collectors .toMap ;
7
6
8
7
import java .util .HashMap ;
@@ -25,7 +24,7 @@ public record ElementAnnotationContainer(
25
24
Map <UType , String > typeUse2 ,
26
25
Map <UType , String > crossParam ) {
27
26
28
- static ElementAnnotationContainer create (Element element , boolean classLevel ) {
27
+ static ElementAnnotationContainer create (Element element ) {
29
28
final var hasValid = ValidPrism .isPresent (element );
30
29
31
30
Map <UType , String > typeUse1 ;
@@ -35,23 +34,14 @@ static ElementAnnotationContainer create(Element element, boolean classLevel) {
35
34
if (element instanceof final ExecutableElement executableElement ) {
36
35
uType = UType .parse (executableElement .getReturnType ());
37
36
38
- Optional .ofNullable (uType .param0 ()).map (UType ::annotations ).stream ()
39
- .flatMap (List ::stream )
40
- .filter (m -> !ValidPrism .isInstance (m ))
41
- .filter (m -> !classLevel || hasMetaConstraintAnnotation (m ))
42
- .collect (
43
- toMap (
44
- a -> UType .parse (a .getAnnotationType ()),
45
- a -> AnnotationUtil .annotationAttributeMap (a , element )));
46
-
47
37
} else {
48
38
uType = UType .parse (element .asType ());
49
39
}
50
40
51
41
typeUse1 =
52
42
Optional .ofNullable (uType .param0 ()).map (UType ::annotations ).stream ()
53
43
.flatMap (List ::stream )
54
- .filter (m -> ! classLevel || hasMetaConstraintAnnotation ( m ) )
44
+ .filter (ElementAnnotationContainer :: hasMetaConstraintAnnotation )
55
45
.collect (
56
46
toMap (
57
47
a -> UType .parse (a .getAnnotationType ()),
@@ -60,7 +50,7 @@ static ElementAnnotationContainer create(Element element, boolean classLevel) {
60
50
typeUse2 =
61
51
Optional .ofNullable (uType .param1 ()).map (UType ::annotations ).stream ()
62
52
.flatMap (List ::stream )
63
- .filter (m -> ! classLevel || hasMetaConstraintAnnotation ( m ) )
53
+ .filter (ElementAnnotationContainer :: hasMetaConstraintAnnotation )
64
54
.collect (
65
55
toMap (
66
56
a -> UType .parse (a .getAnnotationType ()),
@@ -69,7 +59,7 @@ static ElementAnnotationContainer create(Element element, boolean classLevel) {
69
59
final var annotations =
70
60
element .getAnnotationMirrors ().stream ()
71
61
.filter (m -> !ValidPrism .isInstance (m ))
72
- .filter (m -> ! classLevel || hasMetaConstraintAnnotation ( m ) )
62
+ .filter (ElementAnnotationContainer :: hasMetaConstraintAnnotation )
73
63
.map (
74
64
a -> {
75
65
if (CrossParamConstraintPrism .isPresent (a .getAnnotationType ().asElement ())) {
@@ -91,7 +81,8 @@ static ElementAnnotationContainer create(Element element, boolean classLevel) {
91
81
}
92
82
93
83
static boolean hasMetaConstraintAnnotation (AnnotationMirror m ) {
94
- return hasMetaConstraintAnnotation (m .getAnnotationType ().asElement ());
84
+ return hasMetaConstraintAnnotation (m .getAnnotationType ().asElement ())
85
+ || ValidPrism .isInstance (m );
95
86
}
96
87
97
88
static boolean hasMetaConstraintAnnotation (Element element ) {
@@ -106,13 +97,15 @@ static ElementAnnotationContainer create(VariableElement varElement) {
106
97
final var annotations =
107
98
uType .annotations ().stream ()
108
99
.filter (m -> !ValidPrism .isInstance (m ))
100
+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
109
101
.collect (
110
102
toMap (
111
103
a -> UType .parse (a .getAnnotationType ()),
112
104
a -> AnnotationUtil .annotationAttributeMap (a , varElement )));
113
105
var typeUse1 =
114
106
Optional .ofNullable (uType .param0 ()).map (UType ::annotations ).stream ()
115
107
.flatMap (List ::stream )
108
+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
116
109
.collect (
117
110
toMap (
118
111
a -> UType .parse (a .getAnnotationType ()),
@@ -121,6 +114,7 @@ static ElementAnnotationContainer create(VariableElement varElement) {
121
114
var typeUse2 =
122
115
Optional .ofNullable (uType .param1 ()).map (UType ::annotations ).stream ()
123
116
.flatMap (List ::stream )
117
+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
124
118
.collect (
125
119
toMap (
126
120
a -> UType .parse (a .getAnnotationType ()),
0 commit comments