aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/apt/InterceptingJavaFileManager.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2010-12-31 17:14:47 -0300
committerReinier Zwitserloot <reinier@zwitserloot.com>2010-12-31 18:19:20 -0300
commitb9b13f8fcc9412874fcd068629bf36bc9a15cb7b (patch)
treefd5e60b02236c822b4bb1a5bffdd2beb98566ab9 /src/core/lombok/javac/apt/InterceptingJavaFileManager.java
parent983d487b59d3fc30c19fa9bd1ab472468c0958d1 (diff)
downloadlombok-b9b13f8fcc9412874fcd068629bf36bc9a15cb7b.tar.gz
lombok-b9b13f8fcc9412874fcd068629bf36bc9a15cb7b.tar.bz2
lombok-b9b13f8fcc9412874fcd068629bf36bc9a15cb7b.zip
Using annotation processors with lombok sometimes results in a 'Not Supported: DummyRound0' error. This fixes it.
Fixes issue #176
Diffstat (limited to 'src/core/lombok/javac/apt/InterceptingJavaFileManager.java')
-rw-r--r--src/core/lombok/javac/apt/InterceptingJavaFileManager.java74
1 files changed, 68 insertions, 6 deletions
diff --git a/src/core/lombok/javac/apt/InterceptingJavaFileManager.java b/src/core/lombok/javac/apt/InterceptingJavaFileManager.java
index 738804ea..ef741c48 100644
--- a/src/core/lombok/javac/apt/InterceptingJavaFileManager.java
+++ b/src/core/lombok/javac/apt/InterceptingJavaFileManager.java
@@ -26,16 +26,26 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
import java.net.URI;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
import java.util.Iterator;
import java.util.Set;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.NestingKind;
import javax.tools.FileObject;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
-import javax.tools.SimpleJavaFileObject;
import javax.tools.JavaFileObject.Kind;
+import com.sun.tools.javac.util.BaseFileObject;
+
import lombok.core.DiagnosticsReceiver;
final class InterceptingJavaFileManager implements JavaFileManager {
@@ -47,21 +57,73 @@ final class InterceptingJavaFileManager implements JavaFileManager {
this.diagnostics = diagnostics;
}
- @Override public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
+ @Override public JavaFileObject getJavaFileForOutput(Location location, String className, final Kind kind, FileObject sibling) throws IOException {
if (className.startsWith("lombok.dummy.ForceNewRound")) {
- String name = className.replace(".", "/") + kind.extension;
- return new SimpleJavaFileObject(URI.create(name), kind) {
- @Override public OutputStream openOutputStream() throws IOException {
- return new ByteArrayOutputStream();
+ final String name = className.replace(".", "/") + kind.extension;
+ // Can't use SimpleJavaFileObject so we copy/paste most of its content here, because javac doesn't follow the interface,
+ // and casts to its own BaseFileObject type. D'oh!
+ return new BaseFileObject() {
+ @Override public boolean isNameCompatible(String simpleName, Kind kind) {
+ String baseName = simpleName + kind.extension;
+ return kind.equals(getKind())
+ && (baseName.equals(toUri().getPath())
+ || toUri().getPath().endsWith("/" + baseName));
+ }
+
+ @Override public URI toUri() {
+ return URI.create(name);
}
@Override public InputStream openInputStream() throws IOException {
return new ByteArrayInputStream(new byte[0]);
}
+ @Override public OutputStream openOutputStream() throws IOException {
+ return new ByteArrayOutputStream();
+ }
+
@Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return "";
}
+
+ @Override public Writer openWriter() throws IOException {
+ return new OutputStreamWriter(openOutputStream());
+ }
+
+ @Override public long getLastModified() {
+ return 0L;
+ }
+
+ @Override public boolean delete() {
+ return false;
+ }
+
+ @Override public Kind getKind() {
+ return kind;
+ }
+
+ @SuppressWarnings("all")
+ @Override public String getName() {
+ return toUri().getPath();
+ }
+
+ @Override public NestingKind getNestingKind() {
+ return null;
+ }
+
+ @Override public Modifier getAccessLevel() {
+ return null;
+ }
+
+ @Override public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
+ return new StringReader("");
+ }
+
+ protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
+ CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
+ CodingErrorAction action = ignoreEncodingErrors ? CodingErrorAction.REPLACE : CodingErrorAction.REPORT;
+ return decoder.onMalformedInput(action).onUnmappableCharacter(action);
+ }
};
}
JavaFileObject fileObject = delegate.getJavaFileForOutput(location, className, kind, sibling);