diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | src/core/lombok/javac/apt/LombokFileObjects.java | 106 | ||||
-rw-r--r-- | src/stubs/com/sun/tools/javac/file/BaseFileManager.java | 5 |
3 files changed, 100 insertions, 12 deletions
@@ -20,6 +20,7 @@ Robbert Jan Grootjans <grootjans@gmail.com> Roel Spilker <r.spilker@gmail.com> Sander Koning <askoning@gmail.com> Szymon Pacanowski <spacanowski@gmail.com> +Takuya Murakami <tmurakam@tmurakam.org> Taiki Sugawara <buzz.taiki@gmail.com> Thomas Darimont <thomas.darimont@gmail.com> Yun Zhi Lin <yun@yunspace.com> diff --git a/src/core/lombok/javac/apt/LombokFileObjects.java b/src/core/lombok/javac/apt/LombokFileObjects.java index cb2036e9..d0d67b17 100644 --- a/src/core/lombok/javac/apt/LombokFileObjects.java +++ b/src/core/lombok/javac/apt/LombokFileObjects.java @@ -22,13 +22,17 @@ package lombok.javac.apt; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Iterator; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import javax.tools.FileObject; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; import javax.tools.JavaFileObject.Kind; @@ -116,11 +120,8 @@ final class LombokFileObjects { try { Field wrappedField = Class.forName("com.sun.tools.javac.api.ClientCodeWrapper$WrappedJavaFileManager").getDeclaredField("clientJavaFileManager"); wrappedField.setAccessible(true); - JavaFileManager wrappedManager = (JavaFileManager)wrappedField.get(jfm); - Class<?> superType = Class.forName("com.sun.tools.javac.file.BaseFileManager"); - if (superType.isInstance(wrappedManager)) { - return new Java9Compiler(wrappedManager); - } + JavaFileManager wrappedManager = (JavaFileManager) wrappedField.get(jfm); + return new Java9Compiler(wrappedManager); } catch (Exception e) {} } @@ -155,25 +156,108 @@ final class LombokFileObjects { private final BaseFileManager fileManager; public Java9Compiler(JavaFileManager jfm) { - fileManager = (BaseFileManager) jfm; + fileManager = asBaseFileManager(jfm); } @Override public JavaFileObject wrap(LombokFileObject fileObject) { + return new Javac9BaseFileObjectWrapper(fileManager, toPath(fileObject), fileObject); + } + + @Override public Method getDecoderMethod() { + return null; + } + + private static Path toPath(LombokFileObject fileObject) { URI uri = fileObject.toUri(); if (uri.getScheme() == null) { uri = URI.create("file:///" + uri); } - Path path; try { - path = Paths.get(uri); + return Paths.get(uri); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Problems in URI '" + uri + "' (" + fileObject.toUri() + ")", e); } - return new Javac9BaseFileObjectWrapper(fileManager, path, fileObject); } - @Override public Method getDecoderMethod() { - throw new UnsupportedOperationException(); + private static BaseFileManager asBaseFileManager(JavaFileManager jfm) { + if (jfm instanceof BaseFileManager) { + return (BaseFileManager) jfm; + } + return new FileManagerWrapper(jfm); + } + + static class FileManagerWrapper extends BaseFileManager { + JavaFileManager manager; + + public FileManagerWrapper(JavaFileManager manager) { + super(null); + this.manager = manager; + } + + @Override + public int isSupportedOption(String option) { + return manager.isSupportedOption(option); + } + + @Override + public ClassLoader getClassLoader(Location location) { + return manager.getClassLoader(location); + } + + @Override + public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException { + return manager.list(location, packageName, kinds, recurse); + } + + @Override + public String inferBinaryName(Location location, JavaFileObject file) { + return manager.inferBinaryName(location, file); + } + + @Override + public boolean isSameFile(FileObject a, FileObject b) { + return manager.isSameFile(a, b); + } + + @Override + public boolean handleOption(String current, Iterator<String> remaining) { + return manager.handleOption(current, remaining); + } + + @Override + public boolean hasLocation(Location location) { + return manager.hasLocation(location); + } + + @Override + public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException { + return manager.getJavaFileForInput(location, className, kind); + } + + @Override + public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException { + return manager.getJavaFileForOutput(location, className, kind, sibling); + } + + @Override + public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { + return manager.getFileForInput(location, packageName, relativeName); + } + + @Override + public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { + return manager.getFileForOutput(location, packageName, relativeName, sibling); + } + + @Override + public void flush() throws IOException { + manager.flush(); + } + + @Override + public void close() throws IOException { + manager.close(); + } } } } diff --git a/src/stubs/com/sun/tools/javac/file/BaseFileManager.java b/src/stubs/com/sun/tools/javac/file/BaseFileManager.java index 7a2293d5..df24ca3c 100644 --- a/src/stubs/com/sun/tools/javac/file/BaseFileManager.java +++ b/src/stubs/com/sun/tools/javac/file/BaseFileManager.java @@ -4,5 +4,8 @@ package com.sun.tools.javac.file; import javax.tools.JavaFileManager; +import java.nio.charset.Charset; -public abstract class BaseFileManager implements JavaFileManager{} +public abstract class BaseFileManager implements JavaFileManager { + protected BaseFileManager(Charset charset) {} +} |