Class SourceBuilder
java.lang.Object
org.inferred.freebuilder.processor.source.SourceBuilder
Source code builder, using format strings for readability, with sensible formatting for
type objects.
// Imports StringBuilder and appends " StringBuilder foo;\n" to the source code.
builder.addLine(" %s foo;", StringBuilder.class);-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final CompilationUnitBuilder -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSourceBuilder(ScopeHandler.Reflection reflect, FeatureSet features) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidAppends formatted text to the source.Equivalent toadd("%s", excerpt).Appends a formatted line of code to the source.<T extends Feature<T>>
Tfeature(FeatureType<T> featureType) Returns the instance offeatureTypeappropriate for the source being written.static SourceBuilderforEnvironment(ProcessingEnvironment env, FeatureSet features) Returns aSourceBuilder.static SourceBuilderforTesting(Feature<?>... features) Returns aSourceBuilderusingfeatures.static SourceBuilderforTesting(FeatureSet features) Returns aSourceBuilderusingfeatures.scope()Returns the current scope (e.g.toString()typename()Return the qualified name of the main type declared by this unit.
-
Field Details
-
LINE_SEPARATOR
-
source
-
-
Constructor Details
-
SourceBuilder
-
-
Method Details
-
forEnvironment
Returns aSourceBuilder.envwill be inspected for potential import collisions. Iffeaturesis not null, it will be used instead of those deduced fromenv. -
forTesting
Returns aSourceBuilderusingfeatures. The system classloader will be inspected for potential import collisions. -
forTesting
Returns aSourceBuilderusingfeatures. The system classloader will be inspected for potential import collisions. -
add
Appends formatted text to the source.Formatting supports
%sand%n$s. Most args are converted according to theirObject.toString()method, except that:-
PackageandPackageElementinstances use their fully-qualified names (no "package " prefix). -
Class,TypeElement,DeclaredTypeandQualifiedNameinstances use their qualified names where necessary, or shorter versions if a suitable import line can be added. -
Excerptinstances haveExcerpt.addTo(SourceBuilder)called.
-
-
add
Equivalent toadd("%s", excerpt). -
addLine
Appends a formatted line of code to the source.Formatting supports
%sand%n$s. Most args are converted according to theirObject.toString()method, except that:-
PackageandPackageElementinstances use their fully-qualified names (no "package " prefix). -
Class,TypeElement,DeclaredTypeandQualifiedNameinstances use their qualified names where necessary, or shorter versions if a suitable import line can be added. -
Excerptinstances haveExcerpt.addTo(SourceBuilder)called.
-
-
feature
Returns the instance offeatureTypeappropriate for the source being written. For instance,code.feature(returns true if the Guava library can be used in the generated source code.GUAVA).isAvailable()Fluent extension point for features dynamically determined based on the current
ProcessingEnvironment.- See Also:
-
scope
Returns the current scope (e.g. visible method parameters). -
typename
Return the qualified name of the main type declared by this unit.- Throws:
IllegalStateException- if no package or type has been declared
-
toString
-
add
-