mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 08:18:29 +00:00
Moved wrapOutputStream to PostCompiler
This commit is contained in:
1 parent
53650295f0
commit
d41a282e50
2 files changed
+26
-24
No files matched your search
@@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user