diff options
4 files changed, 47 insertions, 14 deletions
diff --git a/src/core/lombok/javac/apt/InterceptingJavaFileManager.java b/src/core/lombok/javac/apt/InterceptingJavaFileManager.java index 87aeb927..979c1279 100644 --- a/src/core/lombok/javac/apt/InterceptingJavaFileManager.java +++ b/src/core/lombok/javac/apt/InterceptingJavaFileManager.java @@ -43,12 +43,12 @@ final class InterceptingJavaFileManager extends ForwardingJavaFileManager<JavaFi @Override public JavaFileObject getJavaFileForOutput(Location location, String className, final Kind kind, FileObject sibling) throws IOException { if (className.startsWith("lombok.dummy.ForceNewRound")) { final String name = className.replace(".", "/") + kind.extension; - return LombokFileObjects.createEmpty(fileManager, name, kind); + return LombokFileObjects.createEmpty(name, kind); } JavaFileObject fileObject = fileManager.getJavaFileForOutput(location, className, kind, sibling); if (kind != Kind.CLASS) { return fileObject; } - return LombokFileObjects.createIntercepting(fileManager, fileObject, className, diagnostics); + return LombokFileObjects.createIntercepting(fileObject, className, diagnostics); } }
\ No newline at end of file diff --git a/src/core/lombok/javac/apt/Javac7BaseFileObjectWrapper.java b/src/core/lombok/javac/apt/Javac7BaseFileObjectWrapper.java index 81cf834a..354e2e01 100644 --- a/src/core/lombok/javac/apt/Javac7BaseFileObjectWrapper.java +++ b/src/core/lombok/javac/apt/Javac7BaseFileObjectWrapper.java @@ -36,8 +36,8 @@ import javax.lang.model.element.NestingKind; class Javac7BaseFileObjectWrapper extends com.sun.tools.javac.file.BaseFileObject { private final LombokFileObject delegate; - public Javac7BaseFileObjectWrapper(com.sun.tools.javac.file.JavacFileManager jfm, LombokFileObject delegate) { - super(jfm); + public Javac7BaseFileObjectWrapper(LombokFileObject delegate) { + super(null); this.delegate = delegate; } diff --git a/src/core/lombok/javac/apt/LombokFileObjects.java b/src/core/lombok/javac/apt/LombokFileObjects.java index b868c847..ef1a6b56 100644 --- a/src/core/lombok/javac/apt/LombokFileObjects.java +++ b/src/core/lombok/javac/apt/LombokFileObjects.java @@ -24,7 +24,6 @@ package lombok.javac.apt; import java.lang.reflect.Method; -import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; import javax.tools.JavaFileObject.Kind; @@ -36,17 +35,17 @@ final class LombokFileObjects { private enum Compiler { JAVAC6 { - @Override public JavaFileObject wrap(JavaFileManager fileManager, LombokFileObject fileObject) { + @Override public JavaFileObject wrap(LombokFileObject fileObject) { return new Javac6BaseFileObjectWrapper(fileObject); } }, JAVAC7 { - @Override public JavaFileObject wrap(JavaFileManager fileManager, LombokFileObject fileObject) { - return new Javac7BaseFileObjectWrapper((com.sun.tools.javac.file.JavacFileManager)fileManager, fileObject); + @Override public JavaFileObject wrap(LombokFileObject fileObject) { + return new Javac7BaseFileObjectWrapper(fileObject); } }; - abstract JavaFileObject wrap(JavaFileManager fileManager, LombokFileObject fileObject); + abstract JavaFileObject wrap(LombokFileObject fileObject); } private static final Compiler compiler; @@ -85,11 +84,11 @@ final class LombokFileObjects { private LombokFileObjects() {} - static JavaFileObject createEmpty(JavaFileManager fileManager, String name, Kind kind) { - return compiler.wrap(fileManager, new EmptyLombokFileObject(name, kind)); + static JavaFileObject createEmpty(String name, Kind kind) { + return compiler.wrap(new EmptyLombokFileObject(name, kind)); } - static JavaFileObject createIntercepting(JavaFileManager fileManager, JavaFileObject delegate, String fileName, DiagnosticsReceiver diagnostics) { - return compiler.wrap(fileManager, new InterceptingJavaFileObject(delegate, fileName, diagnostics, decoderMethod)); + static JavaFileObject createIntercepting(JavaFileObject delegate, String fileName, DiagnosticsReceiver diagnostics) { + return compiler.wrap(new InterceptingJavaFileObject(delegate, fileName, diagnostics, decoderMethod)); } } diff --git a/src/core/lombok/javac/apt/Processor.java b/src/core/lombok/javac/apt/Processor.java index b5d5c81c..ee9a9704 100644 --- a/src/core/lombok/javac/apt/Processor.java +++ b/src/core/lombok/javac/apt/Processor.java @@ -87,8 +87,9 @@ public class Processor extends AbstractProcessor { private void placePostCompileAndDontMakeForceRoundDummiesHook() { stopJavacProcessingEnvironmentFromClosingOurClassloader(); + forceMultipleRoundsInNetBeansEditor(); Context context = processingEnv.getContext(); - + disablePartialReparseInNetBeansEditor(context); try { Method keyMethod = Context.class.getDeclaredMethod("key", Class.class); keyMethod.setAccessible(true); @@ -114,6 +115,39 @@ public class Processor extends AbstractProcessor { } } + private void forceMultipleRoundsInNetBeansEditor() { + try { + Field f = JavacProcessingEnvironment.class.getDeclaredField("isBackgroundCompilation"); + f.setAccessible(true); + f.set(processingEnv, true); + } catch (NoSuchFieldException e) { + // only NetBeans has it + } catch (Throwable t) { + throw Lombok.sneakyThrow(t); + } + } + + private void disablePartialReparseInNetBeansEditor(Context context) { + try { + Class<?> cancelServiceClass = Class.forName("com.sun.tools.javac.util.CancelService"); + Method cancelServiceInstace = cancelServiceClass.getDeclaredMethod("instance", Context.class); + Object cancelService = cancelServiceInstace.invoke(null, context); + if (cancelService == null) return; + Field parserField = cancelService.getClass().getDeclaredField("parser"); + parserField.setAccessible(true); + Object parser = parserField.get(cancelService); + Field supportsReparseField = parser.getClass().getDeclaredField("supportsReparse"); + supportsReparseField.setAccessible(true); + supportsReparseField.set(parser, false); + } catch (ClassNotFoundException e) { + // only NetBeans has it + } catch (NoSuchFieldException e) { + // only NetBeans has it + } catch (Throwable t) { + throw Lombok.sneakyThrow(t); + } + } + private static class WrappingClassLoader extends ClassLoader { private final ClassLoader parent; |