public class CompilationUnitWriter extends Object implements SourceBuilder, Closeable
| Constructor and Description |
|---|
CompilationUnitWriter(Filer filer,
Elements elements,
SourceLevel sourceLevel,
boolean isGuavaAvailable,
QualifiedName classToWrite,
Collection<QualifiedName> nestedClasses,
Element originatingElement)
Returns a
CompilationUnitWriter for classToWrite. |
| Modifier and Type | Method and Description |
|---|---|
SourceBuilder |
add(Excerpt excerpt)
Equivalent to
add("%s", excerpt). |
CompilationUnitWriter |
add(String fmt,
Object... args)
Appends formatted text to the source.
|
CompilationUnitWriter |
addLine(String fmt,
Object... args)
Appends a formatted line of code to the source.
|
void |
close() |
SourceLevel |
getSourceLevel() |
boolean |
isGuavaAvailable() |
SourceStringBuilder |
subBuilder()
Returns a
SourceStringBuilder with the same configuration as this builder. |
public CompilationUnitWriter(Filer filer, Elements elements, SourceLevel sourceLevel, boolean isGuavaAvailable, QualifiedName classToWrite, Collection<QualifiedName> nestedClasses, Element originatingElement) throws FilerException
CompilationUnitWriter for classToWrite. The file preamble (package
and imports) will be generated automatically.FilerException - if a Filer guarantee is violated (see the FilerException
JavaDoc for more information); propagated because this is often seen in GUIDE projects,
so should be downgraded to a warning, whereas runtime exceptions should be flagged as an
internal error to the userpublic CompilationUnitWriter 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 CompilationUnitWriter 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 SourceLevel getSourceLevel()
getSourceLevel in interface SourceBuilderpublic boolean isGuavaAvailable()
isGuavaAvailable in interface SourceBuilderpublic void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2016 Google, Inc.. All rights reserved.