|
15 | 15 |
|
16 | 16 | import javax.lang.model.element.*; |
17 | 17 | import javax.lang.model.type.TypeMirror; |
| 18 | +import javax.lang.model.util.Elements; |
18 | 19 | import javax.lang.model.util.SimpleAnnotationValueVisitor14; |
19 | 20 | import javax.lang.model.util.Types; |
20 | 21 |
|
@@ -46,10 +47,12 @@ private record EnumValue(String type, String value) {} |
46 | 47 |
|
47 | 48 | private final List<String> skip; |
48 | 49 | private final Types types; |
| 50 | + private final Elements elements; |
49 | 51 | private final boolean hasBeanValidation; |
50 | 52 |
|
51 | 53 | public RouteAttributesGenerator(MvcContext context, boolean hasBeanValidation) { |
52 | 54 | var environment = context.getProcessingEnvironment(); |
| 55 | + this.elements = environment.getElementUtils(); |
53 | 56 | this.types = environment.getTypeUtils(); |
54 | 57 | this.skip = Options.stringListOpt(environment, SKIP_ATTRIBUTE_ANNOTATIONS); |
55 | 58 | this.hasBeanValidation = hasBeanValidation; |
@@ -165,22 +168,33 @@ private Map<String, Object> annotationMap(List<? extends AnnotationMirror> annot |
165 | 168 | String prefix = elem.getSimpleName().toString(); |
166 | 169 | // Set all values and then override with present values (fix for JDK 11+) |
167 | 170 | result.putAll(toMap(annotation.getElementValues(), prefix)); |
168 | | - // toMap(elements.getElementValuesWithDefaults(annotation), |
169 | | - // prefix).forEach(result::putIfAbsent); |
| 171 | + |
| 172 | + // Defaults value only pick "value" |
| 173 | + toMap(elements.getElementValuesWithDefaults(annotation), prefix, "value"::equals) |
| 174 | + .forEach(result::putIfAbsent); |
170 | 175 | } |
171 | 176 | return result; |
172 | 177 | } |
173 | 178 |
|
174 | 179 | private Map<String, Object> toMap( |
175 | 180 | Map<? extends ExecutableElement, ? extends AnnotationValue> values, String prefix) { |
| 181 | + return toMap(values, prefix, name -> true); |
| 182 | + } |
| 183 | + |
| 184 | + private Map<String, Object> toMap( |
| 185 | + Map<? extends ExecutableElement, ? extends AnnotationValue> values, |
| 186 | + String prefix, |
| 187 | + Predicate<String> filter) { |
176 | 188 | Map<String, Object> result = new LinkedHashMap<>(); |
177 | 189 | for (var attribute : values.entrySet()) { |
178 | 190 | var value = annotationValue(attribute.getValue()); |
179 | 191 | if (value != null && !value.toString().isEmpty()) { |
180 | 192 | var method = attribute.getKey().getSimpleName().toString(); |
181 | | - var name = method.equals("value") ? prefix : prefix + "." + method; |
182 | | - // Found value is override on JDK 11 with default annotation value, we trust that spe |
183 | | - result.putIfAbsent(name, value); |
| 193 | + if (filter.test(method)) { |
| 194 | + var name = method.equals("value") ? prefix : prefix + "." + method; |
| 195 | + // Found value is override on JDK 11 with default annotation value, we trust that spe |
| 196 | + result.putIfAbsent(name, value); |
| 197 | + } |
184 | 198 | } |
185 | 199 | } |
186 | 200 | return result; |
|
0 commit comments