com.sun.tools.javac.api
Class WrappingJavaFileManager<M extends JavaFileManager>

java.lang.Object
  extended by javax.tools.ForwardingJavaFileManager<M>
      extended by com.sun.tools.javac.api.WrappingJavaFileManager<M>
Type Parameters:
M - the type of file manager wrapped to by this object
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, JavaFileManager, OptionChecker

public class WrappingJavaFileManager<M extends JavaFileManager>
extends ForwardingJavaFileManager<M>

Wraps all calls to a given file manager. Subclasses of this class might override some of these methods and might also provide additional fields and methods.

This class might be moved to javax.tools in a future release.

This is NOT part of any API supported by Sun Microsystems. 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.

Since:
1.6

Nested Class Summary
 
Nested classes/interfaces inherited from interface javax.tools.JavaFileManager
JavaFileManager.Location
 
Field Summary
 
Fields inherited from class javax.tools.ForwardingJavaFileManager
fileManager
 
Constructor Summary
protected WrappingJavaFileManager(M fileManager)
          Creates a new instance of WrappingJavaFileManager.
 
Method Summary
 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.
 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 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.String inferBinaryName(JavaFileManager.Location location, JavaFileObject file)
          Infers a binary name of a file object based on a location.
 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.
protected  FileObject unwrap(FileObject fileObject)
          This implementation returns the given file object.
protected  JavaFileObject unwrap(JavaFileObject fileObject)
          This implementation forwards to unwrap(FileObject).
protected  java.net.URI unwrap(java.net.URI uri)
          This implementation returns the given URI.
protected  FileObject wrap(FileObject fileObject)
          This implementation returns the given file object.
protected  java.lang.Iterable<JavaFileObject> wrap(java.lang.Iterable<JavaFileObject> fileObjects)
          This implementation maps the given list of file objects by calling wrap on each.
protected  JavaFileObject wrap(JavaFileObject fileObject)
          This implementation forwards to wrap(FileObject).
 
Methods inherited from class javax.tools.ForwardingJavaFileManager
close, flush, getClassLoader, handleOption, hasLocation, isSameFile, isSupportedOption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrappingJavaFileManager

protected WrappingJavaFileManager(M fileManager)
Creates a new instance of WrappingJavaFileManager.

Parameters:
fileManager - file manager to be wrapped
Method Detail

wrap

protected FileObject wrap(FileObject fileObject)
This implementation returns the given file object. Subclasses may override this behavior.

Parameters:
fileObject - a file object

wrap

protected JavaFileObject wrap(JavaFileObject fileObject)
This implementation forwards to wrap(FileObject). Subclasses may override this behavior.

Parameters:
fileObject - a file object
Throws:
java.lang.ClassCastException - if the file object returned from the forwarded call is not a subtype of JavaFileObject

unwrap

protected FileObject unwrap(FileObject fileObject)
This implementation returns the given file object. Subclasses may override this behavior.

Parameters:
fileObject - a file object

unwrap

protected JavaFileObject unwrap(JavaFileObject fileObject)
This implementation forwards to unwrap(FileObject). Subclasses may override this behavior.

Parameters:
fileObject - a file object
Throws:
java.lang.ClassCastException - if the file object returned from the forwarded call is not a subtype of JavaFileObject

wrap

protected java.lang.Iterable<JavaFileObject> wrap(java.lang.Iterable<JavaFileObject> fileObjects)
This implementation maps the given list of file objects by calling wrap on each. Subclasses may override this behavior.

Parameters:
fileObjects - a list of file objects
Returns:
the mapping

unwrap

protected java.net.URI unwrap(java.net.URI uri)
This implementation returns the given URI. Subclasses may override this behavior.

Parameters:
uri - a URI

list

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
Description copied from interface: JavaFileManager
Lists all file objects matching the given criteria in the given location. List file objects in "subpackages" if recurse is true.

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.

Specified by:
list in interface JavaFileManager
Overrides:
list in class ForwardingJavaFileManager<M extends JavaFileManager>
Parameters:
location - a location
packageName - a package name
kinds - return objects only of these kinds
recurse - if true include "subpackages"
Returns:
an Iterable of file objects matching the given criteria
Throws:
java.lang.IllegalStateException - if JavaFileManager.close() has been called and this file manager cannot be reopened
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be reopened

inferBinaryName

