Interface GeneratorContext

public interface GeneratorContext
Provides metadata to deferred binding generators.

Methods

commit(TreeLogger, PrintWriter)Commits source generation begun with tryCreate(TreeLogger, String, String).
commitResource(TreeLogger, OutputStream)Commits resource generation begun with tryCreateResource(TreeLogger, String).
getPropertyOracle()Gets the property oracle for the current generator context.
getTypeOracle()Gets the type oracle for the current generator context.
tryCreate(TreeLogger, String, String)Attempts to get a PrintWriter so that the caller can generate the source code for the named type.
tryCreateResource(TreeLogger, String)Attempts to get an OutputStream so that the caller can write file contents into the named file underneath the compilation output directory.

Method Detail

commit

public void commit(TreeLogger logger, PrintWriter pw)
Commits source generation begun with tryCreate(TreeLogger, String, String).

Parameters

logger
pw

commitResource

public void commitResource(TreeLogger logger, OutputStream os)
     throws UnableToCompleteException
Commits resource generation begun with tryCreateResource(TreeLogger, String).

Parameters

logger
os

getPropertyOracle

public PropertyOracle getPropertyOracle()
Gets the property oracle for the current generator context. Generators can use the property oracle to query deferred binding properties.

getTypeOracle

public TypeOracle getTypeOracle()
Gets the type oracle for the current generator context. Generators can use the type oracle to ask questions about the entire translatable code base.

Return Value

a TypeOracle over all the relevant translatable compilation units in the source path

tryCreate

public PrintWriter tryCreate(TreeLogger logger, String packageName, String simpleName)
Attempts to get a PrintWriter so that the caller can generate the source code for the named type. If the named types already exists, null is returned to indicate that no work needs to be done. The file is not committed until commit(TreeLogger, PrintWriter) is called.

Parameters

logger
a logger; normally the logger passed into Generator.generate(TreeLogger, GeneratorContext, String) or a branch thereof
packageName
the name of the package to which the create type belongs
simpleName
the unqualified source name of the type being generated

Return Value

null if the package and class already exists, otherwise a PrintWriter is returned.

tryCreateResource

public OutputStream tryCreateResource(TreeLogger logger, String partialPath)
     throws UnableToCompleteException
Attempts to get an OutputStream so that the caller can write file contents into the named file underneath the compilation output directory. The file is not committed until commitResource(TreeLogger, OutputStream) is called.

Parameters

logger
a logger; normally the logger passed into Generator.generate(TreeLogger, GeneratorContext, String) or a branch thereof
partialPath
the name of the file whose contents are to be written; the name can include subdirectories separated by forward slashes ('/')

Return Value

an OutputStream into which file contents can be written, or null if a resource by that name is already pending or already exists