Class CodeWriter
java.lang.Object
com.squareup.javapoet.CodeWriter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final Stringprivate intprivate booleanprivate static final StringSentinel value that indicates that no user-provided package has been set.private final Appendableprivate String(package private) intWhen emitting a statement, this is the line of the statement currently being written.private boolean -
Constructor Summary
ConstructorsConstructorDescriptionCodeWriter(Appendable out) CodeWriter(Appendable out, String indent, Map<String, ClassName> importedTypes, Set<String> staticImports) CodeWriter(Appendable out, String indent, Set<String> staticImports) -
Method Summary
Modifier and TypeMethodDescription(package private) CodeWriterEmitsswith indentation as required.voidemitAnnotations(List<AnnotationSpec> annotations, boolean inline) voidemitComment(CodeBlock codeBlock) private voidvoidemitJavadoc(CodeBlock javadocCodeBlock) private voidvoidemitModifiers(Set<Modifier> modifiers) voidemitModifiers(Set<Modifier> modifiers, Set<Modifier> implicitModifiers) Emitsmodifiersin the standard order.private booleanemitStaticImportMember(String canonical, String part) voidemitTypeVariables(List<TypeVariableName> typeVariables) Emit type variables with their bounds.private static StringextractMemberName(String part) private voidimportableType(ClassName className) indent()indent(int levels) (package private) StringlookupName(ClassName className) Returns the best name to identifyclassNamewith in the current context.popType()pushPackage(String packageName) private ClassNameReturns the class referenced bysimpleName, using the current nesting context and imports.private ClassNamestackClassName(int stackDepth, String simpleName) Returns the class namedsimpleNamewhen nested in the class atstackDepth.Returns the types that should have been imported for this code.unindent()unindent(int levels)
-
Field Details
-
NO_PACKAGE
Sentinel value that indicates that no user-provided package has been set. -
indent
-
out
-
indentLevel
private int indentLevel -
javadoc
private boolean javadoc -
comment
private boolean comment -
packageName
-
typeSpecStack
-
staticImportClassNames
-
staticImports
-
importedTypes
-
importableTypes
-
referencedNames
-
trailingNewline
private boolean trailingNewline -
statementLine
int statementLineWhen emitting a statement, this is the line of the statement currently being written. The first line of a statement is indented normally and subsequent wrapped lines are double-indented. This is -1 when the currently-written line isn't part of a statement.
-
-
Constructor Details
-
CodeWriter
CodeWriter(Appendable out) -
CodeWriter
CodeWriter(Appendable out, String indent, Set<String> staticImports) -
CodeWriter
-
-
Method Details
-
importedTypes
-
indent
-
indent
-
unindent
-
unindent
-
pushPackage
-
popPackage
-
pushType
-
popType
-
emitComment
- Throws:
IOException
-
emitJavadoc
- Throws:
IOException
-
emitAnnotations
- Throws:
IOException
-
emitModifiers
public void emitModifiers(Set<Modifier> modifiers, Set<Modifier> implicitModifiers) throws IOException Emitsmodifiersin the standard order. Modifiers inimplicitModifierswill not be emitted.- Throws:
IOException
-
emitModifiers
- Throws:
IOException
-
emitTypeVariables
Emit type variables with their bounds. This should only be used when declaring type variables; everywhere else bounds are omitted.- Throws:
IOException
-
emit
- Throws:
IOException
-
emit
- Throws:
IOException
-
emit
- Throws:
IOException
-
extractMemberName
-
emitStaticImportMember
- Throws:
IOException
-
emitLiteral
- Throws:
IOException
-
lookupName
-
importableType
-
resolve
-
stackClassName
-
emitAndIndent
Emitsswith indentation as required. It's important that all code that writes tooutdoes it through here, since we emit indentation lazily in order to avoid unnecessary trailing whitespace.- Throws:
IOException
-
emitIndentation
- Throws:
IOException
-
suggestedImports
-