Class MultiStatement
java.lang.Object
org.springframework.javapoet.support.MultiStatement
A
CodeBlock
wrapper for multiple statements.- Since:
- 6.0
- Author:
- Stephane Nicoll
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd aCodeBlock
rendered as-is using the specified callback.add
(org.springframework.javapoet.CodeBlock codeBlock) Add the specifiedcodeblock
rendered as-is.<T> MultiStatement
Add the statements produced from theitemGenerator
applied 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.boolean
isEmpty()
Specify if this instance is empty.org.springframework.javapoet.CodeBlock
Return aCodeBlock
that applies all thestatements
of this instance.org.springframework.javapoet.CodeBlock
toCodeBlock
(String lambda) Return aCodeBlock
that applies all thestatements
of this instance in the context of a lambda.org.springframework.javapoet.CodeBlock
toCodeBlock
(org.springframework.javapoet.CodeBlock lambda) Return aCodeBlock
that applies all thestatements
of 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:
true
if no statement is registered,false
otherwise
-
add
Add the specifiedcodeblock
rendered as-is.- Parameters:
codeBlock
- the code block to add- Returns:
this
, to facilitate method chaining- See Also:
-
add
Add aCodeBlock
rendered 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 theitemGenerator
applied 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 aCodeBlock
that applies all thestatements
of 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 aCodeBlock
that applies all thestatements
of this instance in the context of a lambda.- Parameters:
lambda
- the context of the lambda, must end with->
- Returns:
- the lambda body
-
toCodeBlock
Return aCodeBlock
that applies all thestatements
of this instance in the context of a lambda.- Parameters:
lambda
- the context of the lambda, must end with->
- Returns:
- the lambda body
-