|
17 | 17 | import javax.annotation.processing.RoundEnvironment;
|
18 | 18 | import javax.annotation.processing.SupportedAnnotationTypes;
|
19 | 19 | import javax.lang.model.SourceVersion;
|
20 |
| -import javax.lang.model.element.Element; |
21 |
| -import javax.lang.model.element.ElementKind; |
22 |
| -import javax.lang.model.element.ExecutableElement; |
23 |
| -import javax.lang.model.element.TypeElement; |
| 20 | +import javax.lang.model.element.*; |
| 21 | +import javax.lang.model.type.DeclaredType; |
24 | 22 | import javax.lang.model.type.TypeMirror;
|
25 | 23 | import javax.lang.model.util.ElementFilter;
|
26 | 24 |
|
@@ -208,24 +206,34 @@ private void writeAdapters(Set<? extends Element> beans) {
|
208 | 206 | private void writeContraintAdapters(Set<? extends Element> beans) {
|
209 | 207 | ElementFilter.typesIn(beans).stream()
|
210 | 208 | .filter(
|
211 |
| - t -> |
212 |
| - t.getAnnotationMirrors().stream() |
| 209 | + type -> |
| 210 | + type.getAnnotationMirrors().stream() |
213 | 211 | .anyMatch(m -> ConstraintPrism.isPresent(m.getAnnotationType().asElement())))
|
214 |
| - .forEach(this::writeAdapterForContraint); |
| 212 | + .forEach(this::writeAdapterForConstraint); |
215 | 213 | }
|
216 | 214 |
|
217 | 215 | private void writeAdapterForType(TypeElement typeElement) {
|
| 216 | + if (isController(typeElement)) { |
| 217 | + // @Valid on controller just indicating the controller request |
| 218 | + // payloads should be validated - ignore this one |
| 219 | + return; |
| 220 | + } |
218 | 221 | final ClassReader beanReader = new ClassReader(typeElement);
|
219 | 222 | writeAdapter(typeElement, beanReader);
|
220 | 223 | }
|
221 | 224 |
|
222 |
| - private void writeAdapterForContraint(TypeElement typeElement) { |
| 225 | + private boolean isController(TypeElement typeElement) { |
| 226 | + return typeElement.getAnnotationMirrors().stream() |
| 227 | + .map(AnnotationMirror::getAnnotationType) |
| 228 | + .map(DeclaredType::toString) |
| 229 | + .anyMatch(val -> val.endsWith(".Controller")); |
| 230 | + } |
223 | 231 |
|
| 232 | + private void writeAdapterForConstraint(TypeElement typeElement) { |
224 | 233 | if (ElementFilter.methodsIn(typeElement.getEnclosedElements()).stream()
|
225 | 234 | .noneMatch(m -> "message".equals(m.getSimpleName().toString()))) {
|
226 | 235 | throw new IllegalStateException("Constraint annotations must contain a message method");
|
227 | 236 | }
|
228 |
| - |
229 | 237 | final ContraintReader beanReader = new ContraintReader(typeElement);
|
230 | 238 | writeAdapter(typeElement, beanReader);
|
231 | 239 | }
|
|
0 commit comments