aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.38.xml14
-rw-r--r--buildScripts/ivy.xml2
-rw-r--r--src/core/lombok/core/AnnotationProcessor.java51
-rw-r--r--src/core/lombok/javac/apt/LombokProcessor.java69
4 files changed, 113 insertions, 23 deletions
diff --git a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.38.xml b/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.38.xml
new file mode 100644
index 00000000..1ca9c743
--- /dev/null
+++ b/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.38.xml
@@ -0,0 +1,14 @@
+<ivy-module version="2.0">
+ <info organisation="org.projectlombok" module="lombok.patcher" revision="0.38" publication="20201008193000">
+ <license name="MIT License" url="https://www.opensource.org/licenses/mit-license.php" />
+ <ivyauthor name="rzwitserloot" url="https://github.com/rzwitserloot" />
+ <ivyauthor name="rspilker" url="https://github.com/rspilker" />
+ <description homepage="https://projectlombok.org/" />
+ </info>
+ <configurations>
+ <conf name="default" />
+ </configurations>
+ <publications>
+ <artifact conf="default" url="https://projectlombok.org/downloads/lombok.patcher-0.38.jar" />
+ </publications>
+</ivy-module>
diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml
index 2fbdab0e..8383d00a 100644
--- a/buildScripts/ivy.xml
+++ b/buildScripts/ivy.xml
@@ -36,7 +36,7 @@
</configurations>
<dependencies>
- <dependency org="org.projectlombok" name="lombok.patcher" rev="0.36" conf="build,stripe->default" />
+ <dependency org="org.projectlombok" name="lombok.patcher" rev="0.38" conf="build,stripe->default" />
<dependency org="zwitserloot.com" name="cmdreader" rev="1.2" conf="build,stripe->runtime" />
<dependency org="projectlombok.org" name="spi" rev="0.2.7" conf="build" />
<dependency org="org.apache.ant" name="ant" rev="1.10.5" conf="build->default" />
diff --git a/src/core/lombok/core/AnnotationProcessor.java b/src/core/lombok/core/AnnotationProcessor.java
index d4a92408..c72d1bb2 100644
--- a/src/core/lombok/core/AnnotationProcessor.java
+++ b/src/core/lombok/core/AnnotationProcessor.java
@@ -26,8 +26,9 @@ import static lombok.core.Augments.ClassLoader_lombokAlreadyAddedTo;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
@@ -83,15 +84,11 @@ public class AnnotationProcessor extends AbstractProcessor {
for (Class<?> procEnvClass = procEnv.getClass(); procEnvClass != null; procEnvClass = procEnvClass.getSuperclass()) {
try {
- Field field;
- try {
- field = Permit.getField(procEnvClass, "delegate");
- } catch (NoSuchFieldException e) {
- field = Permit.getField(procEnvClass, "processingEnv");
- }
- Object delegate = field.get(procEnv);
-
- return tryRecursivelyObtainJavacProcessingEnvironment((ProcessingEnvironment) delegate);
+ Object delegate = tryGetDelegateField(procEnvClass, procEnv);
+ if (delegate == null) delegate = tryGetProcessingEnvField(procEnvClass, procEnv);
+ if (delegate == null) delegate = tryGetProxyDelegateToField(procEnvClass, procEnv);
+
+ if (delegate != null) return tryRecursivelyObtainJavacProcessingEnvironment((ProcessingEnvironment) delegate);
} catch (final Exception e) {
// no valid delegate, try superclass
}
@@ -100,6 +97,40 @@ public class AnnotationProcessor extends AbstractProcessor {
return null;
}
+ /**
+ * Gradle incremental processing
+ */
+ private static Object tryGetDelegateField(Class<?> delegateClass, Object instance) {
+ try {
+ return Permit.getField(delegateClass, "delegate").get(instance);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Kotlin incremental processing
+ */
+ private static Object tryGetProcessingEnvField(Class<?> delegateClass, Object instance) {
+ try {
+ return Permit.getField(delegateClass, "processingEnv").get(instance);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * InteliJ >= 2020.3
+ */
+ private static Object tryGetProxyDelegateToField(Class<?> delegateClass, Object instance) {
+ try {
+ InvocationHandler handler = Proxy.getInvocationHandler(instance);
+ return Permit.getField(handler.getClass(), "val$delegateTo").get(handler);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
static class JavacDescriptor extends ProcessorDescriptor {
private Processor processor;
diff --git a/src/core/lombok/javac/apt/LombokProcessor.java b/src/core/lombok/javac/apt/LombokProcessor.java
index 852e5de6..67df5b20 100644
--- a/src/core/lombok/javac/apt/LombokProcessor.java
+++ b/src/core/lombok/javac/apt/LombokProcessor.java
@@ -24,8 +24,10 @@ package lombok.javac.apt;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -432,11 +434,12 @@ public class LombokProcessor extends AbstractProcessor {
// try to find a "delegate" field in the object, and use this to try to obtain a JavacProcessingEnvironment
for (Class<?> procEnvClass = procEnv.getClass(); procEnvClass != null; procEnvClass = procEnvClass.getSuperclass()) {
- try {
- return getJavacProcessingEnvironment(tryGetDelegateField(procEnvClass, procEnv));
- } catch (final Exception e) {
- // delegate field was not found, try on superclass
- }
+ Object delegate = tryGetDelegateField(procEnvClass, procEnv);
+ if (delegate == null) delegate = tryGetProxyDelegateToField(procEnvClass, procEnv);
+ if (delegate == null) delegate = tryGetProcessingEnvField(procEnvClass, procEnv);
+
+ if (delegate != null) return getJavacProcessingEnvironment(delegate);
+ // delegate field was not found, try on superclass
}
processingEnv.getMessager().printMessage(Kind.WARNING,
@@ -454,11 +457,12 @@ public class LombokProcessor extends AbstractProcessor {
// try to find a "delegate" field in the object, and use this to check for a JavacFiler
for (Class<?> filerClass = filer.getClass(); filerClass != null; filerClass = filerClass.getSuperclass()) {
- try {
- return getJavacFiler(tryGetDelegateField(filerClass, filer));
- } catch (final Exception e) {
- // delegate field was not found, try on superclass
- }
+ Object delegate = tryGetDelegateField(filerClass, filer);
+ if (delegate == null) delegate = tryGetProxyDelegateToField(filerClass, filer);
+ if (delegate == null) delegate = tryGetFilerField(filerClass, filer);
+
+ if (delegate != null) return getJavacFiler(delegate);
+ // delegate field was not found, try on superclass
}
processingEnv.getMessager().printMessage(Kind.WARNING,
@@ -466,7 +470,48 @@ public class LombokProcessor extends AbstractProcessor {
return null;
}
- private Object tryGetDelegateField(Class<?> delegateClass, Object instance) throws Exception {
- return Permit.getField(delegateClass, "delegate").get(instance);
+ /**
+ * Gradle incremental processing
+ */
+ private Object tryGetDelegateField(Class<?> delegateClass, Object instance) {
+ try {
+ return Permit.getField(delegateClass, "delegate").get(instance);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Kotlin incremental processing
+ */
+ private Object tryGetProcessingEnvField(Class<?> delegateClass, Object instance) {
+ try {
+ return Permit.getField(delegateClass, "processingEnv").get(instance);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Kotlin incremental processing
+ */
+ private Object tryGetFilerField(Class<?> delegateClass, Object instance) {
+ try {
+ return Permit.getField(delegateClass, "filer").get(instance);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * InteliJ >= 2020.3
+ */
+ private Object tryGetProxyDelegateToField(Class<?> delegateClass, Object instance) {
+ try {
+ InvocationHandler handler = Proxy.getInvocationHandler(instance);
+ return Permit.getField(handler.getClass(), "val$delegateTo").get(handler);
+ } catch (Exception e) {
+ return null;
+ }
}
}