aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/apt
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok/javac/apt')
-rw-r--r--src/core/lombok/javac/apt/LombokProcessor.java49
1 files changed, 46 insertions, 3 deletions
diff --git a/src/core/lombok/javac/apt/LombokProcessor.java b/src/core/lombok/javac/apt/LombokProcessor.java
index 6547c143..6e229279 100644
--- a/src/core/lombok/javac/apt/LombokProcessor.java
+++ b/src/core/lombok/javac/apt/LombokProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 The Project Lombok Authors.
+ * Copyright (C) 2009-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
@@ -67,7 +67,6 @@ import com.sun.tools.javac.util.Context;
*/
@SupportedAnnotationTypes("*")
public class LombokProcessor extends AbstractProcessor {
-
private JavacProcessingEnvironment processingEnv;
private JavacTransformer transformer;
private Trees trees;
@@ -82,9 +81,14 @@ 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();
- transformer = new JavacTransformer(procEnv.getMessager());
trees = Trees.instance(procEnv);
+ transformer = new JavacTransformer(procEnv.getMessager(), trees);
SortedSet<Long> p = transformer.getPriorities();
if (p.isEmpty()) {
this.priorityLevels = new long[] {0L};
@@ -97,6 +101,45 @@ public class LombokProcessor extends AbstractProcessor {
}
}
+ private static final String JPE = "com.sun.tools.javac.processing.JavacProcessingEnvironment";
+ private static final Field javacProcessingEnvironment_discoveredProcs = getFieldAccessor(JPE, "discoveredProcs");
+ private static final Field discoveredProcessors_procStateList = getFieldAccessor(JPE + "$DiscoveredProcessors", "procStateList");
+ private static final Field processorState_processor = getFieldAccessor(JPE + "$processor", "processor");
+
+ private static final Field getFieldAccessor(String typeName, String fieldName) {
+ try {
+ Class<?> c = Class.forName(typeName);
+ Field f = c.getDeclaredField(fieldName);
+ f.setAccessible(true);
+ return f;
+ } catch (ClassNotFoundException e) {
+ return null;
+ } catch (NoSuchFieldException e) {
+ return null;
+ }
+ }
+
+ private String listAnnotationProcessorsBeforeOurs() {
+ try {
+ Object discoveredProcessors = javacProcessingEnvironment_discoveredProcs.get(this.processingEnv);
+ ArrayList<?> states = (ArrayList<?>) discoveredProcessors_procStateList.get(discoveredProcessors);
+ if (states == null || states.isEmpty()) return null;
+ if (states.size() == 1) return processorState_processor.get(states.get(0)).getClass().getName();
+
+ int idx = 0;
+ StringBuilder out = new StringBuilder();
+ for (Object processState : states) {
+ idx++;
+ String name = processorState_processor.get(processState).getClass().getName();
+ if (out.length() > 0) out.append(", ");
+ out.append("[").append(idx).append("] ").append(name);
+ }
+ return out.toString();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
private void placePostCompileAndDontMakeForceRoundDummiesHook() {
stopJavacProcessingEnvironmentFromClosingOurClassloader();