public class JavacPathFileManager extends BaseFileManager implements PathFileManager
Just as a Path is somewhat analagous to a File, so too is this JavacPathFileManager analogous to JavacFileManager, as it relates to the support of FileObjects based on File objects (i.e. just RegularFileObject, not ZipFileObject and its variants.)
The default values for the standard locations supported by this file
manager are the same as the default values provided by JavacFileManager --
i.e. as determined by the javac.file.Paths class. To override these values,
call setLocation(javax.tools.JavaFileManager.Location, java.lang.Iterable<? extends java.nio.file.Path>)
.
To reduce confusion with Path objects, the locations such as "class path", "source path", etc, are generically referred to here as "search paths".
This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
BaseFileManager.ContentCacheEntry
JavaFileManager.Location
Modifier and Type | Field and Description |
---|---|
protected FileSystem |
defaultFileSystem |
charset, classLoaderClass, contentCache, locations, log, options
Constructor and Description |
---|
JavacPathFileManager(Context context,
boolean register,
Charset charset)
Create a JavacPathFileManager using a given context, optionally registering
it as the JavaFileManager for that context.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Releases any resources opened by this file manager directly or
indirectly.
|
void |
flush()
Flushes any resources opened for output by this file manager
directly or indirectly.
|
ClassLoader |
getClassLoader(JavaFileManager.Location location)
Gets a class loader for loading plug-ins from the given
location.
|
FileSystem |
getDefaultFileSystem()
Get the default file system used to create paths.
|
FileObject |
getFileForInput(JavaFileManager.Location location,
String packageName,
String relativeName)
Gets a file object for input
representing the specified relative
name in the specified package in the given location.
|
FileObject |
getFileForOutput(JavaFileManager.Location location,
String packageName,
String relativeName,
FileObject sibling)
Gets a file object for output
representing the specified relative
name in the specified package in the given location.
|
JavaFileObject |
getJavaFileForInput(JavaFileManager.Location location,
String className,
JavaFileObject.Kind kind)
Gets a file object for input
representing the specified class of the specified kind in the
given location.
|
JavaFileObject |
getJavaFileForOutput(JavaFileManager.Location location,
String className,
JavaFileObject.Kind kind,
FileObject sibling)
Gets a file object for output
representing the specified class of the specified kind in the
given location.
|
Iterable<? extends JavaFileObject> |
getJavaFileObjects(Path... paths)
Get file objects representing the given paths.
|
Iterable<? extends JavaFileObject> |
getJavaFileObjectsFromPaths(Iterable<? extends Path> paths)
Get file objects representing the given files.
|
Iterable<? extends Path> |
getLocation(JavaFileManager.Location location)
Get the search path associated with the given location.
|
Path |
getPath(FileObject fo)
Return the Path for a file object that has been obtained from this
file manager.
|
boolean |
hasLocation(JavaFileManager.Location location)
Determines if a location is known to this file manager.
|
String |
inferBinaryName(JavaFileManager.Location location,
JavaFileObject fo)
Infers a binary name of a file object based on a location.
|
boolean |
isDefaultBootClassPath() |
boolean |
isSameFile(FileObject a,
FileObject b)
Compares two file objects and return true if they represent the
same underlying object.
|
Iterable<JavaFileObject> |
list(JavaFileManager.Location location,
String packageName,
Set<JavaFileObject.Kind> kinds,
boolean recurse)
Lists all file objects matching the given criteria in the given
location.
|
void |
setContext(Context context)
Set the context for JavacPathFileManager.
|
void |
setDefaultFileSystem(FileSystem fs)
Set the default file system used to create paths.
|
void |
setLocation(JavaFileManager.Location location,
Iterable<? extends Path> searchPath)
Associate the given search path with the given location.
|
cache, createLocations, decode, flushCache, getCachedContent, getClassLoader, getDecoder, getEncodingName, getKind, getSource, handleOption, isSupportedOption, makeByteBuffer, nullCheck, nullCheck, recycleByteBuffer
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handleOption
isSupportedOption
protected FileSystem defaultFileSystem
public void setContext(Context context)
setContext
in class BaseFileManager
public FileSystem getDefaultFileSystem()
PathFileManager
FileSystems.getDefault()
.getDefaultFileSystem
in interface PathFileManager
public void setDefaultFileSystem(FileSystem fs)
PathFileManager
setDefaultFileSystem
in interface PathFileManager
fs
- the default file system used to create any new paths.public void flush() throws IOException
JavaFileManager
flush
in interface Flushable
flush
in interface JavaFileManager
IOException
- if an I/O error occurredJavaFileManager.close()
public void close() throws IOException
JavaFileManager
close
in interface Closeable
close
in interface AutoCloseable
close
in interface JavaFileManager
IOException
- if an I/O error occurredJavaFileManager.flush()
public ClassLoader getClassLoader(JavaFileManager.Location location)
JavaFileManager
ANNOTATION_PROCESSOR_PATH
location.getClassLoader
in interface JavaFileManager
location
- a locationnull
if loading plug-ins from the given location is disabled or if
the location is not knownpublic boolean isDefaultBootClassPath()
isDefaultBootClassPath
in class BaseFileManager
public boolean hasLocation(JavaFileManager.Location location)
JavaFileManager
hasLocation
in interface JavaFileManager
location
- a locationpublic Iterable<? extends Path> getLocation(JavaFileManager.Location location)
PathFileManager
getLocation
in interface PathFileManager
location
- a locationnull
if this location has no
associated search pathPathFileManager.setLocation(javax.tools.JavaFileManager.Location, java.lang.Iterable<? extends java.nio.file.Path>)
public void setLocation(JavaFileManager.Location location, Iterable<? extends Path> searchPath) throws IOException
PathFileManager
setLocation
in interface PathFileManager
location
- a locationsearchPath
- a list of files, if null
use the default
search path for this locationIOException
- if location is an output location and searchpath
does not represent an existing directoryPathFileManager.getLocation(javax.tools.JavaFileManager.Location)
public Path getPath(FileObject fo)
PathFileManager
getPath
in interface PathFileManager
fo
- A file object that has been obtained from this file manager.public boolean isSameFile(FileObject a, FileObject b)
JavaFileManager
isSameFile
in interface JavaFileManager
a
- a file objectb
- a file objectpublic Iterable<JavaFileObject> list(JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException
JavaFileManager
Note: even if the given location is unknown to this file
manager, it may not return null
. Also, an unknown
location may not cause an exception.
list
in interface JavaFileManager
location
- a locationpackageName
- a package namekinds
- return objects only of these kindsrecurse
- if true include "subpackages"IOException
- if an I/O error occurred, or if JavaFileManager.close()
has been called and this file manager cannot be
reopenedpublic Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(Iterable<? extends Path> paths)
PathFileManager
getJavaFileObjectsFromPaths
in interface PathFileManager
paths
- a list of pathspublic Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths)
PathFileManager
getJavaFileObjectsFromPaths(Arrays.asList(paths))
getJavaFileObjects
in interface PathFileManager
paths
- an array of pathspublic JavaFileObject getJavaFileForInput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind) throws IOException
JavaFileManager
getJavaFileForInput
in interface JavaFileManager
location
- a locationclassName
- the name of a classkind
- the kind of file, must be one of SOURCE
or CLASS
null
if the
file does not existIOException
- if an I/O error occurred, or if JavaFileManager.close()
has been called and this file manager cannot be
reopenedpublic FileObject getFileForInput(JavaFileManager.Location location, String packageName, String relativeName) throws IOException
JavaFileManager
If the returned object represents a source or class file, it must be an instance
of JavaFileObject
.
Informally, the file object returned by this method is located in the concatenation of the location, package name, and relative name. For example, to locate the properties file "resources/compiler.properties" in the package "com.sun.tools.javac" in the SOURCE_PATH location, this method might be called like so:
getFileForInput(SOURCE_PATH, "com.sun.tools.javac", "resources/compiler.properties");
If the call was executed on Windows, with SOURCE_PATH set to
"C:\Documents and Settings\UncleBob\src\share\classes"
,
a valid result would be a file object representing the file
"C:\Documents and Settings\UncleBob\src\share\classes\com\sun\tools\javac\resources\compiler.properties"
.
getFileForInput
in interface JavaFileManager
location
- a locationpackageName
- a package namerelativeName
- a relative namenull
if the file
does not existIOException
- if an I/O error occurred, or if JavaFileManager.close()
has been called and this file manager cannot be
reopenedpublic JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException
JavaFileManager
Optionally, this file manager might consider the sibling as a hint for where to place the output. The exact semantics of this hint is unspecified. The JDK compiler, javac, for example, will place class files in the same directories as originating source files unless a class file output directory is provided. To facilitate this behavior, javac might provide the originating source file as sibling when calling this method.
getJavaFileForOutput
in interface JavaFileManager
location
- a locationclassName
- the name of a classkind
- the kind of file, must be one of SOURCE
or CLASS
sibling
- a file object to be used as hint for placement;
might be null
IOException
- if an I/O error occurred, or if JavaFileManager.close()
has been called and this file manager cannot be
reopenedpublic FileObject getFileForOutput(JavaFileManager.Location location, String packageName, String relativeName, FileObject sibling) throws IOException
JavaFileManager
Optionally, this file manager might consider the sibling as a hint for where to place the output. The exact semantics of this hint is unspecified. The JDK compiler, javac, for example, will place class files in the same directories as originating source files unless a class file output directory is provided. To facilitate this behavior, javac might provide the originating source file as sibling when calling this method.
If the returned object represents a source or class file, it must be an instance
of JavaFileObject
.
Informally, the file object returned by this method is
located in the concatenation of the location, package name, and
relative name or next to the sibling argument. See getFileForInput
for an example.
getFileForOutput
in interface JavaFileManager
location
- a locationpackageName
- a package namerelativeName
- a relative namesibling
- a file object to be used as hint for placement;
might be null
IOException
- if an I/O error occurred, or if JavaFileManager.close()
has been called and this file manager cannot be
reopenedpublic String inferBinaryName(JavaFileManager.Location location, JavaFileObject fo)
JavaFileManager
inferBinaryName
in interface JavaFileManager
location
- a locationfo
- a file objectnull
the file object is not
found in the given locationCopyright © 2016. All rights reserved.