From 0d7540db0cc0c9a2758799522925f09eddeb7420 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Fri, 14 Feb 2020 00:06:52 +0100 Subject: (#2125) Extract mapstruct binding to separate module. --- .../mapstruct/lombok/mapstruct/NotifierHider.java | 35 ++++++++++++++++++++++ src/bindings/mapstruct/module-info.java | 29 ++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java create mode 100644 src/bindings/mapstruct/module-info.java (limited to 'src/bindings') diff --git a/src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java b/src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java new file mode 100644 index 00000000..a8e92b4b --- /dev/null +++ b/src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java @@ -0,0 +1,35 @@ +package lombok.mapstruct; + +import java.lang.reflect.Field; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +class NotifierHider { + + public static class AstModificationNotifier implements AstModifyingAnnotationProcessor { + private static Field lombokInvoked; + + @Override public boolean isTypeComplete(TypeMirror type) { + if (System.getProperty("lombok.disable") != null) return true; + 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/bindings/mapstruct/module-info.java b/src/bindings/mapstruct/module-info.java new file mode 100644 index 00000000..bbfbd823 --- /dev/null +++ b/src/bindings/mapstruct/module-info.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2020 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +module lombok.mapstruct { + requires lombok; + requires java.compiler; + + requires static org.mapstruct.processor; + + provides org.mapstruct.ap.spi.AstModifyingAnnotationProcessor with lombok.mapstruct.NotifierHider.AstModificationNotifier; +} -- cgit