Interface JctFileManager
- All Superinterfaces:
AutoCloseable, Closeable, Flushable, JavaFileManager, OptionChecker
JavaFileManager that allows adding of PathRoot objects to the
manager.
This component is responsible for bridging the gap between a Workspace and
a JavaCompiler when performing a compilation, and thus includes a number of
required operations that the compiler will query the file system with. In addition, this
interface also defines a number of additional functionalities that are useful for querying and
verifying the outcome of compilations within tests.
- Since:
- 0.0.1
- Author:
- Ashley Scopes
-
Nested Class Summary
Nested classes/interfaces inherited from interface JavaFileManager
JavaFileManager.Location -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPath(JavaFileManager.Location location, PathRoot path) Add a package-oriented path to a given location.voidaddPaths(JavaFileManager.Location location, Collection<? extends PathRoot> paths) Add a collection of package-oriented paths to a given location.voidclose()Close this file manager.booleancontains(JavaFileManager.Location location, FileObject fileObject) Determine if the given file object resides in the given location.voidCopy all containers from the first location to the second location.voidcreateEmptyLocation(JavaFileManager.Location location) Register an empty container for the given location to indicate to the compiler that the feature exists, but has no configured paths.voidflush()Flush this file manager.default @Nullable ModuleContainerGroupGet the location holding theannotation processor module path.default @Nullable PackageContainerGroupGet the location holding theannotation processor path.getClassLoader(JavaFileManager.Location location) Get the class loader for loading classes for the given location.default @Nullable OutputContainerGroupGet the location holding theclass outputs.default @Nullable PackageContainerGroupGet the location holding theclass path.Get the associated effective release.getFileForInput(JavaFileManager.Location location, String packageName, String relativeName) Get a file for input operations.getFileForOutput(JavaFileManager.Location location, String packageName, String relativeName, @Nullable FileObject sibling) Get a file for output operations.getJavaFileForInput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind) Get a Java file for input operations.getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, @Nullable FileObject sibling) Get a Java file for output operations.getLocationForModule(JavaFileManager.Location location, String moduleName) Get the location for a named module within the given location.getLocationForModule(JavaFileManager.Location location, JavaFileObject fileObject) Get the location for the module holding a given file object within the given location.Get the container group for the given module-oriented location.Get a collection of all module container groups in this file manager.default @Nullable ModuleContainerGroupGet the location holding themodule path.default @Nullable ModuleContainerGroupGet the location holding themodule source path.Get the container group for the given output-oriented location.Get a collection of all output container groups in this file manager.Get the container group for the given package-oriented location.Get a collection of all package container groups in this file manager.default @Nullable OutputContainerGroupGet the location holding thesource outputs.default @Nullable PackageContainerGroupGet the location holding thesource path.booleanhandleOption(String current, Iterator<String> remaining) Handles one option.booleanhasLocation(JavaFileManager.Location location) Determines if a location is known to this file manager.inferBinaryName(JavaFileManager.Location location, JavaFileObject file) Infers a binary name of a file object based on a package-oriented location.inferModuleName(JavaFileManager.Location location) Infer the name of the module from its location, as returned bygetLocationForModuleorlistModuleLocations.booleanDetermine if the two file objects are the same file.list(JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) List all file objects in the given location matching the given criteria.List all module-based locations for the given module-oriented or output location.Methods inherited from interface JavaFileManager
getServiceLoaderMethods inherited from interface OptionChecker
isSupportedOption
-
Method Details
-
addPath
Add a package-oriented path to a given location.To add a module, first obtain the module location using
getLocationForModule(Location, String), and pass that result to this call.- Parameters:
location- the location to use.path- the path to add.- See Also:
-
addPaths
Add a collection of package-oriented paths to a given location.To add a module, first obtain the module location using
getLocationForModule(Location, String), and pass that result to this call.- Parameters:
location- the location to use.paths- the paths to add.- See Also:
-
close
Close this file manager.If the file manager is already closed, this will have no effect.
JCT File managers may choose to not implement this operation if not applicable.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceJavaFileManager- Throws:
IOException- if an IO error occurs during closure.
-
contains
Determine if the given file object resides in the given location.If package-oriented, then the file must exist in the given location directly.
If module-oriented, then the file must exist in one of the modules within the location. This implies that
getLocationForModule(Location, JavaFileObject)would also return a valid non-null value.- Specified by:
containsin interfaceJavaFileManager- Parameters:
location- the location.fileObject- the file object.- Returns:
trueif the file exists in the given location, orfalseotherwise.- Throws:
IOException- if an IO error occurs during the lookup.
-
copyContainers
Copy all containers from the first location to the second location.- Parameters:
from- the first location.to- the second location.
-
createEmptyLocation
Register an empty container for the given location to indicate to the compiler that the feature exists, but has no configured paths.This is needed to coerce the behaviour for annotation processing in some cases.
If the location already exists, then do not do anything.
If the location is an output location, then this operation does not make any sense, since an empty location cannot have files output to it. In this case, you will likely get an exception.
Likewise, this operation does not make sense for module locations within a module-oriented location group, so this operation will fail with an error for those inputs as well.
- Parameters:
location- the location to apply an empty container for.- Throws:
IllegalArgumentException- if the location is an output location or a module location.
-
flush
Flush this file manager.If the file manager is already closed, this will have no effect.
JCT File managers may choose to not implement this operation if not applicable.
- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfaceJavaFileManager- Throws:
IOException- if an IO error occurs during flushing.
-
getClassLoader
Get the class loader for loading classes for the given location.- Specified by:
getClassLoaderin interfaceJavaFileManager- Parameters:
location- the location to fetch a class loader for.- Returns:
- a class loader, or
nullif loading classes for the given location is not supported. - Throws:
SecurityException- if a class loader can not be created in the current security contextIllegalStateException- ifclose()has been called and this file manager cannot be reopenedIllegalArgumentException- if the location is a module-oriented location
-
getEffectiveRelease
Get the associated effective release.- Returns:
- the effective release.
- Since:
- 0.0.1
-
getFileForInput
@Nullable FileObject getFileForInput(JavaFileManager.Location location, String packageName, String relativeName) throws IOException Get a file for input operations.- Specified by:
getFileForInputin interfaceJavaFileManager- Parameters:
location- a package-oriented location.packageName- a package name.relativeName- a relative name.- Returns:
- the file object, or
nullif not found or not available. - Throws:
IOException- if an IO error occurs reading the file details.IllegalArgumentException- if the location is not a package-oriented location.
-
getFileForOutput
@Nullable FileObject getFileForOutput(JavaFileManager.Location location, String packageName, String relativeName, @Nullable FileObject sibling) throws IOException Get a file for output operations.- Specified by:
getFileForOutputin interfaceJavaFileManager- Parameters:
location- an output location.packageName- a package name.relativeName- a relative name.sibling- a file object to be used as hint for placement, might benull.- Returns:
- the file object, or
nullif not found or not available. - Throws:
IOException- if an IO error occurs reading the file details.IllegalArgumentException- if the location is not an output location.
-
getJavaFileForInput
@Nullable JavaFileObject getJavaFileForInput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind) throws IOException Get a Java file for input operations.- Specified by:
getJavaFileForInputin interfaceJavaFileManager- Parameters:
location- a package-oriented location.className- the name of a class.kind- the kind of file.- Returns:
- the file object, or
nullif not found or not available. - Throws:
IOException- if an IO error occurs reading the file details.IllegalArgumentException- if the location is not a package-oriented location.
-
getJavaFileForOutput
@Nullable JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, @Nullable FileObject sibling) throws IOException Get a Java file for output operations.- Specified by:
getJavaFileForOutputin interfaceJavaFileManager- Parameters:
location- an output location.className- the name of a class.kind- the kind of file.sibling- a file object to be used as hint for placement, might benull.- Returns:
- the file object, or
nullif not found or not available. - Throws:
IOException- if an IO error occurs reading the file details.IllegalArgumentException- if the location is not an output location.
-
getLocationForModule
@Nullable JavaFileManager.Location getLocationForModule(JavaFileManager.Location location, String moduleName) throws IOException Get the location for a named module within the given location.- Specified by:
getLocationForModulein interfaceJavaFileManager- Parameters:
location- the module-oriented location.moduleName- the name of the module to be found.- Returns:
- the location of the named module, or
nullif not found. - Throws:
IOException- if an IO error occurs during resolution.IllegalArgumentException- if the location is neither an output location nor a module-oriented location.
-
getLocationForModule
@Nullable JavaFileManager.Location getLocationForModule(JavaFileManager.Location location, JavaFileObject fileObject) throws IOException Get the location for the module holding a given file object within the given location.- Specified by:
getLocationForModulein interfaceJavaFileManager- Parameters:
location- the module-oriented location.fileObject- the file object to resolve the module for.- Returns:
- the location, or
nullif not found. - Throws:
IOException- if an IO error occurs during resolution.IllegalArgumentException- if the location is neither an output location nor a module-oriented location.
-
getPackageContainerGroup
Get the container group for the given package-oriented location.- Parameters:
location- the package oriented location.- Returns:
- the container group, or null if one does not exist.
-
getPackageContainerGroups
Get a collection of all package container groups in this file manager.- Returns:
- the package container groups.
-
getModuleContainerGroup
Get the container group for the given module-oriented location.- Parameters:
location- the module oriented location.- Returns:
- the container group, or null if one does not exist.
-
getModuleContainerGroups
Get a collection of all module container groups in this file manager.- Returns:
- the module container groups.
-
getOutputContainerGroup
Get the container group for the given output-oriented location.- Parameters:
location- the output oriented location.- Returns:
- the container group, or null if one does not exist.
-
getOutputContainerGroups
Get a collection of all output container groups in this file manager.- Returns:
- the output container groups.
-
handleOption
Handles one option. Ifcurrentis an option to this file manager it will consume any arguments to that option fromremainingand return true, otherwise return false.- Specified by:
handleOptionin interfaceJavaFileManager- Parameters:
current- current option.remaining- remaining options.- Returns:
trueif this option was handled by this file manager,falseotherwise.- Throws:
IllegalArgumentException- if this option to this file manager is used incorrectly.IllegalStateException- ifclose()has been called and this file manager cannot be reopened.
-
hasLocation
Determines if a location is known to this file manager.- Specified by:
hasLocationin interfaceJavaFileManager- Parameters:
location- a location.- Returns:
- true if the location is known to this file manager.
-
inferBinaryName
Infers a binary name of a file object based on a package-oriented location. The binary name returned might not be a valid binary name according to the Java Language Specification.- Specified by:
inferBinaryNamein interfaceJavaFileManager- Parameters:
location- a location.file- a file object.- Returns:
- a binary name or
nullthe file object is not found in the given location - Throws:
IllegalArgumentException- if the location is a module-oriented location.IllegalStateException- ifclose()has been called and this file manager cannot be reopened.
-
inferModuleName
Infer the name of the module from its location, as returned bygetLocationForModuleorlistModuleLocations.- Specified by:
inferModuleNamein interfaceJavaFileManager- Parameters:
location- a package-oriented location representing a module.- Returns:
- the name of the module, or
nullif the name cannot be resolved or does not exist. - Throws:
IOException- if an I/O error occurred during resolution.IllegalArgumentException- if the location is not one known to this file manager.
-
isSameFile
Determine if the two file objects are the same file.- Specified by:
isSameFilein interfaceJavaFileManager- Parameters:
a- a file object, can benull.b- a file object, can benull.- Returns:
trueif both arguments are non-null and refer to the same logical file, orfalseotherwise.
-
list
Set<JavaFileObject> list(JavaFileManager.Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException List all file objects in the given location matching the given criteria.- Specified by:
listin interfaceJavaFileManager- Parameters:
location- the location to search in.packageName- the package name to search in, or""to search in the root location.kinds- the kinds of file to return, orSet.of()(JavaFileObject.Kind.OTHER)to find all files.recurse-trueto recurse into subpackages,falseto only check the current package.- Returns:
- a collection of unique file objects that were found.
- Throws:
IOException- if an IO error occurs reading the file system.IllegalArgumentException- if the location is a module-oriented locationIllegalStateException- ifclose()has been called and this file manager cannot be reopened
-
listLocationsForModules
Iterable<Set<JavaFileManager.Location>> listLocationsForModules(JavaFileManager.Location location) throws IOException List all module-based locations for the given module-oriented or output location.- Specified by:
listLocationsForModulesin interfaceJavaFileManager- Parameters:
location- the module-oriented/output location for which to list the modules.- Returns:
- the iterable of sets of modules.
- Throws:
IOException- if an IO error occurs during resolution.IllegalArgumentException- if the location is not a module-oriented or output location.
-
getClassOutputGroup
Get the location holding theclass outputs.- Returns:
- the location, or
nullif the location is not present in the file manager. - Since:
- 0.1.0
-
getSourceOutputGroup
Get the location holding thesource outputs.- Returns:
- the location, or
nullif the location is not present in the file manager. - Since:
- 0.1.0
-
getClassPathGroup
Get the location holding theclass path.- Returns:
- the location, or
nullif the location is not present in the file manager. - Since:
- 0.1.0
-
getSourcePathGroup
Get the location holding thesource path.- Returns:
- the location, or
nullif the location is not present in the file manager. - Since:
- 0.1.0
-
getAnnotationProcessorPathGroup
Get the location holding theannotation processor path.- Returns:
- the location, or
nullif the location is not present in the file manager. - Since:
- 0.1.0
-
getAnnotationProcessorModulePathGroup
Get the location holding theannotation processor module path.- Returns:
- the location, or
nullif the location is not present in the file manager. - Since:
- 0.1.0
-
getModuleSourcePathGroup
Get the location holding themodule source path.- Returns:
- the location, or
nullif the location is not present in the file manager. - Since:
- 0.1.0
-
getModulePathGroup
Get the location holding themodule path.- Returns:
- the location, or
nullif the location is not present in the file manager. - Since:
- 0.1.0
-