1616import javax .lang .model .element .ExecutableElement ;
1717import javax .lang .model .element .VariableElement ;
1818
19- public record ElementAnnotationContainer (
19+ record ElementAnnotationContainer (
2020 UType genericType ,
2121 boolean hasValid ,
2222 Map <UType , String > annotations ,
@@ -32,97 +32,94 @@ static ElementAnnotationContainer create(Element element) {
3232 UType uType ;
3333 if (element instanceof final ExecutableElement executableElement ) {
3434 uType = UType .parse (executableElement .getReturnType ());
35-
3635 } else {
3736 uType = UType .parse (element .asType ());
3837 }
3938
4039 typeUse1 =
41- Optional .ofNullable (uType .param0 ()).map (UType ::annotations ).stream ()
42- .flatMap (List ::stream )
43- .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
44- .collect (
45- toMap (
46- a -> UType .parse (a .getAnnotationType ()),
47- a -> AnnotationUtil .annotationAttributeMap (a , element )));
40+ Optional .ofNullable (uType .param0 ()).map (UType ::annotations ).stream ()
41+ .flatMap (List ::stream )
42+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
43+ .collect (
44+ toMap (
45+ a -> UType .parse (a .getAnnotationType ()),
46+ a -> AnnotationUtil .annotationAttributeMap (a , element )));
4847
4948 typeUse2 =
50- Optional .ofNullable (uType .param1 ()).map (UType ::annotations ).stream ()
51- .flatMap (List ::stream )
52- .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
53- .collect (
54- toMap (
55- a -> UType .parse (a .getAnnotationType ()),
56- a -> AnnotationUtil .annotationAttributeMap (a , element )));
49+ Optional .ofNullable (uType .param1 ()).map (UType ::annotations ).stream ()
50+ .flatMap (List ::stream )
51+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
52+ .collect (
53+ toMap (
54+ a -> UType .parse (a .getAnnotationType ()),
55+ a -> AnnotationUtil .annotationAttributeMap (a , element )));
5756
5857 final var annotations =
59- element .getAnnotationMirrors ().stream ()
60- .filter (m -> !ValidPrism .isInstance (m ))
61- .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
62- .map (
63- a -> {
64- if (CrossParamConstraintPrism .isPresent (a .getAnnotationType ().asElement ())) {
65- crossParam .put (
66- UType .parse (a .getAnnotationType ()),
67- AnnotationUtil .annotationAttributeMap (a , element ));
68- return null ;
69- }
70- return a ;
71- })
72- .filter (Objects ::nonNull )
73- .collect (
74- toMap (
75- a -> UType .parse (a .getAnnotationType ()),
76- a -> AnnotationUtil .annotationAttributeMap (a , element )));
58+ element .getAnnotationMirrors ().stream ()
59+ .filter (m -> !ValidPrism .isInstance (m ))
60+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
61+ .map (a -> {
62+ if (CrossParamConstraintPrism .isPresent (a .getAnnotationType ().asElement ())) {
63+ crossParam .put (
64+ UType .parse (a .getAnnotationType ()),
65+ AnnotationUtil .annotationAttributeMap (a , element ));
66+ return null ;
67+ }
68+ return a ;
69+ })
70+ .filter (Objects ::nonNull )
71+ .collect (
72+ toMap (
73+ a -> UType .parse (a .getAnnotationType ()),
74+ a -> AnnotationUtil .annotationAttributeMap (a , element )));
7775
7876 if (Util .isNonNullable (element )) {
7977 var nonNull = UType .parse (APContext .typeElement (NonNullPrism .PRISM_TYPE ).asType ());
8078 annotations .put (nonNull , "Map.of(\" message\" ,\" {avaje.NotNull.message}\" )" );
8179 }
8280
83- return new ElementAnnotationContainer (
84- uType , hasValid , annotations , typeUse1 , typeUse2 , crossParam );
81+ return new ElementAnnotationContainer (uType , hasValid , annotations , typeUse1 , typeUse2 , crossParam );
8582 }
8683
8784 static boolean hasMetaConstraintAnnotation (AnnotationMirror m ) {
8885 return hasMetaConstraintAnnotation (m .getAnnotationType ().asElement ())
89- || ValidPrism .isInstance (m );
86+ || ValidPrism .isInstance (m );
9087 }
9188
9289 static boolean hasMetaConstraintAnnotation (Element element ) {
9390 return ConstraintPrism .isPresent (element );
9491 }
9592
96- // it seems we cannot directly retrieve mirrors from var elements, so var Elements needs special
97- // handling
93+ // it seems we cannot directly retrieve mirrors from var elements, so var Elements needs special handling
9894
9995 static ElementAnnotationContainer create (VariableElement varElement ) {
10096 var uType = UType .parse (varElement .asType ());
10197 final var annotations =
102- uType .annotations ().stream ()
103- .filter (m -> !ValidPrism .isInstance (m ))
104- .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
105- .collect (
106- toMap (
107- a -> UType .parse (a .getAnnotationType ()),
108- a -> AnnotationUtil .annotationAttributeMap (a , varElement )));
98+ uType .annotations ().stream ()
99+ .filter (m -> !ValidPrism .isInstance (m ))
100+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
101+ .collect (
102+ toMap (
103+ a -> UType .parse (a .getAnnotationType ()),
104+ a -> AnnotationUtil .annotationAttributeMap (a , varElement )));
105+
109106 var typeUse1 =
110- Optional .ofNullable (uType .param0 ()).map (UType ::annotations ).stream ()
111- .flatMap (List ::stream )
112- .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
113- .collect (
114- toMap (
115- a -> UType .parse (a .getAnnotationType ()),
116- a -> AnnotationUtil .annotationAttributeMap (a , varElement )));
107+ Optional .ofNullable (uType .param0 ()).map (UType ::annotations ).stream ()
108+ .flatMap (List ::stream )
109+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
110+ .collect (
111+ toMap (
112+ a -> UType .parse (a .getAnnotationType ()),
113+ a -> AnnotationUtil .annotationAttributeMap (a , varElement )));
117114
118115 var typeUse2 =
119- Optional .ofNullable (uType .param1 ()).map (UType ::annotations ).stream ()
120- .flatMap (List ::stream )
121- .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
122- .collect (
123- toMap (
124- a -> UType .parse (a .getAnnotationType ()),
125- a -> AnnotationUtil .annotationAttributeMap (a , varElement )));
116+ Optional .ofNullable (uType .param1 ()).map (UType ::annotations ).stream ()
117+ .flatMap (List ::stream )
118+ .filter (ElementAnnotationContainer ::hasMetaConstraintAnnotation )
119+ .collect (
120+ toMap (
121+ a -> UType .parse (a .getAnnotationType ()),
122+ a -> AnnotationUtil .annotationAttributeMap (a , varElement )));
126123
127124 final boolean hasValid = uType .annotations ().stream ().anyMatch (ValidPrism ::isInstance );
128125
@@ -131,8 +128,7 @@ static ElementAnnotationContainer create(VariableElement varElement) {
131128 annotations .put (nonNull , "Map.of(\" message\" ,\" {avaje.NotNull.message}\" )" );
132129 }
133130
134- return new ElementAnnotationContainer (
135- uType , hasValid , annotations , typeUse1 , typeUse2 , Map .of ());
131+ return new ElementAnnotationContainer (uType , hasValid , annotations , typeUse1 , typeUse2 , Map .of ());
136132 }
137133
138134 public void addImports (Set <String > importTypes ) {
@@ -149,14 +145,13 @@ boolean isEmpty() {
149145 boolean supportsPrimitiveValidation () {
150146 for (final var validationAnnotation : annotations .keySet ()) {
151147 ConstraintPrism .getOptionalOn (typeElement (validationAnnotation .full ()))
152- .ifPresent (
153- p -> {
154- if (p .unboxPrimitives ()) {
155- validationAnnotation
156- .shortType ()
157- .transform (PrimitiveUtil ::addPrimitiveValidationAnnotation );
158- }
159- });
148+ .ifPresent (p -> {
149+ if (p .unboxPrimitives ()) {
150+ validationAnnotation
151+ .shortType ()
152+ .transform (PrimitiveUtil ::addPrimitiveValidationAnnotation );
153+ }
154+ });
160155
161156 if (!isPrimitiveValidationAnnotations (validationAnnotation .shortType ())) {
162157 return false ;
0 commit comments