public java.lang.String inferBinaryName(JavaFileManager.Location location,
                                        JavaFileObject file)
Description copied from interface: JavaFileManager
Infers a binary name of a file object based on a location. The binary name returned might not be a valid JLS binary name.

Specified by:
inferBinaryName in interface JavaFileManager
Overrides:
inferBinaryName in class ForwardingJavaFileManager<M extends JavaFileManager>
Parameters:
location - a location
file - a file object
Returns:
a binary name or null the file object is not found in the given location
Throws:
java.lang.IllegalStateException - if JavaFileManager.close() has been called and this file manager cannot be reopened

getJavaFileForInput

public JavaFileObject getJavaFileForInput(JavaFileManager.Location location,
                                          java.lang.String className,
                                          JavaFileObject.Kind kind)
                                   throws java.io.IOException
Description copied from interface: JavaFileManager
Gets a file object for input representing the specified class of the specified kind in the given location.

Specified by:
getJavaFileForInput in interface JavaFileManager
Overrides:
getJavaFileForInput in class ForwardingJavaFileManager<M extends JavaFileManager>
Parameters:
location - a location
className - the name of a class
kind - the kind of file, must be one of SOURCE or CLASS
Returns:
a file object, might return null if the file does not exist
Throws:
java.lang.IllegalArgumentException - if the location is not known to this file manager and the file manager does not support unknown locations, or if the kind is not valid
java.lang.UnsupportedOperationException
java.lang.IllegalStateException - if JavaFileManager.close() has been called and this file manager cannot be reopened
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be reopened

getJavaFileForOutput

public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location,
                                           java.lang.String className,
                                           JavaFileObject.Kind kind,
                                           FileObject sibling)
                                    throws java.io.IOException
Description copied from interface: JavaFileManager
Gets a file object for output representing the specified class of the specified kind in the given location.

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. 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.

Specified by:
getJavaFileForOutput in interface JavaFileManager
Overrides:
getJavaFileForOutput in class ForwardingJavaFileManager<M extends JavaFileManager>
Parameters:
location - a location
className - the name of a class
kind - 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
Returns:
a file object for output
Throws:
java.lang.IllegalArgumentException - if sibling is not known to this file manager, or if the location is not known to this file manager and the file manager does not support unknown locations, or if the kind is not valid
java.lang.UnsupportedOperationException
java.lang.IllegalStateException - JavaFileManager.close() has been called and this file manager cannot be reopened
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be reopened

getFileForInput

public FileObject getFileForInput(JavaFileManager.Location location,
                                  java.lang.String packageName,
                                  java.lang.String relativeName)
                           throws java.io.IOException
Description copied from interface: JavaFileManager
Gets a file object for input representing the specified relative name in the specified package in the given location.

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".

Specified by:
getFileForInput in interface JavaFileManager
Overrides:
getFileForInput in class ForwardingJavaFileManager<M extends JavaFileManager>
Parameters:
location - a location
packageName - a package name
relativeName - a relative name
Returns:
a file object, might return null if the file does not exist
Throws:
java.lang.IllegalArgumentException - if the location is not known to this file manager and the file manager does not support unknown locations, or if relativeName is not valid
java.lang.IllegalStateException - if JavaFileManager.close() has been called and this file manager cannot be reopened
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be reopened

getFileForOutput

public FileObject getFileForOutput(JavaFileManager.Location location,
                                   java.lang.String packageName,
                                   java.lang.String relativeName,
                                   FileObject sibling)
                            throws java.io.IOException
Description copied from interface: JavaFileManager
Gets a file object for output representing the specified relative name in the specified package in the given location.

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. 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.

Specified by:
getFileForOutput in interface JavaFileManager
Overrides:
getFileForOutput in class ForwardingJavaFileManager<M extends JavaFileManager>
Parameters:
location - a location
packageName - a package name
relativeName - a relative name
sibling - a file object to be used as hint for placement; might be null
Returns:
a file object
Throws:
java.lang.IllegalArgumentException - if sibling is not known to this file manager, or if the location is not known to this file manager and the file manager does not support unknown locations, or if relativeName is not valid
java.lang.IllegalStateException - if JavaFileManager.close() has been called and this file manager cannot be reopened
java.io.IOException - if an I/O error occurred, or if JavaFileManager.close() has been called and this file manager cannot be reopened