Interface Filer
There are two distinguished locations (subtrees within the
file system) where newly created files are placed:
one for new source files, and one for new class files.
(These might be specified on a tool's command line, for example,
using flags such as -s
and -d
.)
Auxiliary files may be created in either location.
During each run of an annotation processing tool, a file with a given pathname may be created only once. If that file already exists before the first attempt to create it, the old contents will be deleted. Any subsequent attempt to create the same file during a run will fail.
- Since:
- 1.5
- Version:
- 1.1 04/01/26
- Author:
- Joseph D. Darcy, Scott Seligman
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Locations (subtrees within the file system) where new files are created. -
Method Summary
Modifier and TypeMethodDescriptioncreateBinaryFile
(Filer.Location loc, String pkg, File relPath) Creates a new binary file, and returns a stream for writing to it.createClassFile
(String name) Creates a new class file, and returns a stream for writing to it.createSourceFile
(String name) Creates a new source file and returns a writer for it.createTextFile
(Filer.Location loc, String pkg, File relPath, String charsetName) Creates a new text file, and returns a writer for it.
-
Method Details
-
createSourceFile
Creates a new source file and returns a writer for it. The file's name and path (relative to the root of all newly created source files) is based on the type to be declared in that file. If more than one type is being declared, the name of the principal top-level type (the public one, for example) should be used.The charset used to encode the file is determined by the implementation. An annotation processing tool may have an
-encoding
flag or the like for specifying this. It will typically use the platform's default encoding if none is specified.- Parameters:
name
- canonical (fully qualified) name of the principal type being declared in this file- Returns:
- a writer for the new file
- Throws:
IOException
- if the file cannot be created
-
createClassFile
Creates a new class file, and returns a stream for writing to it. The file's name and path (relative to the root of all newly created class files) is based on the name of the type being written.- Parameters:
name
- canonical (fully qualified) name of the type being written- Returns:
- a stream for writing to the new file
- Throws:
IOException
- if the file cannot be created
-
createTextFile
PrintWriter createTextFile(Filer.Location loc, String pkg, File relPath, String charsetName) throws IOException Creates a new text file, and returns a writer for it. The file is located along with either the newly created source or newly created binary files. It may be named relative to some package (as are source and binary files), and from there by an arbitrary pathname. In a loose sense, the pathname of the new file will be the concatenation ofloc
,pkg
, andrelPath
.A charset for encoding the file may be provided. If none is given, the charset used to encode source files (see
createSourceFile(String)
) will be used.- Parameters:
loc
- location of the new filepkg
- package relative to which the file should be named, or the empty string if nonerelPath
- final pathname components of the filecharsetName
- the name of the charset to use, or null if none is being explicitly specified- Returns:
- a writer for the new file
- Throws:
IOException
- if the file cannot be created
-
createBinaryFile
Creates a new binary file, and returns a stream for writing to it. The file is located along with either the newly created source or newly created binary files. It may be named relative to some package (as are source and binary files), and from there by an arbitrary pathname. In a loose sense, the pathname of the new file will be the concatenation ofloc
,pkg
, andrelPath
.- Parameters:
loc
- location of the new filepkg
- package relative to which the file should be named, or the empty string if nonerelPath
- final pathname components of the file- Returns:
- a stream for writing to the new file
- Throws:
IOException
- if the file cannot be created
-