diff options
author | Takuya Murakami <tmurakam@tmurakam.org> | 2017-10-16 23:38:57 +0900 |
---|---|---|
committer | Takuya Murakami <tmurakam@tmurakam.org> | 2017-10-16 23:41:28 +0900 |
commit | 4298d97be8c2a3e1034619601719a493fcf17d48 (patch) | |
tree | d7c1fd34b3c0ea6bd9faad8a21adbac8e2c8c750 /src/core | |
parent | f55ebbe710f8d8065520225dc78ebf6d7ecd7616 (diff) | |
download | lombok-4298d97be8c2a3e1034619601719a493fcf17d48.tar.gz lombok-4298d97be8c2a3e1034619601719a493fcf17d48.tar.bz2 lombok-4298d97be8c2a3e1034619601719a493fcf17d48.zip |
LombokFileObjects: get encoding from wrappedManager.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/lombok/javac/apt/LombokFileObjects.java | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/core/lombok/javac/apt/LombokFileObjects.java b/src/core/lombok/javac/apt/LombokFileObjects.java index 8b6d4c2e..917bfe9e 100644 --- a/src/core/lombok/javac/apt/LombokFileObjects.java +++ b/src/core/lombok/javac/apt/LombokFileObjects.java @@ -26,7 +26,7 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URI; -import java.nio.charset.StandardCharsets; +import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Iterator; @@ -37,6 +37,7 @@ import javax.tools.FileObject; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; import javax.tools.JavaFileObject.Kind; +import javax.tools.StandardLocation; import lombok.core.DiagnosticsReceiver; @@ -126,7 +127,8 @@ final class LombokFileObjects { if (superType.isInstance(wrappedManager)) { return new Java9Compiler(wrappedManager); } else { - return new Java9Compiler(new BaseFileManagerWrapper(wrappedManager)); + String encoding = getEncodingOf(wrappedManager); + return new Java9Compiler(new BaseFileManagerWrapper(wrappedManager, encoding != null ? Charset.forName(encoding) : null)); } } catch (Exception e) {} @@ -150,11 +152,23 @@ final class LombokFileObjects { throw new IllegalArgumentException(sb.toString()); } + private static String getEncodingOf(JavaFileManager manager) { + try { + // FileObject may be instance of org.jetbrains.jps.javac.OutputFileObject + FileObject fo = manager.getFileForOutput(StandardLocation.CLASS_OUTPUT, "", "dummy", null); + Field encodingField = fo.getClass().getDeclaredField("myEncodingName"); + encodingField.setAccessible(true); + return (String)encodingField.get(fo); + } catch (Exception e) { + return null; + } + } + static class BaseFileManagerWrapper extends BaseFileManager { JavaFileManager manager; - public BaseFileManagerWrapper(JavaFileManager manager) { - super(null); // use default encoding + public BaseFileManagerWrapper(JavaFileManager manager, Charset charset) { + super(charset); this.manager = manager; } |