public class SourceStringBuilder extends java.lang.Object implements SourceBuilder
SourceBuilder that writes to a StringBuilder.| Modifier and Type | Method and Description |
|---|---|
SourceBuilder |
add(Excerpt excerpt)
Equivalent to
add("%s", excerpt). |
SourceBuilder |
add(java.lang.String fmt,
java.lang.Object... args)
Appends formatted text to the source.
|
SourceBuilder |
addLine(java.lang.String fmt,
java.lang.Object... args)
Appends a formatted line of code to the source.
|
static SourceBuilder |
compilable(FeatureSet features)
Returns a
SourceStringBuilder that returns compilable code. |
<T extends Feature<T>> |
feature(FeatureType<T> feature)
Returns the instance of
featureType appropriate for the source being written. |
Scope |
scope()
Returns the current scope (e.g.
|
static SourceBuilder |
simple(Feature<?>... features)
Returns a
SourceStringBuilder that always shortens types, even if that causes
conflicts. |
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. |
java.lang.String |
toString()
Returns the source code written so far.
|
public static SourceBuilder simple(Feature<?>... features)
SourceStringBuilder that always shortens types, even if that causes
conflicts.public static SourceBuilder compilable(FeatureSet features)
SourceStringBuilder that returns compilable code.public SourceBuilder add(Excerpt excerpt)
SourceBuilderadd("%s", excerpt).add in interface SourceBuilderpublic SourceBuilder 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 SourceBuilder 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 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> 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 SourceBuilderFeaturepublic Scope scope()
SourceBuilderscope in interface SourceBuilderpublic java.lang.String toString()
toString in class java.lang.Object