|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.tools.javac.file.JavacFileManager
public class JavacFileManager
This class provides access to the source, class and other files used by the compiler and related tools.
| Nested Class Summary | |
|---|---|
static interface |
JavacFileManager.Archive
An archive provides a flat directory structure of a ZipFile by mapping directory names to lists of files (basenames). |
private static class |
JavacFileManager.ByteBufferCache
A single-element cache of direct byte buffers. |
class |
JavacFileManager.MissingArchive
|
| Nested classes/interfaces inherited from interface javax.tools.JavaFileManager |
|---|
JavaFileManager.Location |
| Field Summary | |
|---|---|
(package private) java.util.Map<java.io.File,JavacFileManager.Archive> |
archives
A directory of zip files already opened. |
private JavacFileManager.ByteBufferCache |
byteBufferCache
|
protected java.nio.charset.Charset |
charset
User provided charset (through javax.tools). |
private java.io.File |
classOutDir
The standard output directory, primarily used for classes. |
private java.util.Map<JavaFileObject,java.lang.ref.SoftReference<java.nio.CharBuffer>> |
contentCache
|
private java.lang.String |
defaultEncodingName
|
private static boolean |
fileSystemIsCaseSensitive
|
private FSInfo |
fsInfo
|
protected boolean |
ignoreSymbolFile
|
private static JavacOption[] |
javacFileManagerOptions
|
protected Log |
log
The log to be used for error reporting. |
protected boolean |
mmappedIO
|
private Options |
options
|
private Paths |
paths
Encapsulates knowledge of paths |
private java.util.Set<JavaFileObject.Kind> |
sourceOrClass
|
private java.io.File |
sourceOutDir
The output directory, used when generating sources while processing annotations. |
private static java.lang.String[] |
symbolFileLocation
|
private static RelativePath.RelativeDirectory |
symbolFilePrefix
|
private java.io.File |
uninited
|
(package private) boolean |
useZipFileIndex
|
| Constructor Summary | |
|---|---|
JavacFileManager(Context context,
boolean register,
java.nio.charset.Charset charset)
Create a JavacFileManager using a given context, optionally registering it as the JavaFileManager for that context. |
|
| Method Summary | ||
|---|---|---|
(package private) void |
cache(JavaFileObject file,
java.nio.CharBuffer cb)
|
|
private boolean |
caseMapCheck(java.io.File f,
RelativePath name)
Hack to make Windows case sensitive. |
|
void |
close()
Close the JavaFileManager, releasing resources. |
|
(package private) java.nio.CharBuffer |
decode(java.nio.ByteBuffer inbuf,
boolean ignoreEncodingErrors)
Decode a ByteBuffer into a CharBuffer. |
|
void |
flush()
Flush any output resources. |
|
(package private) java.nio.CharBuffer |
getCachedContent(JavaFileObject file)
|
|
java.lang.ClassLoader |
getClassLoader(JavaFileManager.Location location)
Gets a class loader for loading plug-ins from the given location. |
|
private java.io.File |
getClassOutDir()
|
|
(package private) java.nio.charset.CharsetDecoder |
getDecoder(java.lang.String encodingName,
boolean ignoreEncodingErrors)
|
|
private java.lang.String |
getDefaultEncodingName()
|
|
protected java.lang.String |
getEncodingName()
|
|
private JavaFileObject |
getFileForInput(JavaFileManager.Location location,
RelativePath.RelativeFile name)
|
|
FileObject |
getFileForInput(JavaFileManager.Location location,
java.lang.String packageName,
java.lang.String relativeName)
Gets a file object for input representing the specified relative name in the specified package in the given location. |
|
JavaFileObject |
getFileForInput(java.lang.String name)
|
|
private JavaFileObject |
getFileForOutput(JavaFileManager.Location location,
RelativePath.RelativeFile fileName,
FileObject sibling)
|
|
FileObject |
getFileForOutput(JavaFileManager.Location location,
java.lang.String packageName,
java.lang.String relativeName,
FileObject sibling)
Gets a file object for output representing the specified relative name in the specified package in the given location. |
|
JavaFileObject |
getFileForOutput(java.lang.String classname,
JavaFileObject.Kind kind,
JavaFileObject sibling)
|
|
static java.lang.String |
getJavacBaseFileName(FileObject file)
|
|
static java.lang.String |
getJavacFileName(FileObject file)
|
|
JavaFileObject |
getJavaFileForInput(JavaFileManager.Location location,
java.lang.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,
java.lang.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. |
|
java.lang.Iterable<? extends JavaFileObject> |
getJavaFileObjects(java.io.File... files)
Gets file objects representing the given files. |
|
java.lang.Iterable<? extends JavaFileObject> |
getJavaFileObjects(java.lang.String... names)
Gets file objects representing the given file names. |
|
java.lang.Iterable<? extends JavaFileObject> |
getJavaFileObjectsFromFiles(java.lang.Iterable<? extends java.io.File> files)
Gets file objects representing the given files. |
|
java.lang.Iterable<? extends JavaFileObject> |
getJavaFileObjectsFromStrings(java.lang.Iterable<java.lang.String> names)
Gets file objects representing the given file names. |
|
protected JavaFileObject.Kind |
getKind(java.lang.String extension)
|
|
java.lang.Iterable<? extends java.io.File> |
getLocation(JavaFileManager.Location location)
Gets the path associated with the given location. |
|
private java.io.File |
getOutputDirectory(java.lang.Iterable<? extends java.io.File> path)
|
|
private java.io.File |
getOutputLocation(java.io.File dir,
OptionName defaultOptionName)
|
|
JavaFileObject |
getRegularFile(java.io.File file)
|
|
static java.lang.String |
getRelativeName(java.io.File file)
Converts a relative file name to a relative URI. |
|
protected Source |
getSource()
|
|
private java.io.File |
getSourceOutDir()
|
|
boolean |
handleOption(java.lang.String current,
java.util.Iterator<java.lang.String> remaining)
Handles one option. |
|
boolean |
hasLocation(JavaFileManager.Location location)
Determines if a location is known to this file manager. |
|
java.lang.String |
inferBinaryName(JavaFileManager.Location location,
JavaFileObject file)
Infers a binary name of a file object based on a location. |
|
protected static boolean |
isRelativeUri(java.net.URI uri)
Enforces the specification of a "relative" URI as used in getFileForInput. |
|
boolean |
isSameFile(FileObject a,
FileObject b)
Compares two file objects and return true if they represent the same underlying object. |
|
int |
isSupportedOption(java.lang.String option)
Determines if the given option is supported and if so, the number of arguments the option takes. |
|
private boolean |
isValidFile(java.lang.String s,
java.util.Set<JavaFileObject.Kind> fileKinds)
|
|
private static boolean |
isValidName(java.lang.String name)
|
|
java.lang.Iterable<JavaFileObject> |
list(JavaFileManager.Location location,
java.lang.String packageName,
java.util.Set<JavaFileObject.Kind> kinds,
boolean recurse)
Lists all file objects matching the given criteria in the given location. |
|
private void |
listDirectory(java.io.File directory,
RelativePath.RelativeDirectory subdirectory,
java.util.Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
ListBuffer<JavaFileObject> l)
Insert all files in subdirectory `subdirectory' of `directory' which end in one of the extensions in `extensions' into packageSym. |
|
(package private) java.nio.ByteBuffer |
makeByteBuffer(java.io.InputStream in)
Make a byte buffer from an input stream. |
|
private static
|
nullCheck(java.lang.Iterable<T> it)
|
|
private static
|
nullCheck(T o)
|
|
protected JavacFileManager.Archive |
openArchive(java.io.File zipFileName)
Open a new zip file directory. |
|
static void |
preRegister(Context context)
Register a Context.Factory to create a JavacFileManager. |
|
private static void |
printAscii(java.lang.String format,
java.lang.Object... args)
|
|
(package private) void |
recycleByteBuffer(java.nio.ByteBuffer bb)
|
|
void |
setContext(Context context)
Set the context for JavacFileManager. |
|
void |
setLocation(JavaFileManager.Location location,
java.lang.Iterable<? extends java.io.File> path)
Associates the given path with the given location. |
|
static void |
testName(java.lang.String name,
boolean isValidPackageName,
boolean isValidClassName)
|
|
static char[] |
toArray(java.nio.CharBuffer buffer)
|
|
private static void |
validateClassName(java.lang.String className)
|
|
private static void |
validatePackageName(java.lang.String packageName)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
boolean useZipFileIndex
protected Log log
private Paths paths
private Options options
private FSInfo fsInfo
private final java.io.File uninited
private final java.util.Set<JavaFileObject.Kind> sourceOrClass
private java.io.File classOutDir
private java.io.File sourceOutDir
protected boolean mmappedIO
protected boolean ignoreSymbolFile
protected java.nio.charset.Charset charset
private static final boolean fileSystemIsCaseSensitive
java.util.Map<java.io.File,JavacFileManager.Archive> archives
private static final java.lang.String[] symbolFileLocation
private static final RelativePath.RelativeDirectory symbolFilePrefix
private final java.util.Map<JavaFileObject,java.lang.ref.SoftReference<java.nio.CharBuffer>> contentCache
private java.lang.String defaultEncodingName
private final JavacFileManager.ByteBufferCache byteBufferCache
private static JavacOption[] javacFileManagerOptions
| Constructor Detail |
|---|
public JavacFileManager(Context context,
boolean register,
java.nio.charset.Charset charset)
| Method Detail |
|---|
public static char[] toArray(java.nio.CharBuffer buffer)
public static void preRegister(Context context)
public void setContext(Context context)
public JavaFileObject getFileForInput(java.lang.String name)
public JavaFileObject getRegularFile(java.io.File file)
public JavaFileObject getFileForOutput(java.lang.String classname,
JavaFileObject.Kind kind,
JavaFileObject sibling)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(java.lang.Iterable<java.lang.String> names)
StandardJavaFileManager
getJavaFileObjectsFromStrings in interface StandardJavaFileManagernames - a list of file names
public java.lang.Iterable<? extends JavaFileObject> getJavaFileObjects(java.lang.String... names)
StandardJavaFileManager
getJavaFileObjectsFromStrings(Arrays.asList(names))
getJavaFileObjects in interface StandardJavaFileManagernames - a list of file names
protected JavaFileObject.Kind getKind(java.lang.String extension)
private static boolean isValidName(java.lang.String name)
private static void validateClassName(java.lang.String className)
private static void validatePackageName(java.lang.String packageName)
public static void testName(java.lang.String name,
boolean isValidPackageName,
boolean isValidClassName)
private static void printAscii(java.lang.String format,
java.lang.Object... args)
private void listDirectory(java.io.File directory,
RelativePath.RelativeDirectory subdirectory,
java.util.Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
ListBuffer<JavaFileObject> l)
private boolean isValidFile(java.lang.String s,
java.util.Set<JavaFileObject.Kind> fileKinds)
private boolean caseMapCheck(java.io.File f,
RelativePath name)
protected JavacFileManager.Archive openArchive(java.io.File zipFileName)
throws java.io.IOException
java.io.IOExceptionpublic void flush()
flush in interface java.io.Flushableflush in interface JavaFileManagerJavaFileManager.close()public void close()
close in interface java.io.Closeableclose in interface JavaFileManagerJavaFileManager.flush()java.nio.CharBuffer getCachedContent(JavaFileObject file)
void cache(JavaFileObject file,
java.nio.CharBuffer cb)
private java.lang.String getDefaultEncodingName()
protected java.lang.String getEncodingName()
protected Source getSource()
java.nio.ByteBuffer makeByteBuffer(java.io.InputStream in)
throws java.io.IOException
java.io.IOExceptionvoid recycleByteBuffer(java.nio.ByteBuffer bb)
java.nio.charset.CharsetDecoder getDecoder(java.lang.String encodingName,
boolean ignoreEncodingErrors)
java.nio.CharBuffer decode(java.nio.ByteBuffer inbuf,
boolean ignoreEncodingErrors)
public java.lang.ClassLoader getClassLoader(JavaFileManager.Location location)
JavaFileManagerANNOTATION_PROCESSOR_PATH location.
getClassLoader in interface JavaFileManagerlocation - a location
null
if loading plug-ins from the given location is disabled or if
the location is not known
public java.lang.Iterable<JavaFileObject> list(JavaFileManager.Location location,
java.lang.String packageName,
java.util.Set<JavaFileObject.Kind> kinds,
boolean recurse)
throws java.io.IOException
JavaFileManagerNote: 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 JavaFileManagerlocation - a locationpackageName - a package namekinds - return objects only of these kindsrecurse - if true include "subpackages"
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be
reopened
public java.lang.String inferBinaryName(JavaFileManager.Location location,
JavaFileObject file)
JavaFileManager
inferBinaryName in interface JavaFileManagerlocation - a locationfile - a file object
null the file object is not
found in the given location
public boolean isSameFile(FileObject a,
FileObject b)
JavaFileManager
isSameFile in interface JavaFileManagerisSameFile in interface StandardJavaFileManagera - a file objectb - a file object
public boolean handleOption(java.lang.String current,
java.util.Iterator<java.lang.String> remaining)
JavaFileManagercurrent is an option to this
file manager it will consume any arguments to that option from
remaining and return true, otherwise return false.
handleOption in interface JavaFileManagercurrent - current optionremaining - remaining options
public int isSupportedOption(java.lang.String option)
OptionChecker
isSupportedOption in interface OptionCheckeroption - an option
public boolean hasLocation(JavaFileManager.Location location)
JavaFileManager
hasLocation in interface JavaFileManagerlocation - a location
public JavaFileObject getJavaFileForInput(JavaFileManager.Location location,
java.lang.String className,
JavaFileObject.Kind kind)
throws java.io.IOException
JavaFileManager
getJavaFileForInput in interface JavaFileManagerlocation - a locationclassName - the name of a classkind - the kind of file, must be one of SOURCE or CLASS
null if the
file does not exist
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be
reopened
public FileObject getFileForInput(JavaFileManager.Location location,
java.lang.String packageName,
java.lang.String relativeName)
throws java.io.IOException
JavaFileManagerIf 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 JavaFileManagerlocation - a locationpackageName - a package namerelativeName - a relative name
null if the file
does not exist
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be
reopened
private JavaFileObject getFileForInput(JavaFileManager.Location location,
RelativePath.RelativeFile name)
throws java.io.IOException
java.io.IOException
public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location,
java.lang.String className,
JavaFileObject.Kind kind,
FileObject sibling)
throws java.io.IOException
JavaFileManagerOptionally, this file manager might consider the sibling as a hint for where to place the output. The exact semantics of this hint is unspecified. Sun's 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 JavaFileManagerlocation - a locationclassName - the name of a classkind - the kind of file, must be one of SOURCE or CLASSsibling - a file object to be used as hint for placement;
might be null
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be
reopened
public FileObject getFileForOutput(JavaFileManager.Location location,
java.lang.String packageName,
java.lang.String relativeName,
FileObject sibling)
throws java.io.IOException
JavaFileManagerOptionally, this file manager might consider the sibling as a hint for where to place the output. The exact semantics of this hint is unspecified. Sun's 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 JavaFileManagerlocation - a locationpackageName - a package namerelativeName - a relative namesibling - a file object to be used as hint for placement;
might be null
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be
reopened
private JavaFileObject getFileForOutput(JavaFileManager.Location location,
RelativePath.RelativeFile fileName,
FileObject sibling)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(java.lang.Iterable<? extends java.io.File> files)
StandardJavaFileManager
getJavaFileObjectsFromFiles in interface StandardJavaFileManagerfiles - a list of files
public java.lang.Iterable<? extends JavaFileObject> getJavaFileObjects(java.io.File... files)
StandardJavaFileManager
getJavaFileObjectsFromFiles(Arrays.asList(files))
getJavaFileObjects in interface StandardJavaFileManagerfiles - an array of files
public void setLocation(JavaFileManager.Location location,
java.lang.Iterable<? extends java.io.File> path)
throws java.io.IOException
StandardJavaFileManager
setLocation in interface StandardJavaFileManagerlocation - a locationpath - a list of files, if null use the default
path for this location
java.io.IOException - if location is an output location and path
does not represent an existing directoryStandardJavaFileManager.getLocation(javax.tools.JavaFileManager.Location)
private java.io.File getOutputDirectory(java.lang.Iterable<? extends java.io.File> path)
throws java.io.IOException
java.io.IOException
private java.io.File getOutputLocation(java.io.File dir,
OptionName defaultOptionName)
public java.lang.Iterable<? extends java.io.File> getLocation(JavaFileManager.Location location)
StandardJavaFileManager
getLocation in interface StandardJavaFileManagerlocation - a location
null if this location has no
associated pathStandardJavaFileManager.setLocation(javax.tools.JavaFileManager.Location, java.lang.Iterable extends java.io.File>)private java.io.File getClassOutDir()
private java.io.File getSourceOutDir()
protected static boolean isRelativeUri(java.net.URI uri)
public static java.lang.String getRelativeName(java.io.File file)
file - a relative file name
java.lang.IllegalArgumentException - if the file name is not
relative according to the definition given in JavaFileManager.getFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, java.lang.String)public static java.lang.String getJavacFileName(FileObject file)
public static java.lang.String getJavacBaseFileName(FileObject file)
private static <T> T nullCheck(T o)
private static <T> java.lang.Iterable<T> nullCheck(java.lang.Iterable<T> it)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||