public static final class CodeBlock.Builder
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
CodeBlock.Builder |
add(CodeBlock codeBlock) |
CodeBlock.Builder |
add(java.lang.String format,
java.lang.Object... args)
Add code with positional or relative arguments.
|
CodeBlock.Builder |
addNamed(java.lang.String format,
java.util.Map<java.lang.String,?> arguments)
Adds code using named arguments.
|
CodeBlock.Builder |
addStatement(CodeBlock codeBlock) |
CodeBlock.Builder |
addStatement(java.lang.String format,
java.lang.Object... args) |
CodeBlock.Builder |
beginControlFlow(java.lang.String controlFlow,
java.lang.Object... args) |
CodeBlock |
build() |
CodeBlock.Builder |
clear() |
CodeBlock.Builder |
endControlFlow() |
CodeBlock.Builder |
endControlFlow(java.lang.String controlFlow,
java.lang.Object... args) |
CodeBlock.Builder |
indent() |
boolean |
isEmpty() |
CodeBlock.Builder |
nextControlFlow(java.lang.String controlFlow,
java.lang.Object... args) |
CodeBlock.Builder |
unindent() |
public boolean isEmpty()
public CodeBlock.Builder addNamed(java.lang.String format, java.util.Map<java.lang.String,?> arguments)
Named arguments specify their name after the '$' followed by : and the corresponding type
character. Argument names consist of characters in a-z, A-Z, 0-9, and _
and must
start with a lowercase character.
For example, to refer to the type Integer
with the argument name clazz
use a format string containing $clazz:T
and include the key clazz
with
value java.lang.Integer.class
in the argument map.
public CodeBlock.Builder add(java.lang.String format, java.lang.Object... args)
Relative arguments map 1:1 with the placeholders in the format string.
Positional arguments use an index after the placeholder to identify which argument index to use. For example, for a literal to reference the 3rd argument: "$3L" (1 based index)
Mixing relative and positional arguments in a call to add is invalid and will result in an error.
public CodeBlock.Builder beginControlFlow(java.lang.String controlFlow, java.lang.Object... args)
controlFlow
- the control flow construct and its code, such as "if (foo == 5)".
Shouldn't contain braces or newline characters.public CodeBlock.Builder nextControlFlow(java.lang.String controlFlow, java.lang.Object... args)
controlFlow
- the control flow construct and its code, such as "else if (foo == 10)".
Shouldn't contain braces or newline characters.public CodeBlock.Builder endControlFlow()
public CodeBlock.Builder endControlFlow(java.lang.String controlFlow, java.lang.Object... args)
controlFlow
- the optional control flow construct and its code, such as
"while(foo == 20)". Only used for "do/while" control flows.public CodeBlock.Builder addStatement(java.lang.String format, java.lang.Object... args)
public CodeBlock.Builder addStatement(CodeBlock codeBlock)
public CodeBlock.Builder add(CodeBlock codeBlock)
public CodeBlock.Builder indent()
public CodeBlock.Builder unindent()
public CodeBlock.Builder clear()
public CodeBlock build()
Copyright © 2020 Square, Inc.. All Rights Reserved.