diff options
Diffstat (limited to 'src/core/lombok')
-rw-r--r-- | src/core/lombok/core/PostCompiler.java | 25 | ||||
-rw-r--r-- | src/core/lombok/javac/apt/InterceptingJavaFileObject.java | 25 |
2 files changed, 26 insertions, 24 deletions
diff --git a/src/core/lombok/core/PostCompiler.java b/src/core/lombok/core/PostCompiler.java index 07cfc04d..52568286 100644 --- a/src/core/lombok/core/PostCompiler.java +++ b/src/core/lombok/core/PostCompiler.java @@ -21,7 +21,9 @@ */ package lombok.core; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.Collections; import java.util.List; @@ -55,4 +57,27 @@ public final class PostCompiler { diagnostics.addWarning("Could not load post-compile transformers: " + e.getMessage()); } } + + public static OutputStream wrapOutputStream(final OutputStream originalStream, final String className, final DiagnosticsReceiver diagnostics) throws IOException { + return new ByteArrayOutputStream() { + @Override public void close() throws IOException { + // no need to call super + byte[] original = toByteArray(); + byte[] copy = null; + try { + copy = applyTransformations(original, className, diagnostics); + } catch (Exception e) { + diagnostics.addWarning(String.format("Error during the transformation of '%s'; no post-compilation has been applied", className)); + } + + if (copy == null) { + copy = original; + } + + // Exceptions below should bubble + originalStream.write(copy); + originalStream.close(); + } + }; + } } diff --git a/src/core/lombok/javac/apt/InterceptingJavaFileObject.java b/src/core/lombok/javac/apt/InterceptingJavaFileObject.java index 1e07440a..c0d3565c 100644 --- a/src/core/lombok/javac/apt/InterceptingJavaFileObject.java +++ b/src/core/lombok/javac/apt/InterceptingJavaFileObject.java @@ -21,7 +21,6 @@ */ package lombok.javac.apt; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -48,29 +47,7 @@ final class InterceptingJavaFileObject implements JavaFileObject { } public OutputStream openOutputStream() throws IOException { - // Open it first to make sure we throw an exception if that fails. - final OutputStream originalStream = delegate.openOutputStream(); - - return new ByteArrayOutputStream() { - @Override public void close() throws IOException { - // no need to call super - byte[] original = toByteArray(); - byte[] copy = null; - try { - copy = PostCompiler.applyTransformations(original, className, diagnostics); - } catch (Exception e) { - diagnostics.addWarning(String.format("Error during the transformation of '%s'; no post-compilation has been applied", className)); - } - - if (copy == null) { - copy = original; - } - - // Exceptions below should bubble - originalStream.write(copy); - originalStream.close(); - } - }; + return PostCompiler.wrapOutputStream(delegate.openOutputStream(), className, diagnostics); } public Writer openWriter() throws IOException { |