58 import static java.nio.file.FileVisitOption.*; |
58 import static java.nio.file.FileVisitOption.*; |
59 import static javax.tools.StandardLocation.*; |
59 import static javax.tools.StandardLocation.*; |
60 |
60 |
61 import com.sun.tools.javac.util.BaseFileManager; |
61 import com.sun.tools.javac.util.BaseFileManager; |
62 import com.sun.tools.javac.util.Context; |
62 import com.sun.tools.javac.util.Context; |
|
63 import com.sun.tools.javac.util.DefinedBy; |
|
64 import com.sun.tools.javac.util.DefinedBy.Api; |
63 import com.sun.tools.javac.util.List; |
65 import com.sun.tools.javac.util.List; |
64 import com.sun.tools.javac.util.ListBuffer; |
66 import com.sun.tools.javac.util.ListBuffer; |
65 |
67 |
66 import static com.sun.tools.javac.main.Option.*; |
68 import static com.sun.tools.javac.main.Option.*; |
67 |
69 |
136 @Override |
138 @Override |
137 public void setDefaultFileSystem(FileSystem fs) { |
139 public void setDefaultFileSystem(FileSystem fs) { |
138 defaultFileSystem = fs; |
140 defaultFileSystem = fs; |
139 } |
141 } |
140 |
142 |
141 @Override |
143 @Override @DefinedBy(Api.COMPILER) |
142 public void flush() throws IOException { |
144 public void flush() throws IOException { |
143 contentCache.clear(); |
145 contentCache.clear(); |
144 } |
146 } |
145 |
147 |
146 @Override |
148 @Override @DefinedBy(Api.COMPILER) |
147 public void close() throws IOException { |
149 public void close() throws IOException { |
148 for (FileSystem fs: fileSystems.values()) |
150 for (FileSystem fs: fileSystems.values()) |
149 fs.close(); |
151 fs.close(); |
150 } |
152 } |
151 |
153 |
152 @Override |
154 @Override @DefinedBy(Api.COMPILER) |
153 public ClassLoader getClassLoader(Location location) { |
155 public ClassLoader getClassLoader(Location location) { |
154 nullCheck(location); |
156 nullCheck(location); |
155 Iterable<? extends Path> path = getLocation(location); |
157 Iterable<? extends Path> path = getLocation(location); |
156 if (path == null) |
158 if (path == null) |
157 return null; |
159 return null; |
167 return getClassLoader(lb.toArray(new URL[lb.size()])); |
169 return getClassLoader(lb.toArray(new URL[lb.size()])); |
168 } |
170 } |
169 |
171 |
170 // <editor-fold defaultstate="collapsed" desc="Location handling"> |
172 // <editor-fold defaultstate="collapsed" desc="Location handling"> |
171 |
173 |
|
174 @DefinedBy(Api.COMPILER) |
172 public boolean hasLocation(Location location) { |
175 public boolean hasLocation(Location location) { |
173 return (getLocation(location) != null); |
176 return (getLocation(location) != null); |
174 } |
177 } |
175 |
178 |
176 public Iterable<? extends Path> getLocation(Location location) { |
179 public Iterable<? extends Path> getLocation(Location location) { |
279 if (!(fo instanceof PathFileObject)) |
282 if (!(fo instanceof PathFileObject)) |
280 throw new IllegalArgumentException(); |
283 throw new IllegalArgumentException(); |
281 return ((PathFileObject) fo).getPath(); |
284 return ((PathFileObject) fo).getPath(); |
282 } |
285 } |
283 |
286 |
284 @Override |
287 @Override @DefinedBy(Api.COMPILER) |
285 public boolean isSameFile(FileObject a, FileObject b) { |
288 public boolean isSameFile(FileObject a, FileObject b) { |
286 nullCheck(a); |
289 nullCheck(a); |
287 nullCheck(b); |
290 nullCheck(b); |
288 if (!(a instanceof PathFileObject)) |
291 if (!(a instanceof PathFileObject)) |
289 throw new IllegalArgumentException("Not supported: " + a); |
292 throw new IllegalArgumentException("Not supported: " + a); |
290 if (!(b instanceof PathFileObject)) |
293 if (!(b instanceof PathFileObject)) |
291 throw new IllegalArgumentException("Not supported: " + b); |
294 throw new IllegalArgumentException("Not supported: " + b); |
292 return ((PathFileObject) a).isSameFile((PathFileObject) b); |
295 return ((PathFileObject) a).isSameFile((PathFileObject) b); |
293 } |
296 } |
294 |
297 |
295 @Override |
298 @Override @DefinedBy(Api.COMPILER) |
296 public Iterable<JavaFileObject> list(Location location, |
299 public Iterable<JavaFileObject> list(Location location, |
297 String packageName, Set<Kind> kinds, boolean recurse) |
300 String packageName, Set<Kind> kinds, boolean recurse) |
298 throws IOException { |
301 throws IOException { |
299 // validatePackageName(packageName); |
302 // validatePackageName(packageName); |
300 nullCheck(packageName); |
303 nullCheck(packageName); |
400 @Override |
403 @Override |
401 public Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths) { |
404 public Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths) { |
402 return getJavaFileObjectsFromPaths(Arrays.asList(nullCheck(paths))); |
405 return getJavaFileObjectsFromPaths(Arrays.asList(nullCheck(paths))); |
403 } |
406 } |
404 |
407 |
405 @Override |
408 @Override @DefinedBy(Api.COMPILER) |
406 public JavaFileObject getJavaFileForInput(Location location, |
409 public JavaFileObject getJavaFileForInput(Location location, |
407 String className, Kind kind) throws IOException { |
410 String className, Kind kind) throws IOException { |
408 return getFileForInput(location, getRelativePath(className, kind)); |
411 return getFileForInput(location, getRelativePath(className, kind)); |
409 } |
412 } |
410 |
413 |
411 @Override |
414 @Override @DefinedBy(Api.COMPILER) |
412 public FileObject getFileForInput(Location location, |
415 public FileObject getFileForInput(Location location, |
413 String packageName, String relativeName) throws IOException { |
416 String packageName, String relativeName) throws IOException { |
414 return getFileForInput(location, getRelativePath(packageName, relativeName)); |
417 return getFileForInput(location, getRelativePath(packageName, relativeName)); |
415 } |
418 } |
416 |
419 |
431 } |
434 } |
432 } |
435 } |
433 return null; |
436 return null; |
434 } |
437 } |
435 |
438 |
436 @Override |
439 @Override @DefinedBy(Api.COMPILER) |
437 public JavaFileObject getJavaFileForOutput(Location location, |
440 public JavaFileObject getJavaFileForOutput(Location location, |
438 String className, Kind kind, FileObject sibling) throws IOException { |
441 String className, Kind kind, FileObject sibling) throws IOException { |
439 return getFileForOutput(location, getRelativePath(className, kind), sibling); |
442 return getFileForOutput(location, getRelativePath(className, kind), sibling); |
440 } |
443 } |
441 |
444 |
442 @Override |
445 @Override @DefinedBy(Api.COMPILER) |
443 public FileObject getFileForOutput(Location location, String packageName, |
446 public FileObject getFileForOutput(Location location, String packageName, |
444 String relativeName, FileObject sibling) |
447 String relativeName, FileObject sibling) |
445 throws IOException { |
448 throws IOException { |
446 return getFileForOutput(location, getRelativePath(packageName, relativeName), sibling); |
449 return getFileForOutput(location, getRelativePath(packageName, relativeName), sibling); |
447 } |
450 } |
472 return PathFileObject.createSimplePathFileObject(this, file); |
475 return PathFileObject.createSimplePathFileObject(this, file); |
473 } |
476 } |
474 |
477 |
475 } |
478 } |
476 |
479 |
477 @Override |
480 @Override @DefinedBy(Api.COMPILER) |
478 public String inferBinaryName(Location location, JavaFileObject fo) { |
481 public String inferBinaryName(Location location, JavaFileObject fo) { |
479 nullCheck(fo); |
482 nullCheck(fo); |
480 // Need to match the path semantics of list(location, ...) |
483 // Need to match the path semantics of list(location, ...) |
481 Iterable<? extends Path> paths = getLocation(location); |
484 Iterable<? extends Path> paths = getLocation(location); |
482 if (paths == null) { |
485 if (paths == null) { |