| 限定符和类型 | 方法和说明 |
|---|---|
CodeBlock.Builder |
add(CodeBlock codeBlock) |
CodeBlock.Builder |
add(String format,
Object... args)
Add code with positional or relative arguments.
|
CodeBlock.Builder |
addNamed(String format,
Map<String,?> arguments)
Adds code using named arguments.
|
CodeBlock.Builder |
addStatement(CodeBlock codeBlock) |
CodeBlock.Builder |
addStatement(String format,
Object... args) |
CodeBlock.Builder |
beginControlFlow(String controlFlow,
Object... args) |
CodeBlock |
build() |
CodeBlock.Builder |
clear() |
CodeBlock.Builder |
endControlFlow() |
CodeBlock.Builder |
endControlFlow(String controlFlow,
Object... args) |
CodeBlock.Builder |
indent() |
boolean |
isEmpty() |
CodeBlock.Builder |
nextControlFlow(String controlFlow,
Object... args) |
CodeBlock.Builder |
unindent() |
public boolean isEmpty()
public CodeBlock.Builder addNamed(String format, Map<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(String format, 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(String controlFlow, 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(String controlFlow, 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(String controlFlow, 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(String format, 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 © 2025 fossc. All rights reserved.