public class StandardGeneratorContext extends Object implements GeneratorContext
Modifier and Type | Class and Description |
---|---|
static class |
StandardGeneratorContext.GeneratedUnitImpl
This generated unit acts as a normal generated unit as well as a buffer
into which generators can write their source.
|
Constructor and Description |
---|
StandardGeneratorContext(CompilerContext compilerContext,
CompilationState compilationState,
ArtifactSet allGeneratedArtifacts,
boolean isProdMode)
Normally, the compiler host would be aware of the same types that are
available in the supplied type oracle although it isn't strictly required.
|
Modifier and Type | Method and Description |
---|---|
void |
addGeneratedUnit(GeneratedUnit gu)
Adds a generated unit to the context if not already present, but will not
overwrite an existing unit.
|
void |
addGeneratedUnits(Collection<GeneratedUnit> generatedUnits)
Adds generated units to the context, but will not overwrite any existing
units that might already be present.
|
void |
addGeneratedUnitsFromCache()
Adds all available cached generated units to the context.
|
void |
addGeneratedUnitsMarkedForReuseFromCache()
Adds cached generated units to the context that have been marked for reuse.
|
boolean |
checkRebindRuleAvailable(String sourceTypeName)
Checks whether a rebind rule is available for a given sourceTypeName.
|
void |
clear()
Frees memory used up by compilation state.
|
void |
commit(TreeLogger logger,
PrintWriter pw)
Commits a pending generated type.
|
void |
commitArtifact(TreeLogger logger,
Artifact<?> artifact)
Adds an Artifact to the context's ArtifactSets.
|
void |
commitArtifactsFromCache(TreeLogger logger)
Commits all available cached Artifacts to the context.
|
GeneratedResource |
commitResource(TreeLogger logger,
OutputStream os)
Commits resource generation begun with
GeneratorContext.tryCreateResource(TreeLogger, String) . |
ArtifactSet |
finish(TreeLogger logger)
Call this whenever generators are known to not be running to clear out
uncommitted compilation units and to force committed compilation units to
be parsed and added to the type oracle.
|
Set<String> |
getActiveLinkerNames() |
ArtifactSet |
getArtifacts()
Gets newly committed artifacts.
|
CachedGeneratorResult |
getCachedGeneratorResult()
Gets the previously cached rebind result for the current generator.
|
GeneratorContext |
getCanonicalContext() |
CompilationState |
getCompilationState() |
Map<String,GeneratedUnit> |
getGeneratedUnitMap()
Gets all committed Java units.
|
PropertyOracle |
getPropertyOracle()
Gets the property oracle for the current generator context.
|
ResourceOracle |
getResourcesOracle()
Returns a resource oracle containing all resources that are mapped into the
module's source (or super-source) paths.
|
TypeOracle |
getTypeOracle()
Gets the type oracle for the current generator context.
|
boolean |
isDirty() |
boolean |
isGeneratorResultCachingEnabled()
Check whether generator result caching is currently enabled.
|
boolean |
isGlobalCompile()
Returns whether the current compile and generator passes are executing in
the global phase of a compile, as opposed to further down in the dependency
tree.
|
boolean |
isProdMode()
Returns true if generators are being run to produce code for a production
compile.
|
void |
reset()
Clears all accumulated artifacts and state so that the context can be used
as if from scratch.
|
String |
runGenerator(TreeLogger logger,
Class<? extends Generator> generatorClass,
String typeName)
This method is maintained for backwards compatibility.
|
RebindResult |
runGeneratorIncrementally(TreeLogger logger,
Class<? extends Generator> generatorClass,
String typeName)
Runs a generator incrementally, with support for managing the returned
RebindResult object, which can contain cached results. |
void |
setCachedGeneratorResult(CachedGeneratorResult cachedRebindResult)
Set previously cached rebind result for currently active generator.
|
void |
setCurrentGenerator(Class<? extends Generator> currentGenerator) |
void |
setCurrentRebindBinaryTypeName(String currentRebindBinaryTypeName) |
void |
setGeneratorResultCachingEnabled(boolean enabled) |
void |
setPropertyOracle(PropertyOracle propertyOracle)
Sets the current transient property oracle to answer current property
questions.
|
void |
setRebindRuleResolver(RebindRuleResolver resolver) |
PrintWriter |
tryCreate(TreeLogger logger,
String packageName,
String simpleTypeName)
Attempts to get a
PrintWriter so that the caller can generate
the source code for the named type. |
OutputStream |
tryCreateResource(TreeLogger logger,
String partialPath)
Attempts to get an
OutputStream so that the caller can write
file contents into the named file underneath the compilation output
directory. |
boolean |
tryReuseTypeFromCache(String typeName)
Adds a type name to the list of types to be reused from cache, if
available.
|
public StandardGeneratorContext(CompilerContext compilerContext, CompilationState compilationState, ArtifactSet allGeneratedArtifacts, boolean isProdMode)
public void addGeneratedUnit(GeneratedUnit gu)
public void addGeneratedUnits(Collection<GeneratedUnit> generatedUnits)
public void addGeneratedUnitsFromCache()
public void addGeneratedUnitsMarkedForReuseFromCache()
public boolean checkRebindRuleAvailable(String sourceTypeName)
checkRebindRuleAvailable
in interface GeneratorContext
sourceTypeName
- the name of a type to check for rebind rule
availability.public void clear()
public final void commit(TreeLogger logger, PrintWriter pw)
commit
in interface GeneratorContext
public void commitArtifact(TreeLogger logger, Artifact<?> artifact)
commitArtifact
in interface GeneratorContext
logger
- a logger; normally the logger passed into the currently
invoked generator or a branch thereofartifact
- the Artifact to provide to the Linker chain.public void commitArtifactsFromCache(TreeLogger logger)
public GeneratedResource commitResource(TreeLogger logger, OutputStream os) throws UnableToCompleteException
GeneratorContext
GeneratorContext.tryCreateResource(TreeLogger, String)
.commitResource
in interface GeneratorContext
UnableToCompleteException
- if the resource cannot be written to
disk, if the specified stream is unknown, or if the stream has
already been committedpublic ArtifactSet finish(TreeLogger logger) throws UnableToCompleteException
UnableToCompleteException
public boolean isDirty()
public void reset()
public ArtifactSet getArtifacts()
public CachedGeneratorResult getCachedGeneratorResult()
getCachedGeneratorResult
in interface GeneratorContext
CachedGeneratorResult
object, if one has been provided to
the context. Null is returned if there is no previous result
available.public GeneratorContext getCanonicalContext()
public CompilationState getCompilationState()
public Map<String,GeneratedUnit> getGeneratedUnitMap()
public final PropertyOracle getPropertyOracle()
GeneratorContext
getPropertyOracle
in interface GeneratorContext
public boolean isGlobalCompile()
public ResourceOracle getResourcesOracle()
GeneratorContext
com.google.gwt.core.client
as
a source package, then a resource at
com/google/gwt/core/client/Foo.properties
would be exposed by
this resource oracle.getResourcesOracle
in interface GeneratorContext
public final TypeOracle getTypeOracle()
GeneratorContext
getTypeOracle
in interface GeneratorContext
public boolean isGeneratorResultCachingEnabled()
GeneratorContext
isGeneratorResultCachingEnabled
in interface GeneratorContext
public boolean isProdMode()
GeneratorContext
isProdMode
in interface GeneratorContext
public String runGenerator(TreeLogger logger, Class<? extends Generator> generatorClass, String typeName) throws UnableToCompleteException
runGeneratorIncrementally(com.google.gwt.core.ext.TreeLogger, java.lang.Class<? extends com.google.gwt.core.ext.Generator>, java.lang.String)
should be used instead.UnableToCompleteException
public RebindResult runGeneratorIncrementally(TreeLogger logger, Class<? extends Generator> generatorClass, String typeName) throws UnableToCompleteException
RebindResult
object, which can contain cached results. This is a
replacement for the runGenerator(com.google.gwt.core.ext.TreeLogger, java.lang.Class<? extends com.google.gwt.core.ext.Generator>, java.lang.String)
method.
If the passed in generatorClass is an instance of
IncrementalGenerator
, it's
IncrementalGenerator.generateIncrementally(com.google.gwt.core.ext.TreeLogger, com.google.gwt.core.ext.GeneratorContext, java.lang.String)
method will be called.
Otherwise, for backwards compatibility, the generatorClass will be wrapped
in a IncrementalGenerator
instance, and it's
Generator.generate(com.google.gwt.core.ext.TreeLogger, com.google.gwt.core.ext.GeneratorContext, java.lang.String)
method will be called.
logger
- generatorClass
- typeName
- UnableToCompleteException
public void setCachedGeneratorResult(CachedGeneratorResult cachedRebindResult)
public void setCurrentRebindBinaryTypeName(String currentRebindBinaryTypeName)
public void setGeneratorResultCachingEnabled(boolean enabled)
public void setPropertyOracle(PropertyOracle propertyOracle)
public void setRebindRuleResolver(RebindRuleResolver resolver)
public PrintWriter tryCreate(TreeLogger logger, String packageName, String simpleTypeName)
GeneratorContext
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 GeneratorContext.commit(TreeLogger, PrintWriter)
is
called.tryCreate
in interface GeneratorContext
logger
- a logger; normally the logger passed into the currently
invoked generator, or a branch thereofpackageName
- the name of the package to which the create type belongssimpleTypeName
- the unqualified source name of the type being generatednull
if the package and class already exists,
otherwise a PrintWriter
is returned.public OutputStream tryCreateResource(TreeLogger logger, String partialPath) throws UnableToCompleteException
GeneratorContext
OutputStream
so that the caller can write
file contents into the named file underneath the compilation output
directory. The file is not committed until
GeneratorContext.commitResource(TreeLogger, OutputStream)
is called.tryCreateResource
in interface GeneratorContext
logger
- a logger; normally the logger passed into the currently
invoked generator, or a branch thereofpartialPath
- the name of the file whose contents are to be written;
the name can include subdirectories separated by forward slashes
('/')OutputStream
into which file contents can be
written, or null
if a resource by that name is already
pending or already existsUnableToCompleteException
- if the resource could not be initialized
for some reason, such as if the specified partial path is invalidpublic boolean tryReuseTypeFromCache(String typeName)
tryReuseTypeFromCache
in interface GeneratorContext
typeName
- The fully qualified name of a type.Copyright © 2018. All rights reserved.