aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2010-08-05 23:44:48 +0200
committerRoel Spilker <r.spilker@gmail.com>2010-08-05 23:44:48 +0200
commitd41a282e50a8348b904951893d98239095a7ccab (patch)
tree687dc54dde63a3c8d2ac00d48d1be68d8eedaf78
parent53650295f04edfbb7a48d4bdf3c790b11a5beeca (diff)
downloadlombok-d41a282e50a8348b904951893d98239095a7ccab.tar.gz
lombok-d41a282e50a8348b904951893d98239095a7ccab.tar.bz2
lombok-d41a282e50a8348b904951893d98239095a7ccab.zip
Moved wrapOutputStream to PostCompiler
-rw-r--r--src/core/lombok/core/PostCompiler.java25
-rw-r--r--src/core/lombok/javac/apt/InterceptingJavaFileObject.java25
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 {