mirror of
https://github.com/tiennm99/lombok.git
synced 2026-09-05 02:19:49 +00:00
[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).
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user