public class Block extends Excerpt implements SourceBuilder
ValueType.FieldReceiver| Modifier and Type | Method and Description |
|---|---|
Block |
add(Excerpt excerpt)
Equivalent to
add("%s", excerpt). |
Block |
add(java.lang.String fmt,
java.lang.Object... args)
Appends formatted text to the source.
|
protected void |
addFields(ValueType.FieldReceiver fields)
Implement this method to report the name and value of each field.
|
Block |
addLine(java.lang.String fmt,
java.lang.Object... args)
Appends a formatted line of code to the source.
|
void |
addTo(SourceBuilder source) |
Excerpt |
declare(Excerpt typeAndPreamble,
java.lang.String preferredName,
Excerpt value)
Declare a variable, preferably named
preferredName but renamed if necessary to avoid
collisions, in this block's preamble, returning an Excerpt to use it. |
<T extends Feature<T>> |
feature(FeatureType<T> featureType)
Returns the instance of
featureType appropriate for the source being written. |
Block |
innerBlock()
Contains variable declaration to an inner block.
|
static Block |
methodBody(SourceBuilder parent,
java.lang.String... paramNames) |
Scope |
scope()
Returns the current scope (e.g.
|
SourceStringBuilder |
subBuilder()
Returns a
SourceStringBuilder with the same configuration as this builder. |
SourceStringBuilder |
subScope(Scope newScope)
Returns a
SourceStringBuilder with the same configuration as this builder, but with
a different scope. |
public static Block methodBody(SourceBuilder parent, java.lang.String... paramNames)
public Excerpt declare(Excerpt typeAndPreamble, java.lang.String preferredName, Excerpt value)
preferredName but renamed if necessary to avoid
collisions, in this block's preamble, returning an Excerpt to use it. Duplicate declarations
will be elided.java.lang.IllegalStateException - if preferredName has already been added to this block
with a different declarationpublic Block innerBlock()
public Block add(java.lang.String fmt, java.lang.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 Block addLine(java.lang.String fmt, java.lang.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 Block add(Excerpt excerpt)
SourceBuilderadd("%s", excerpt).add 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 SourceStringBuilder subScope(Scope newScope)
SourceBuilderSourceStringBuilder with the same configuration as this builder, but with
a different scope. 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).subScope in interface SourceBuilderpublic <T extends Feature<T>> T feature(FeatureType<T> featureType)
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 SourceBuilderFeaturepublic Scope scope()
SourceBuilderscope in interface SourceBuilderpublic void addTo(SourceBuilder source)
protected void addFields(ValueType.FieldReceiver fields)
ValueType