aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/apt
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2017-11-29 18:16:04 +0100
committerRoel Spilker <r.spilker@gmail.com>2017-11-29 19:42:24 +0100
commit4710d20e180c35674b2d934aafb0a8171ff1608e (patch)
tree2707e7966a48cc24125f5d76b3ed19a7cc3ab78a /src/core/lombok/javac/apt
parent72561d742884e857bc11cca290be26d9d04ec937 (diff)
downloadlombok-4710d20e180c35674b2d934aafb0a8171ff1608e.tar.gz
lombok-4710d20e180c35674b2d934aafb0a8171ff1608e.tar.bz2
lombok-4710d20e180c35674b2d934aafb0a8171ff1608e.zip
replace all fileManagers to make sure we patch the generated bytecode, fixes #1518
Diffstat (limited to 'src/core/lombok/javac/apt')
-rw-r--r--src/core/lombok/javac/apt/LombokProcessor.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/core/lombok/javac/apt/LombokProcessor.java b/src/core/lombok/javac/apt/LombokProcessor.java
index b962a955..5c7e47ee 100644
--- a/src/core/lombok/javac/apt/LombokProcessor.java
+++ b/src/core/lombok/javac/apt/LombokProcessor.java
@@ -54,6 +54,8 @@ import lombok.javac.JavacTransformer;
import com.sun.source.util.TreePath;
import com.sun.source.util.Trees;
+import com.sun.tools.javac.jvm.ClassWriter;
+import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.processing.JavacFiler;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
@@ -156,7 +158,6 @@ public class LombokProcessor extends AbstractProcessor {
@SuppressWarnings("unchecked")
Map<Object,Object> ht = (Map<Object,Object>) htField.get(context);
final JavaFileManager originalFiler = (JavaFileManager) ht.get(key);
-
if (!(originalFiler instanceof InterceptingJavaFileManager)) {
final Messager messager = processingEnv.getMessager();
DiagnosticsReceiver receiver = new MessagerDiagnosticsReceiver(messager);
@@ -166,11 +167,37 @@ public class LombokProcessor extends AbstractProcessor {
Field filerFileManagerField = JavacFiler.class.getDeclaredField("fileManager");
filerFileManagerField.setAccessible(true);
filerFileManagerField.set(processingEnv.getFiler(), newFiler);
+
+ replaceFileManagerJdk9(context, newFiler);
}
} catch (Exception e) {
throw Lombok.sneakyThrow(e);
}
}
+
+ private void replaceFileManagerJdk9(Context context, JavaFileManager newFiler) {
+ try {
+ JavaCompiler compiler = (JavaCompiler) JavaCompiler.class.getDeclaredMethod("instance", Context.class).invoke(null, context);
+ try {
+ Field fileManagerField = JavaCompiler.class.getDeclaredField("fileManager");
+ fileManagerField.setAccessible(true);
+ fileManagerField.set(compiler, newFiler);
+ }
+ catch (Exception e) {}
+
+ try {
+ Field writerField = JavaCompiler.class.getDeclaredField("writer");
+ writerField.setAccessible(true);
+ ClassWriter writer = (ClassWriter) writerField.get(compiler);
+ Field fileManagerField = ClassWriter.class.getDeclaredField("fileManager");
+ fileManagerField.setAccessible(true);
+ fileManagerField.set(writer, newFiler);
+ }
+ catch (Exception e) {}
+ }
+ catch (Exception e) {
+ }
+ }
private void forceMultipleRoundsInNetBeansEditor() {
try {