Class MultiStatement
java.lang.Object
org.springframework.javapoet.support.MultiStatement
A
CodeBlock wrapper for multiple statements.- Since:
- 6.0
- Author:
- Stephane Nicoll
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd aCodeBlockrendered as-is using the specified callback.add(org.springframework.javapoet.CodeBlock codeBlock) Add the specifiedcodeblockrendered as-is.<T> MultiStatementAdd the statements produced from theitemGeneratorapplied on the specified items.addStatement(String code, Object... args) Add a statement using the specified formatted String and the specified arguments.addStatement(Consumer<org.springframework.javapoet.CodeBlock.Builder> code) Add a statement using the specified callback.addStatement(org.springframework.javapoet.CodeBlock statement) Add a statement.booleanisEmpty()Specify if this instance is empty.org.springframework.javapoet.CodeBlockReturn aCodeBlockthat applies all thestatementsof this instance.org.springframework.javapoet.CodeBlocktoCodeBlock(String lambda) Return aCodeBlockthat applies all thestatementsof this instance in the context of a lambda.org.springframework.javapoet.CodeBlocktoCodeBlock(org.springframework.javapoet.CodeBlock lambda) Return aCodeBlockthat applies all thestatementsof this instance in the context of a lambda.
-
Constructor Details
-
MultiStatement
public MultiStatement()
-
-
Method Details
-
isEmpty
public boolean isEmpty()Specify if this instance is empty.- Returns:
trueif no statement is registered,falseotherwise
-
add
Add the specifiedcodeblockrendered as-is.- Parameters:
codeBlock- the code block to add- Returns:
this, to facilitate method chaining- See Also:
-
add
Add aCodeBlockrendered as-is using the specified callback.- Parameters:
code- the callback to use- Returns:
this, to facilitate method chaining- See Also:
-
addStatement
Add a statement.- Parameters:
statement- the statement to add- Returns:
this, to facilitate method chaining
-
addStatement
Add a statement using the specified callback.- Parameters:
code- the callback to use- Returns:
this, to facilitate method chaining
-
addStatement
Add a statement using the specified formatted String and the specified arguments.- Parameters:
code- the code of the statementargs- the arguments for placeholders- Returns:
this, to facilitate method chaining- See Also:
-
CodeBlock.of(String, Object...)
-
addAll
public <T> MultiStatement addAll(Iterable<T> items, Function<T, org.springframework.javapoet.CodeBlock> itemGenerator) Add the statements produced from theitemGeneratorapplied on the specified items.- Type Parameters:
T- the type of the item- Parameters:
items- the items to handle, each item is represented as a statementitemGenerator- the item generator- Returns:
this, to facilitate method chaining
-
toCodeBlock
public org.springframework.javapoet.CodeBlock toCodeBlock()Return aCodeBlockthat applies all thestatementsof this instance. If only one statement is available, it is not completed using the;termination so that it can be used in the context of a lambda.- Returns:
- the statement(s)
-
toCodeBlock
public org.springframework.javapoet.CodeBlock toCodeBlock(org.springframework.javapoet.CodeBlock lambda) Return aCodeBlockthat applies all thestatementsof this instance in the context of a lambda.- Parameters:
lambda- the context of the lambda, must end with->- Returns:
- the lambda body
-
toCodeBlock
Return aCodeBlockthat applies all thestatementsof this instance in the context of a lambda.- Parameters:
lambda- the context of the lambda, must end with->- Returns:
- the lambda body
-