mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 06:17:44 +00:00
Added support for MapStructu’s AstModifyingAnnotationProcessor SPI system. Also removed log statements.
This commit is contained in:
1 parent
5cbdd35744
commit
5a7f02ca05
4 files changed
+71
-14
No files matched your search
@@ -143,6 +143,7 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
|
||||
anymore until you 'ant clean'. That's very much not desired, so we kill the processor, which stops lombok from running.
|
||||
We re-create the file at the end of this target. -->
|
||||
<delete file="build/lombok/META-INF/services/javax.annotation.processing.Processor" quiet="true" />
|
||||
<delete file="build/lombok/META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor" quiet="true" />
|
||||
<ivy:compile destdir="build/stubsstubs" source="1.5" target="1.5" includeantruntime="false">
|
||||
<compilerarg value="-Xbootclasspath/p:lib/openJDK6Environment/rt-openjdk6.jar" />
|
||||
<src path="src/stubsstubs" />
|
||||
@@ -228,6 +229,7 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
|
||||
<mkdir dir="build/lombok/META-INF/services" />
|
||||
<echo file="build/lombok/META-INF/services/javax.annotation.processing.Processor">lombok.launch.AnnotationProcessorHider$AnnotationProcessor
|
||||
lombok.launch.AnnotationProcessorHider$ClaimingProcessor</echo>
|
||||
<echo file="build/lombok/META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor">lombok.launch.AnnotationProcessorHider$AstModificationNotifier</echo>
|
||||
</target>
|
||||
|
||||
<target name="dist" description="Builds THE lombok.jar file which contains everything." depends="version, compile">
|
||||
|
||||
@@ -81,10 +81,6 @@ public class LombokProcessor extends AbstractProcessor {
|
||||
}
|
||||
|
||||
this.processingEnv = (JavacProcessingEnvironment) procEnv;
|
||||
String beforeOurs = listAnnotationProcessorsBeforeOurs();
|
||||
if (beforeOurs != null) {
|
||||
procEnv.getMessager().printMessage(Kind.NOTE, "Lombok is not the first annotation processor in the lineup. Configure your build tool with an explicit list of processors so that lombok is first. See https://projectlombok.org/configureMultipleProcessors for more. Processors before lombok in the lineup: " + beforeOurs);
|
||||
}
|
||||
|
||||
placePostCompileAndDontMakeForceRoundDummiesHook();
|
||||
trees = Trees.instance(procEnv);
|
||||
@@ -119,6 +115,11 @@ public class LombokProcessor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
// The intent of this method is to have lombok emit a warning if it's not 'first in line'. However, pragmatically speaking, you're always looking at one of two cases:
|
||||
// (A) The other processor(s) running before lombok require lombok to have run or they crash. So, they crash, and unfortunately we are never even init-ed; the warning is never emitted.
|
||||
// (B) The other processor(s) don't care about it at all. So, it doesn't actually matter that lombok isn't first.
|
||||
// Hence, for now, no warnings.
|
||||
@SuppressWarnings("unused")
|
||||
private String listAnnotationProcessorsBeforeOurs() {
|
||||
try {
|
||||
Object discoveredProcessors = javacProcessingEnvironment_discoveredProcs.get(this.processingEnv);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014-2016 The Project Lombok Authors.
|
||||
* Copyright (C) 2014-2017 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
|
||||
@@ -33,14 +33,23 @@ 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;
|
||||
|
||||
class AnnotationProcessorHider {
|
||||
public static class AnnotationProcessor extends AbstractProcessor {
|
||||
private static final long START = System.currentTimeMillis();
|
||||
|
||||
private void log(String txt) {
|
||||
System.out.printf("***[%3d]: %s\n", System.currentTimeMillis() - START, txt);
|
||||
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 AnnotationProcessor extends AbstractProcessor {
|
||||
private final AbstractProcessor instance = createWrappedInstance();
|
||||
|
||||
@Override public Set<String> getSupportedOptions() {
|
||||
@@ -56,15 +65,12 @@ class AnnotationProcessorHider {
|
||||
}
|
||||
|
||||
@Override public void init(ProcessingEnvironment processingEnv) {
|
||||
log("Lombok in init");
|
||||
AstModificationNotifierData.lombokInvoked = true;
|
||||
instance.init(processingEnv);
|
||||
super.init(processingEnv);
|
||||
}
|
||||
|
||||
private int roundCounter = 0;
|
||||
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
roundCounter++;
|
||||
log("Lombok in round " + roundCounter);
|
||||
return instance.process(annotations, roundEnv);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
Reference in new issue
Block a user