diff options
author | Rawi01 <Rawi01@users.noreply.github.com> | 2020-10-04 11:22:48 +0200 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2020-10-08 14:06:23 +0200 |
commit | 29d34186f7db17fd9ea61c9487d70aad7faefe26 (patch) | |
tree | ef5347963a624e9d07995527a7321243641fc172 /src/core/lombok/javac | |
parent | 58545cec67ada261d13c454fce460ed55798cd72 (diff) | |
download | lombok-29d34186f7db17fd9ea61c9487d70aad7faefe26.tar.gz lombok-29d34186f7db17fd9ea61c9487d70aad7faefe26.tar.bz2 lombok-29d34186f7db17fd9ea61c9487d70aad7faefe26.zip |
[fixes #2592] Find ProcessingEnvironment in InteliJ 2020.3 and Kotlin
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r-- | src/core/lombok/javac/apt/LombokProcessor.java | 69 |
1 files changed, 57 insertions, 12 deletions
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; + } } } |