|
1 | 1 | package lombok.mapstruct;
|
2 | 2 |
|
3 |
| -import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; |
| 3 | +import java.lang.reflect.Field; |
4 | 4 |
|
5 |
| -import javax.lang.model.element.AnnotationMirror; |
6 | 5 | import javax.lang.model.type.TypeMirror;
|
7 |
| -import java.util.List; |
8 | 6 |
|
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 |
| - */ |
| 7 | +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; |
| 8 | + |
14 | 9 | class NotifierHider {
|
15 | 10 | public static class AstModificationNotifier implements AstModifyingAnnotationProcessor {
|
16 |
| - @Override |
17 |
| - public boolean isTypeComplete(TypeMirror typeMirror) { |
| 11 | + private static Field lombokInvoked; |
| 12 | + |
| 13 | + @Override public boolean isTypeComplete(TypeMirror type) { |
18 | 14 | if (System.getProperty("lombok.disable") != null) return true;
|
19 |
| - List<? extends AnnotationMirror> annotationMirrors = typeMirror.getAnnotationMirrors(); |
20 |
| - if (annotationMirrors == null || annotationMirrors.isEmpty()) return true; |
21 |
| - |
22 |
| - for (AnnotationMirror annotationMirror : annotationMirrors) { |
23 |
| - String annotationName = String.valueOf(annotationMirror); |
24 |
| - if (annotationName.startsWith("@lombok.")) return false; |
| 15 | + return isLombokInvoked(); |
| 16 | + } |
| 17 | + |
| 18 | + private static boolean isLombokInvoked() { |
| 19 | + if (lombokInvoked != null) { |
| 20 | + try { |
| 21 | + return lombokInvoked.getBoolean(null); |
| 22 | + } catch (Exception e) {} |
| 23 | + return true; |
25 | 24 | }
|
26 | 25 |
|
| 26 | + try { |
| 27 | + Class<?> data = Class.forName("lombok.launch.AnnotationProcessorHider$AstModificationNotifierData"); |
| 28 | + lombokInvoked = data.getField("lombokInvoked"); |
| 29 | + return lombokInvoked.getBoolean(null); |
| 30 | + } catch (Exception e) {} |
27 | 31 | return true;
|
28 | 32 | }
|
29 | 33 | }
|
|
0 commit comments