public class SourceBuilder
extends java.lang.Object
// Imports StringBuilder and appends " StringBuilder foo;\n" to the source code.
builder.addLine(" %s foo;", StringBuilder.class);| 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.
|
<T extends Feature<T>> |
feature(FeatureType<T> featureType)
Returns the instance of
featureType appropriate for the source being written. |
static SourceBuilder |
forEnvironment(javax.annotation.processing.ProcessingEnvironment env,
FeatureSet features)
Returns a
SourceBuilder. |
static SourceBuilder |
forTesting(Feature<?>... features)
Returns a
SourceBuilder using features. |
static SourceBuilder |
forTesting(FeatureSet features)
Returns a
SourceBuilder using features. |
Scope |
scope()
Returns the current scope (e.g.
|
java.lang.String |
toString() |
QualifiedName |
typename()
Return the qualified name of the main type declared by this unit.
|
public static SourceBuilder forEnvironment(javax.annotation.processing.ProcessingEnvironment env, FeatureSet features)
SourceBuilder. env will be inspected for potential import collisions.
If features is not null, it will be used instead of those deduced from env.public static SourceBuilder forTesting(Feature<?>... features)
SourceBuilder using features. The system classloader will be
inspected for potential import collisions.public static SourceBuilder forTesting(FeatureSet features)
SourceBuilder using features. The system classloader will be
inspected for potential import collisions.public SourceBuilder add(java.lang.String fmt, java.lang.Object... args)
Formatting supports %s and %n$s. Most args are converted according to their
Object.toString() method, 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.
public SourceBuilder add(Excerpt excerpt)
add("%s", excerpt).public SourceBuilder addLine(java.lang.String fmt, java.lang.Object... args)
Formatting supports %s and %n$s. Most args are converted according to their
Object.toString() method, 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.
public <T extends Feature<T>> T feature(FeatureType<T> featureType)
featureType 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.
Featurepublic Scope scope()
public QualifiedName typename()
java.lang.IllegalStateException - if no package or type has been declaredpublic java.lang.String toString()
toString in class java.lang.Object