From b6f17ef81acdff9896a8e2b2eced40223491ed4e Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 6 Feb 2018 06:09:48 +0100 Subject: [jdk9] added a best-effort attempt to claim away lombok annotations when lombok is deployed in JDK9-module mode. Due to a bug or oversight in jigsaw it is no longer possible to supply 2 providers for the Processor service, which was the common and as far as I know only way to deal with the situation that you want to claim a subset of annotations but look at all of them (which is what lombok wants to do). --- src/core/lombok/core/AnnotationProcessor.java | 17 ++++++++++++++++- src/core9/module-info.java | 1 - 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/core/lombok/core/AnnotationProcessor.java b/src/core/lombok/core/AnnotationProcessor.java index 5531ad8e..64b8de43 100644 --- a/src/core/lombok/core/AnnotationProcessor.java +++ b/src/core/lombok/core/AnnotationProcessor.java @@ -40,6 +40,7 @@ import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; +import javax.lang.model.element.Name; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic.Kind; @@ -163,7 +164,21 @@ public class AnnotationProcessor extends AbstractProcessor { for (ProcessorDescriptor proc : active) proc.process(annotations, roundEnv); - return false; + boolean onlyLombok = true; + boolean zeroElems = true; + for (TypeElement elem : annotations) { + zeroElems = false; + Name n = elem.getQualifiedName(); + if (n.length() > 7 && n.subSequence(0, 7).toString().equals("lombok.")) continue; + onlyLombok = false; + } + + // Normally we rely on the claiming processor to claim away all lombok annotations. + // One of the many Java9 oversights is that this 'process' API has not been fixed to address the point that 'files I want to look at' and 'annotations I want to claim' must be one and the same, + // and yet in java9 you can no longer have 2 providers for the same service, thus, if you go by module path, lombok no longer loads the ClaimingProcessor. + // This doesn't do as good a job, but it'll have to do. The only way to go from here, I think, is either 2 modules, or use reflection hackery to add ClaimingProcessor during our init. + + return onlyLombok && !zeroElems; } /** diff --git a/src/core9/module-info.java b/src/core9/module-info.java index a4c97a89..f11e2922 100644 --- a/src/core9/module-info.java +++ b/src/core9/module-info.java @@ -12,7 +12,6 @@ module lombok { exports lombok.extern.slf4j; provides javax.annotation.processing.Processor with lombok.launch.AnnotationProcessorHider.AnnotationProcessor; -// provides javax.annotation.processing.Processor with lombok.launch.AnnotationProcessorHider.ClaimingProcessor; provides org.mapstruct.ap.spi.AstModifyingAnnotationProcessor with lombok.launch.AnnotationProcessorHider.AstModificationNotifier; } -- cgit