APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.processing

public Class JavacFiler

extends Object
implements Filer, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, javax.annotation.processing.Filer
Imports
java.io.Closeable, .FileNotFoundException, .InputStream, .OutputStream, .FilterOutputStream, .Reader, .Writer, .FilterWriter, .PrintWriter, .IOException, java.util.*, java.util.stream.Stream, javax.annotation.processing.*, javax.lang.model.SourceVersion, javax.lang.model.element.NestingKind, .Modifier, .Element, javax.tools.*, .JavaFileManager.Location, com.sun.tools.javac.code.Symbol.ClassSymbol, .Symbol.ModuleSymbol, .Symtab, .Symbol.PackageSymbol, com.sun.tools.javac.comp.Modules, com.sun.tools.javac.model.JavacElements, com.sun.tools.javac.resources.CompilerProperties.LintWarnings, .CompilerProperties.Warnings, com.sun.tools.javac.util.*, .DefinedBy.Api, com.sun.tools.javac.main.Option

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:
createSourceFile("foo.Bar")
...
createSourceFile("foo.Bar")
is disallowed as is opening a text file that happens to have the same name as a source file:
createSourceFile("foo.Bar")
...
createTextFile(SOURCE_TREE, "foo", new File("Bar"), null)

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.

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.

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
JavacFiler.FilerInputFileObject

Wrap a JavaFileObject to manage reading by the Filer.

private class
private class
JavacFiler.FilerOutputFileObject

Wrap a JavaFileObject to manage writing by the Filer.

private class
private class
JavacFiler.FilerOutputStream

Wrap a OutputStream returned from the JavaFileManager to properly register source or class files when they are closed.

private class
JavacFiler.FilerWriter

Wrap a Writer returned from the JavaFileManager to properly register source or class files when they are closed.

pack-priv static class

Field Summary

Modifier and TypeField and Description
private final Set<Pair<Symbol.ModuleSymbol, String>>
aggregateGeneratedClassNames

Names of all created class files.

private final Set<Pair<Symbol.ModuleSymbol, String>>
aggregateGeneratedSourceNames

Names of all created source files.

private static final String
pack-priv Context
private final String
pack-priv JavacElements
pack-priv JavaFileManager
private final Set<FileObject>
fileObjectHistory

Logical names of all created files.

private final Map<Symbol.ModuleSymbol, Map<String, JavaFileObject>>
generatedClasses

Names and class files of the class files closed in this round.

private Set<JavaFileObject>
generatedSourceFileObjects

JavaFileObjects for source files closed in this round.

private Set<String>
generatedSourceNames

Names of source files closed in this round.

private final Set<String>
private final Set<FileObject>
initialInputs

Initial inputs passed to the tool.

pack-priv boolean
pack-priv Log
pack-priv Modules
pack-priv Names
private static final String
private static final String
private final Set<String>
openTypeNames

Names of types that have had files created but not closed.

pack-priv Symtab

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
checkFileReopening(FileObject fileObject, boolean forWriting)

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
private void
checkName(String name, boolean allowUnnamedPackageInfo)

private void
checkNameAndExistence(Symbol.ModuleSymbol mod, String typename, boolean allowUnnamedPackageInfo)

private Pair<Symbol.ModuleSymbol, String>
private JavacFiler.Tuple3<JavaFileManager.Location, Symbol.ModuleSymbol, String>
checkOrInferModule(JavaFileManager.Location location, CharSequence moduleAndPkg, boolean write)

private void
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

private void
closeFileObject(Symbol.ModuleSymbol mod, String typeName, FileObject fileObject)

Upon close, register files opened by create{Source, Class}File for annotation processing.

private boolean
public JavaFileObject
createClassFile(CharSequence nameAndModule, Element... originatingElements)

Implements javax.annotation.processing.Filer.createClassFile.

Creates a new class file, and returns an object to allow writing to it.

public FileObject
createResource(JavaFileManager.Location location, CharSequence moduleAndPkg, CharSequence relativeName, Element... originatingElements)

Implements javax.annotation.processing.Filer.createResource.

Creates a new auxiliary resource file for writing and returns a file object for it.

public JavaFileObject
createSourceFile(CharSequence nameAndModule, Element... originatingElements)

Implements javax.annotation.processing.Filer.createSourceFile.

Creates a new source file and returns an object to allow writing to it.

private JavaFileObject
createSourceOrClassFile(Symbol.ModuleSymbol mod, boolean isSourceFile, String name, Element... originatingElements)

public void
displayState()

Debugging function to display internal state.

public Map<Symbol.ModuleSymbol, Map<String, JavaFileObject>>
public Set<JavaFileObject>
public Set<String>
public FileObject
getResource(JavaFileManager.Location location, CharSequence moduleAndPkg, CharSequence relativeName)

Implements javax.annotation.processing.Filer.getResource.

Returns an object for reading an existing resource.

private Symbol.ModuleSymbol
private boolean
isInFileObjectHistory(FileObject fileObject, boolean forWriting)

private boolean
isPackageInfo(String name, boolean allowUnnamedPackageInfo)

private void
public boolean
public void
newRound()

Update internal state for a new round.

private JavaFileObject[]
originatingFiles(Element[] originatingElements)

public void
setInitialState(Collection<? extends JavaFileObject> initialInputs, Collection<String> initialClassNames)

pack-priv void
setLastRound(boolean lastRound)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait