public class CompilationUnitBuilder extends Object implements SourceBuilder
SourceBuilder which also handles package declaration and imports.| Constructor and Description |
|---|
CompilationUnitBuilder(ProcessingEnvironment env,
QualifiedName classToWrite,
Collection<QualifiedName> nestedClasses)
Returns a
CompilationUnitBuilder for classToWrite. |
| Modifier and Type | Method and Description |
|---|---|
SourceBuilder |
add(Excerpt excerpt)
Equivalent to
add("%s", excerpt). |
CompilationUnitBuilder |
add(String fmt,
Object... args)
Appends formatted text to the source.
|
CompilationUnitBuilder |
addLine(String fmt,
Object... args)
Appends a formatted line of code to the source.
|
<T extends Feature<T>> |
feature(FeatureType<T> feature)
Returns the instance of
featureType appropriate for the source being written. |
SourceStringBuilder |
subBuilder()
Returns a
SourceStringBuilder with the same configuration as this builder. |
String |
toString() |
public CompilationUnitBuilder(ProcessingEnvironment env, QualifiedName classToWrite, Collection<QualifiedName> nestedClasses)
CompilationUnitBuilder for classToWrite. The file preamble (package
and imports) will be generated automatically; the feature set will be taken from env..public CompilationUnitBuilder add(String fmt, Object... args)
SourceBuilderFormatting is done by String.format(java.lang.String, java.lang.Object...), except that:
Package and PackageElement instances use their fully-qualified names
(no "package " prefix).
Class, TypeElement, DeclaredType and QualifiedName
instances use their qualified names where necessary, or shorter versions if a suitable
import line can be added.
Excerpt instances have Excerpt.addTo(SourceBuilder) called.
add in interface SourceBuilderpublic SourceBuilder add(Excerpt excerpt)
SourceBuilderadd("%s", excerpt).add in interface SourceBuilderpublic CompilationUnitBuilder addLine(String fmt, Object... args)
SourceBuilderFormatting is done by String.format(java.lang.String, java.lang.Object...), except that:
Package and PackageElement instances use their fully-qualified names
(no "package " prefix).
Class, TypeElement, DeclaredType and QualifiedName
instances use their qualified names where necessary, or shorter versions if a suitable
import line can be added.
Excerpt instances have Excerpt.addTo(SourceBuilder) called.
addLine in interface SourceBuilderpublic SourceStringBuilder subBuilder()
SourceBuilderSourceStringBuilder with the same configuration as this builder. In
particular, the TypeShortener will be shared, so any types added to the sub-builder
will be included in the imports for this builder (and its parents).subBuilder in interface SourceBuilderpublic <T extends Feature<T>> T feature(FeatureType<T> feature)
SourceBuilderfeatureType appropriate for the source being written. For
instance, code.feature(GUAVA).isAvailable() returns true if the Guava
library can be used in the generated source code.
Fluent extension point for features dynamically determined based on the current
ProcessingEnvironment.
feature in interface SourceBuilderFeatureCopyright © 2016 Google, Inc.. All rights reserved.