/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The FilerImplementation class must maintain a number of
* constraints. First, multiple attempts to open the same path within
* the same invocation of the tool results in an IOException being
* thrown. For example, trying to open the same source file twice:
*
* <pre>
* createSourceFile("foo.Bar")
* ...
* createSourceFile("foo.Bar")
* </pre>
*
* is disallowed as is opening a text file that happens to have
* the same name as a source file:
*
* <pre>
* createSourceFile("foo.Bar")
* ...
* createTextFile(SOURCE_TREE, "foo", new File("Bar"), null)
* </pre>
*
* <p>Additionally, creating a source file that corresponds to an
* already created class file (or vice versa) also results in an
* IOException since each type can only be created once. However, if
* the Filer is used to create a text file named *.java that happens
* to correspond to an existing class file, a warning is *not*
* generated. Similarly, a warning is not generated for a binary file
* named *.class and an existing source file.
*
* <p>The reason for this difference is that source files and class
* files are registered with the tool and can get passed on as
* declarations to the next round of processing. Files that are just
* named *.java and *.class are not processed in that manner; although
* having extra source files and class files on the source path and
* class path can alter the behavior of the tool and any final
* compile.
*
* <p><b>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.</b>
*/
// TODO: Implement different transaction model for updating the
// Filer's record keeping on file close.
"Output stream or writer has already been opened.";
"FileObject was not opened for reading.";
"FileObject was not opened for writing.";
/**
* Wrap a JavaFileObject to manage writing by the Filer.
*/
private boolean opened = false;
super(fileObject);
}
if (opened)
throw new IOException(ALREADY_OPENED);
opened = true;
}
if (opened)
throw new IOException(ALREADY_OPENED);
opened = true;
}
// Three anti-literacy methods
throw new IllegalStateException(NOT_FOR_READING);
}
throw new IllegalStateException(NOT_FOR_READING);
}
throw new IllegalStateException(NOT_FOR_READING);
}
public boolean delete() {
return false;
}
}
super(name, javaFileObject);
this.javaFileObject = javaFileObject;
}
return javaFileObject.getKind();
}
}
return javaFileObject.getNestingKind();
}
return javaFileObject.getAccessLevel();
}
}
/**
* Wrap a JavaFileObject to manage reading by the Filer.
*/
super(fileObject);
}
throw new IllegalStateException(NOT_FOR_WRITING);
}
throw new IllegalStateException(NOT_FOR_WRITING);
}
public boolean delete() {
return false;
}
}
super(javaFileObject);
this.javaFileObject = javaFileObject;
}
return javaFileObject.getKind();
}
}
return javaFileObject.getNestingKind();
}
return javaFileObject.getAccessLevel();
}
}
/**
* Wrap a {@code OutputStream} returned from the {@code
* JavaFileManager} to properly register source or class files
* when they are closed.
*/
boolean closed = false;
/**
* @param typeName name of class or {@code null} if just a
* binary file
*/
super(fileObject.openOutputStream());
this.fileObject = fileObject;
}
if (!closed) {
closed = true;
/*
* If an IOException occurs when closing the underlying
* stream, still try to process the file.
*/
}
}
}
/**
* Wrap a {@code Writer} returned from the {@code JavaFileManager}
* to properly register source or class files when they are
* closed.
*/
boolean closed = false;
/**
* @param fileObject the fileObject to be written to
* @param typeName name of source file or {@code null} if just a
* text file
*/
super(fileObject.openWriter());
this.fileObject = fileObject;
}
if (!closed) {
closed = true;
/*
* If an IOException occurs when closing the underlying
* Writer, still try to process the file.
*/
}
}
}
boolean lastRound;
private final boolean lint;
/**
* Logical names of all created files. This set must be
* synchronized.
*/
/**
* Names of types that have had files created but not closed.
*/
/**
* Names of source files closed in this round. This set must be
* synchronized. Its iterators should preserve insertion order.
*/
/**
* Names and class files of the class files closed in this round.
* This set must be synchronized. Its iterators should preserve
* insertion order.
*/
/**
* JavaFileObjects for source files closed in this round. This
* set must be synchronized. Its iterators should preserve
* insertion order.
*/
/**
* Names of all created source files. Its iterators should
* preserve insertion order.
*/
/**
* Names of all created class files. Its iterators should
* preserve insertion order.
*/
}
}
}
private JavaFileObject createSourceOrClassFile(boolean isSourceFile, String name) throws IOException {
if (lint) {
if (periodIndex != -1) {
}
}
checkFileReopening(fileObject, true);
if (lastRound)
if (isSourceFile)
else
}
checkFileReopening(fileObject, true);
if (fileObject instanceof JavaFileObject)
else
}
if (location instanceof StandardLocation) {
if (!stdLoc.isOutputLocation())
throw new IllegalArgumentException("Resource creation not supported in location " +
stdLoc);
}
}
// TODO: Only support reading resources in selected output
// locations? Only allow reading of non-source, non-class
// files from the supported input locations?
// In the following, getFileForInput is the "obvious" method
// to use, but it does not have the "obvious" semantics for
// SOURCE_OUTPUT and CLASS_OUTPUT. Conversely, getFileForOutput
// does not have the correct semantics for any "path" location
// with more than one component. So, for now, we use a hybrid
// invocation.
if (location.isOutputLocation()) {
null);
} else {
relativeName.toString());
}
if (fileObject == null) {
throw new FileNotFoundException(name);
}
// If the path was already opened for writing, throw an exception.
checkFileReopening(fileObject, false);
return new FilerInputFileObject(fileObject);
}
}
if (lint)
}
}
// Is the name of the form "package-info" or
// "foo.bar.package-info"?
if (periodIndex == -1) {
} else {
// "foo.bar.package-info." illegal
}
}
private void checkNameAndExistence(String typename, boolean allowUnnamedPackageInfo) throws FilerException {
// TODO: Check if type already exists on source or class path?
// If so, use warning message key proc.type.already.exists
if (lint)
}
}
/**
* Check to see if the file has already been opened; if so, throw
* an exception, otherwise add it to the set of files.
*/
private void checkFileReopening(FileObject fileObject, boolean addToHistory) throws FilerException {
if (lint)
}
}
if (addToHistory)
}
public boolean newFiles() {
return (!generatedSourceNames.isEmpty())
|| (!generatedClasses.isEmpty());
}
return generatedSourceNames;
}
return generatedSourceFileObjects;
}
return generatedClasses;
}
public void warnIfUnclosedFiles() {
if (!openTypeNames.isEmpty())
}
/**
* Update internal state for a new round.
*/
}
}
public void close() {
// Cross-round state
}
private void clearRoundState() {
}
/**
* Debugging function to display internal state.
*/
public void displayState() {
}
return "javac Filer";
}
/**
* Upon close, register files opened by create{Source, Class}File
* for annotation processing.
*/
/*
* If typeName is non-null, the file object was opened as a
* source or class file by the user. If a file was opened as
* a resource, typeName will be null and the file is *not*
* subject to annotation processing.
*/
if (!(fileObject instanceof JavaFileObject))
switch(javaFileObject.getKind()) {
case SOURCE:
break;
case CLASS:
break;
default:
break;
}
}
}
}