diff --git a/AUTHORS b/AUTHORS index 67e800602..a8c9bcc45 100755 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,6 @@ Lombok contributors in alphabetical order: Adam Juraszek -Aleksandar Kanchev <136312841+kanchev1@users.noreply.github.com> Aleksandr Zhelezniak Amine Touzani Andre Brait diff --git a/src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java b/src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java index 834b5bf2e..222e9c0ba 100644 --- a/src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java +++ b/src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java @@ -1,29 +1,33 @@ package lombok.mapstruct; -import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import java.lang.reflect.Field; -import javax.lang.model.element.AnnotationMirror; import javax.lang.model.type.TypeMirror; -import java.util.List; -/** - * Report to MapStruct that a type is completed when there aren't any Lombok annotations left on it. Lombok annotations - * are removed whenever a class is processed. This way, annotations which require multiple rounds to process are also - * correctly handled, and MapStruct processing will be delayed until Lombok completely finishes processing required types. - */ +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + class NotifierHider { public static class AstModificationNotifier implements AstModifyingAnnotationProcessor { - @Override - public boolean isTypeComplete(TypeMirror typeMirror) { + private static Field lombokInvoked; + + @Override public boolean isTypeComplete(TypeMirror type) { if (System.getProperty("lombok.disable") != null) return true; - List annotationMirrors = typeMirror.getAnnotationMirrors(); - if (annotationMirrors == null || annotationMirrors.isEmpty()) return true; - - for (AnnotationMirror annotationMirror : annotationMirrors) { - String annotationName = String.valueOf(annotationMirror); - if (annotationName.startsWith("@lombok.")) return false; + return isLombokInvoked(); + } + + private static boolean isLombokInvoked() { + if (lombokInvoked != null) { + try { + return lombokInvoked.getBoolean(null); + } catch (Exception e) {} + return true; } + try { + Class data = Class.forName("lombok.launch.AnnotationProcessorHider$AstModificationNotifierData"); + lombokInvoked = data.getField("lombokInvoked"); + return lombokInvoked.getBoolean(null); + } catch (Exception e) {} return true; } } diff --git a/src/launch/lombok/launch/AnnotationProcessor.java b/src/launch/lombok/launch/AnnotationProcessor.java index 28a28d723..456a8cefc 100644 --- a/src/launch/lombok/launch/AnnotationProcessor.java +++ b/src/launch/lombok/launch/AnnotationProcessor.java @@ -39,6 +39,10 @@ class AnnotationProcessorHider { + public static class AstModificationNotifierData { + public volatile static boolean lombokInvoked = false; + } + public static class AnnotationProcessor extends AbstractProcessor { private final AbstractProcessor instance = createWrappedInstance(); @@ -56,6 +60,7 @@ public static class AnnotationProcessor extends AbstractProcessor { @Override public void init(ProcessingEnvironment processingEnv) { disableJava9SillyWarning(); + AstModificationNotifierData.lombokInvoked = true; instance.init(processingEnv); super.init(processingEnv); }