aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authormszabo-wikia <2721291+mszabo-wikia@users.noreply.github.com>2018-06-06 14:59:18 +0200
committermszabo-wikia <2721291+mszabo-wikia@users.noreply.github.com>2018-06-06 14:59:44 +0200
commitca99bdfbede1586970a6253a1fbd3adb04be5a76 (patch)
tree4cb4cf4c28bbb853fac2ae9b028150f88a8f157e /src/core
parent5f58f0aed2e5ab0add2c6d99e4248520efd11e65 (diff)
downloadlombok-ca99bdfbede1586970a6253a1fbd3adb04be5a76.tar.gz
lombok-ca99bdfbede1586970a6253a1fbd3adb04be5a76.tar.bz2
lombok-ca99bdfbede1586970a6253a1fbd3adb04be5a76.zip
Fix #1716: Update for Gradle incremental compilation API change in Gradle 4.8 and above
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/javac/apt/LombokProcessor.java35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/core/lombok/javac/apt/LombokProcessor.java b/src/core/lombok/javac/apt/LombokProcessor.java
index fc457735..6f82f261 100644
--- a/src/core/lombok/javac/apt/LombokProcessor.java
+++ b/src/core/lombok/javac/apt/LombokProcessor.java
@@ -70,6 +70,9 @@ import com.sun.tools.javac.util.Context;
*/
@SupportedAnnotationTypes("*")
public class LombokProcessor extends AbstractProcessor {
+ private static final String GRADLE_INCREMENTAL_FILER_CLASS =
+ "org.gradle.api.internal.tasks.compile.processing.IncrementalFiler";
+
private ProcessingEnvironment processingEnv;
private JavacProcessingEnvironment javacProcessingEnv;
private JavacFiler javacFiler;
@@ -431,20 +434,30 @@ public class LombokProcessor extends AbstractProcessor {
* gradle incremental compilation, the delegate Filer of the gradle wrapper is returned.
*/
public JavacFiler getJavacFiler(Filer filer) {
- final Class<?> filerSuperClass = filer.getClass().getSuperclass();
- if (filerSuperClass.getName().equals("org.gradle.api.internal.tasks.compile.processing.IncrementalFiler")) {
- try {
- Field field = filerSuperClass.getDeclaredField("delegate");
- field.setAccessible(true);
- Object delegate = field.get(filer);
- return (JavacFiler) delegate;
- } catch (final Exception e) {
- e.printStackTrace();
- processingEnv.getMessager().printMessage(Kind.WARNING,
- "Can't get the delegate of the gradle IncrementalFiler. Lombok won't work.");
+ try {
+ final Class<?> filerClass = filer.getClass();
+ final Class<?> filerSuperClass = filerClass.getSuperclass();
+
+ if (filerSuperClass.getName().equals(GRADLE_INCREMENTAL_FILER_CLASS)) {
+ // Gradle before 4.8
+ return tryGetJavacFilerDelegate(filerSuperClass, filer);
+ } else if (filer.getClass().getName().equals(GRADLE_INCREMENTAL_FILER_CLASS)) {
+ // Gradle 4.8 and above
+ return tryGetJavacFilerDelegate(filerClass, filer);
}
+ } catch (final Exception e) {
+ e.printStackTrace();
+ processingEnv.getMessager().printMessage(Kind.WARNING,
+ "Can't get the delegate of the gradle IncrementalFiler. Lombok won't work.");
}
+
return (JavacFiler) filer;
}
+ private JavacFiler tryGetJavacFilerDelegate(Class<?> filerDelegateClass, Object instance) throws Exception {
+ Field field = filerDelegateClass.getDeclaredField("delegate");
+ field.setAccessible(true);
+ Object delegate = field.get(instance);
+ return (JavacFiler) delegate;
+ }
}