Code blocks support placeholders like java.. Where String#format
uses percent % to reference target values, this class uses dollar sign $ and has
its own set of permitted placeholders:
$L emits a literal value with no escaping. Arguments for literals may be
strings, primitives, type declarations, annotations and even other code blocks.
$N emits a name, using name collision avoidance where necessary. Arguments
for names may be strings (actually any character sequence),
parameters, fields, methods, and types.
$S escapes the value as a string, wraps it with double quotes, and emits
that. For example, 6" sandwich is emitted "6\" sandwich".
$T emits a type reference. Types will be imported if possible. Arguments
for types may be classes, ,* type mirrors, and elements.
$$ emits a dollar sign.
$W emits a space or a newline, depending on its position on the line. This prefers
to wrap lines before 100 columns.
$Z acts as a zero-width space. This prefers to wrap lines before 100 columns.
$> increases the indentation level.
$< decreases the indentation level.
$[ begins a statement. For multiline statements, every line after the first line
is double-indented.
$] ends a statement.
| Modifier and Type | Class and Description |
|---|---|
| public static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final List | |
| pack-priv final List | formatParts
A heterogeneous list containing string literals and value placeholders. |
| private static final Pattern | |
| private static final Pattern |
| Modifier and Type | Method and Description |
|---|---|
| public static CodeBlock. | |
| public boolean | equals(Object
the reference object with which to compare. o)Overrides java. Indicates whether some other object is "equal to" this one. |
| public int | |
| public boolean | |
| public static CodeBlock | |
| public static Collector | |
| public static Collector | |
| public static CodeBlock | |
| public CodeBlock. | |
| public String |
| args | back to summary |
|---|---|
| pack-priv final List<Object> args | |
| formatParts | back to summary |
|---|---|
| pack-priv final List<String> formatParts A heterogeneous list containing string literals and value placeholders. | |
| LOWERCASE | back to summary |
|---|---|
| private static final Pattern LOWERCASE | |
| NAMED_ARGUMENT | back to summary |
|---|---|
| private static final Pattern NAMED_ARGUMENT | |
| CodeBlock | back to summary |
|---|---|
| private CodeBlock(CodeBlock. | |
| builder | back to summary |
|---|---|
| public static CodeBlock. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() | |
| join | back to summary |
|---|---|
| public static CodeBlock join(Iterable<CodeBlock> codeBlocks, String separator) Joins | |
| joining | back to summary |
|---|---|
| public static Collector A | |
| joining | back to summary |
|---|---|
| public static Collector A | |
| of | back to summary |
|---|---|
| public static CodeBlock of(String format, Object... args) | |
| toBuilder | back to summary |
|---|---|
| public CodeBlock. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final List | |
| pack-priv final List |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public CodeBlock. | |
| public CodeBlock. | |
| private void | |
| public CodeBlock. | |
| public CodeBlock. | |
| public CodeBlock. | |
| private Object | |
| private String | |
| private String | |
| private TypeName | |
| public CodeBlock. | beginControlFlow(String
the control flow construct and its code, such as "if (foo == 5)".
Shouldn't contain braces or newline characters. controlFlow, Object... args)
|
| public CodeBlock | |
| public CodeBlock. | |
| public CodeBlock. | |
| public CodeBlock. | endControlFlow(String
the optional control flow construct and its code, such as
"while(foo == 20)". Only used for "do/while" control flows. controlFlow, Object... args)
|
| public CodeBlock. | |
| public boolean | |
| private boolean | |
| public CodeBlock. | nextControlFlow(String
the control flow construct and its code, such as "else if (foo == 10)".
Shouldn't contain braces or newline characters. controlFlow, Object... args)
|
| public CodeBlock. |
| args | back to summary |
|---|---|
| pack-priv final List<Object> args | |
| formatParts | back to summary |
|---|---|
| pack-priv final List<String> formatParts | |
| Builder | back to summary |
|---|---|
| private Builder() | |
| add | back to summary |
|---|---|
| public CodeBlock. Add code with positional or relative arguments. 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. | |
| add | back to summary |
|---|---|
| public CodeBlock. | |
| addArgument | back to summary |
|---|---|
| private void addArgument(String format, char c, Object arg) | |
| addNamed | back to summary |
|---|---|
| public CodeBlock. Adds code using named arguments. Named arguments specify their name after the '$' followed by : and the corresponding type
character. Argument names consist of characters in For example, to refer to the type | |
| addStatement | back to summary |
|---|---|
| public CodeBlock. | |
| addStatement | back to summary |
|---|---|
| public CodeBlock. | |
| argToLiteral | back to summary |
|---|---|
| private Object argToLiteral(Object o) | |
| argToName | back to summary |
|---|---|
| private String argToName(Object o) | |
| argToString | back to summary |
|---|---|
| private String argToString(Object o) | |
| argToType | back to summary |
|---|---|
| private TypeName argToType(Object o) | |
| beginControlFlow | back to summary |
|---|---|
public CodeBlock.
| |
| build | back to summary |
|---|---|
| public CodeBlock build() | |
| clear | back to summary |
|---|---|
| public CodeBlock. | |
| endControlFlow | back to summary |
|---|---|
| public CodeBlock. | |
| endControlFlow | back to summary |
|---|---|
public CodeBlock.
| |
| indent | back to summary |
|---|---|
| public CodeBlock. | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() | |
| isNoArgPlaceholder | back to summary |
|---|---|
| private boolean isNoArgPlaceholder(char c) | |
| nextControlFlow | back to summary |
|---|---|
public CodeBlock.
| |
| unindent | back to summary |
|---|---|
| public CodeBlock. | |
| Modifier and Type | Field and Description |
|---|---|
| private final CodeBlock. | |
| private final String | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv CodeBlock. | |
| pack-priv CodeBlock | |
| pack-priv CodeBlock. |
| builder | back to summary |
|---|---|
| private final CodeBlock. | |
| delimiter | back to summary |
|---|---|
| private final String delimiter | |
| first | back to summary |
|---|---|
| private boolean first | |
| CodeBlockJoiner | back to summary |
|---|---|
| pack-priv CodeBlockJoiner(String delimiter, CodeBlock. | |
| add | back to summary |
|---|---|
| pack-priv CodeBlock. | |
| join | back to summary |
|---|---|
| pack-priv CodeBlock join() | |
| merge | back to summary |
|---|---|
| pack-priv CodeBlock. | |