|
1 | 1 | package lombok.mapstruct;
|
2 | 2 |
|
3 |
| -import java.lang.reflect.Field; |
| 3 | +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; |
4 | 4 |
|
| 5 | +import javax.lang.model.element.AnnotationMirror; |
5 | 6 | import javax.lang.model.type.TypeMirror;
|
| 7 | +import java.util.List; |
6 | 8 |
|
7 |
| -import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; |
8 |
| - |
| 9 | +/** |
| 10 | + * Report to MapStruct that a type is completed when there aren't any Lombok annotations left on it. Lombok annotations |
| 11 | + * are removed whenever a class is processed. This way, annotations which require multiple rounds to process are also |
| 12 | + * correctly handled, and MapStruct processing will be delayed until Lombok completely finishes processing required types. |
| 13 | + */ |
9 | 14 | class NotifierHider {
|
10 | 15 |
|
11 | 16 | public static class AstModificationNotifier implements AstModifyingAnnotationProcessor {
|
12 |
| - private static Field lombokInvoked; |
13 |
| - |
14 |
| - @Override public boolean isTypeComplete(TypeMirror type) { |
15 |
| - if (System.getProperty("lombok.disable") != null) return true; |
16 |
| - return isLombokInvoked(); |
17 |
| - } |
18 |
| - |
19 |
| - private static boolean isLombokInvoked() { |
20 |
| - if (lombokInvoked != null) { |
21 |
| - try { |
22 |
| - return lombokInvoked.getBoolean(null); |
23 |
| - } catch (Exception e) {} |
| 17 | + |
| 18 | + @Override |
| 19 | + public boolean isTypeComplete(final TypeMirror typeMirror) { |
| 20 | + final List<? extends AnnotationMirror> annotationMirrors = typeMirror.getAnnotationMirrors(); |
| 21 | + if (annotationMirrors == null || annotationMirrors.isEmpty()) { |
24 | 22 | return true;
|
25 | 23 | }
|
26 |
| - |
27 |
| - try { |
28 |
| - Class<?> data = Class.forName("lombok.launch.AnnotationProcessorHider$AstModificationNotifierData"); |
29 |
| - lombokInvoked = data.getField("lombokInvoked"); |
30 |
| - return lombokInvoked.getBoolean(null); |
31 |
| - } catch (Exception e) {} |
| 24 | + |
| 25 | + for (final AnnotationMirror annotationMirror : annotationMirrors) { |
| 26 | + final String annotationName = String.valueOf(annotationMirror); |
| 27 | + // check for ClaimingProcessor's SupportedAnnotationTypes |
| 28 | + if (annotationName.startsWith("@lombok.")) { |
| 29 | + return false; |
| 30 | + } |
| 31 | + } |
| 32 | + |
32 | 33 | return true;
|
| 34 | + |
33 | 35 | }
|
34 | 36 | }
|
35 | 37 | }
|
0 commit comments