mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-17 06:14:58 +00:00
Printing missing gradle integration would print for any non-javac, non-gradle compiler. Fixed that.
This commit is contained in:
1 parent
eeab3c0021
commit
b9fb35cb8e
2 files changed
+14
-13
No files matched your search
@@ -49,7 +49,7 @@ import lombok.patcher.ClassRootFinder;
|
||||
|
||||
@SupportedAnnotationTypes("*")
|
||||
public class AnnotationProcessor extends AbstractProcessor {
|
||||
|
||||
|
||||
private static String trace(Throwable t) {
|
||||
StringWriter w = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(w, true));
|
||||
@@ -65,7 +65,7 @@ public class AnnotationProcessor extends AbstractProcessor {
|
||||
private final List<ProcessorDescriptor> registered = Arrays.asList(new JavacDescriptor(), new EcjDescriptor());
|
||||
private final List<ProcessorDescriptor> active = new ArrayList<ProcessorDescriptor>();
|
||||
private final List<String> delayedWarnings = new ArrayList<String>();
|
||||
|
||||
|
||||
/**
|
||||
* This method is a simplified version of {@link lombok.javac.apt.LombokProcessor.getJavacProcessingEnvironment}
|
||||
* It simply returns the processing environment, but in case of gradle incremental compilation,
|
||||
@@ -73,34 +73,35 @@ public class AnnotationProcessor extends AbstractProcessor {
|
||||
*/
|
||||
public static ProcessingEnvironment getJavacProcessingEnvironment(ProcessingEnvironment procEnv, List<String> delayedWarnings) {
|
||||
ProcessingEnvironment javacProcEnv = tryRecursivelyObtainJavacProcessingEnvironment(procEnv);
|
||||
|
||||
|
||||
if (javacProcEnv == null) {
|
||||
delayedWarnings.add("Can't get the delegate of the gradle IncrementalProcessingEnvironment.");
|
||||
if (!procEnv.getClass().getName().startsWith("org.eclipse.jdt.")) {
|
||||
delayedWarnings.add("Can't get the delegate of the gradle IncrementalProcessingEnvironment.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return javacProcEnv;
|
||||
}
|
||||
|
||||
|
||||
private static ProcessingEnvironment tryRecursivelyObtainJavacProcessingEnvironment(ProcessingEnvironment procEnv) {
|
||||
if (procEnv.getClass().getName().equals("com.sun.tools.javac.processing.JavacProcessingEnvironment")) {
|
||||
return procEnv;
|
||||
}
|
||||
|
||||
|
||||
for (Class<?> procEnvClass = procEnv.getClass(); procEnvClass != null; procEnvClass = procEnvClass.getSuperclass()) {
|
||||
try {
|
||||
Field field = procEnvClass.getDeclaredField("delegate");
|
||||
field.setAccessible(true);
|
||||
Object delegate = field.get(procEnv);
|
||||
|
||||
|
||||
return tryRecursivelyObtainJavacProcessingEnvironment((ProcessingEnvironment) delegate);
|
||||
} catch (final Exception e) {
|
||||
// no valid delegate, try superclass
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static class JavacDescriptor extends ProcessorDescriptor {
|
||||
private Processor processor;
|
||||
@@ -111,9 +112,9 @@ public class AnnotationProcessor extends AbstractProcessor {
|
||||
|
||||
@Override boolean want(ProcessingEnvironment procEnv, List<String> delayedWarnings) {
|
||||
ProcessingEnvironment javacProcEnv = getJavacProcessingEnvironment(procEnv, delayedWarnings);
|
||||
|
||||
|
||||
if (javacProcEnv == null) return false;
|
||||
|
||||
|
||||
try {
|
||||
ClassLoader classLoader = findAndPatchClassLoader(javacProcEnv);
|
||||
processor = (Processor) Class.forName("lombok.javac.apt.LombokProcessor", false, classLoader).newInstance();
|
||||
|
||||
@@ -44,7 +44,7 @@ import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
|
||||
/**
|
||||
* Handles the {@code lombok.FieldDefaults} annotation for eclipse.
|
||||
* Handles the {@code lombok.FieldDefaults} annotation for javac.
|
||||
*/
|
||||
@ProviderFor(JavacASTVisitor.class)
|
||||
@HandlerPriority(-2048) //-2^11; to ensure @Value picks up on messing with the fields' 'final' state, run earlier.
|
||||
|
||||
Reference in new issue
Block a user