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 +++++++++++++ src/core9/module-info.java | 4 +- .../ap/spi/AstModifyingAnnotationProcessor.java | 48 ++++++++++++++++++++++ .../ap/spi/AstModifyingAnnotationProcessor.java | 48 ---------------------- src/launch/lombok/launch/AnnotationProcessor.java | 15 ++----- 6 files changed, 117 insertions(+), 62 deletions(-) create mode 100644 src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java create mode 100644 src/bindings/mapstruct/module-info.java create mode 100644 src/j9stubs/mapstruct/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java delete mode 100644 src/j9stubs/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java (limited to 'src') 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; +} diff --git a/src/core9/module-info.java b/src/core9/module-info.java index 56e54270..293bc839 100644 --- a/src/core9/module-info.java +++ b/src/core9/module-info.java @@ -23,7 +23,6 @@ module lombok { requires java.compiler; requires java.instrument; requires jdk.unsupported; - requires static org.mapstruct.processor; exports lombok; exports lombok.experimental; @@ -34,6 +33,7 @@ module lombok { exports lombok.extern.slf4j; exports lombok.extern.flogger; + exports lombok.launch to lombok.mapstruct; + provides javax.annotation.processing.Processor with lombok.launch.AnnotationProcessorHider.AnnotationProcessor; - provides org.mapstruct.ap.spi.AstModifyingAnnotationProcessor with lombok.launch.AnnotationProcessorHider.AstModificationNotifier; } diff --git a/src/j9stubs/mapstruct/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java b/src/j9stubs/mapstruct/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java new file mode 100644 index 00000000..ffb99030 --- /dev/null +++ b/src/j9stubs/mapstruct/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.type.TypeMirror; + +/** + * A contract to be implemented by other annotation processors which - against the design philosophy of JSR 269 - alter + * the types under compilation. + *

+ * This contract will be queried by MapStruct when examining types referenced by mappers to be generated, most notably + * the source and target types of mapping methods. If at least one AST-modifying processor announces further changes to + * such type, the generation of the affected mapper(s) will be deferred to a future round in the annnotation processing + * cycle. + *

+ * Implementations are discovered via the service loader, i.e. a JAR providing an AST-modifying processor needs to + * declare its implementation in a file {@code META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor}. + * + * @author Gunnar Morling + */ +//@org.mapstruct.util.Experimental +public interface AstModifyingAnnotationProcessor { + + /** + * Whether the specified type has been fully processed by this processor or not (i.e. this processor will amend the + * given type's structure after this invocation). + * + * @param type The type of interest + * @return {@code true} if this processor has fully processed the given type, {@code false} otherwise. + */ + boolean isTypeComplete(TypeMirror type); +} \ No newline at end of file diff --git a/src/j9stubs/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java b/src/j9stubs/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java deleted file mode 100644 index ffb99030..00000000 --- a/src/j9stubs/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.spi; - -import javax.lang.model.type.TypeMirror; - -/** - * A contract to be implemented by other annotation processors which - against the design philosophy of JSR 269 - alter - * the types under compilation. - *

- * This contract will be queried by MapStruct when examining types referenced by mappers to be generated, most notably - * the source and target types of mapping methods. If at least one AST-modifying processor announces further changes to - * such type, the generation of the affected mapper(s) will be deferred to a future round in the annnotation processing - * cycle. - *

- * Implementations are discovered via the service loader, i.e. a JAR providing an AST-modifying processor needs to - * declare its implementation in a file {@code META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor}. - * - * @author Gunnar Morling - */ -//@org.mapstruct.util.Experimental -public interface AstModifyingAnnotationProcessor { - - /** - * Whether the specified type has been fully processed by this processor or not (i.e. this processor will amend the - * given type's structure after this invocation). - * - * @param type The type of interest - * @return {@code true} if this processor has fully processed the given type, {@code false} otherwise. - */ - boolean isTypeComplete(TypeMirror type); -} \ No newline at end of file diff --git a/src/launch/lombok/launch/AnnotationProcessor.java b/src/launch/lombok/launch/AnnotationProcessor.java index b03dec76..456a8cef 100644 --- a/src/launch/lombok/launch/AnnotationProcessor.java +++ b/src/launch/lombok/launch/AnnotationProcessor.java @@ -34,22 +34,13 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; -import javax.lang.model.type.TypeMirror; - -import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import sun.misc.Unsafe; class AnnotationProcessorHider { - public static class AstModificationNotifier implements AstModifyingAnnotationProcessor { - @Override public boolean isTypeComplete(TypeMirror type) { - if (System.getProperty("lombok.disable") != null) return true; - return AstModificationNotifierData.lombokInvoked; - } - } - - static class AstModificationNotifierData { - volatile static boolean lombokInvoked = false; + + public static class AstModificationNotifierData { + public volatile static boolean lombokInvoked = false; } public static class AnnotationProcessor extends AbstractProcessor { -- cgit