Class LordOfTheStrings.CodeBlockBuilder
java.lang.Object
org.springframework.data.javapoet.LordOfTheStrings.CodeBlockBuilder
- Enclosing class:
- LordOfTheStrings
An extended variant of
CodeBlock.Builder that supports building statements in a fluent way and extended for
functional statement creation.
This builder provides additional methods for creating and managing code blocks, including support for control flow, named arguments, and conditional statements. It is designed to enhance the readability and flexibility of code block construction.
Use this builder to create complex code structures in a fluent and intuitive manner.
- See Also:
-
CodeBlock.Builder
-
Method Summary
Modifier and TypeMethodDescriptionAdd a formatted statement to the code block.add(org.springframework.javapoet.CodeBlock codeBlock) Add aCodeBlockto the code block.Add named arguments to the code block.addStatement(String format, @Nullable Object... args) Add a formatted statement to the code block.Add a statement to the code block using aConsumerto configure it.addStatement(org.springframework.javapoet.CodeBlock codeBlock) Add aCodeBlockas a statement to the code block.beginControlFlow(String controlFlow, @Nullable Object... args) Begin a control flow block with the specified format and arguments.org.springframework.javapoet.CodeBlockbuild()Build theCodeBlockfrom the current state of the builder.clear()Clear the current state of the builder.End the current control flow block.endControlFlow(String controlFlow, @Nullable Object... args) End the current control flow block with the specified format and arguments.indent()Indent the current code block.booleanisEmpty()Determine whether this builder is empty.nextControlFlow(String controlFlow, @Nullable Object... args) Begin the next control flow block with the specified format and arguments.unindent()Unindent the current code block.
-
Method Details
-
isEmpty
public boolean isEmpty()Determine whether this builder is empty.- Returns:
trueif the builder is empty;falseotherwise.- See Also:
-
CodeBlock.Builder.isEmpty()
-
add
@Contract("_, _ -> this") public LordOfTheStrings.CodeBlockBuilder add(String format, @Nullable Object... args) Add a formatted statement to the code block.- Parameters:
format- the format string.args- the arguments for the format string.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.add(String, Object...)
-
addStatement
@Contract("_ -> this") public LordOfTheStrings.CodeBlockBuilder addStatement(org.springframework.javapoet.CodeBlock codeBlock) Add aCodeBlockas a statement to the code block.- Parameters:
codeBlock- theCodeBlockto add.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.addStatement(CodeBlock)
-
addStatement
@Contract("null -> fail; _ -> this") public LordOfTheStrings.CodeBlockBuilder addStatement(Consumer<LordOfTheStrings.StatementBuilder> consumer) Add a statement to the code block using aConsumerto configure it.- Parameters:
consumer- theConsumerto configure the statement.- Returns:
thisbuilder.
-
add
@Contract("_ -> this") public LordOfTheStrings.CodeBlockBuilder add(org.springframework.javapoet.CodeBlock codeBlock) Add aCodeBlockto the code block.- Parameters:
codeBlock- theCodeBlockto add.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.addStatement(CodeBlock)
-
addStatement
@Contract("_, _ -> this") public LordOfTheStrings.CodeBlockBuilder addStatement(String format, @Nullable Object... args) Add a formatted statement to the code block.- Parameters:
format- the format string.args- the arguments for the format string.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.addStatement(String, Object...)
-
addNamed
@Contract("_, _ -> this") public LordOfTheStrings.CodeBlockBuilder addNamed(String format, Map<String, ?> arguments) Add named arguments to the code block.- Parameters:
format- the format string.arguments- the named arguments.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.addNamed(String, Map)
-
beginControlFlow
@Contract("_, _ -> this") public LordOfTheStrings.CodeBlockBuilder beginControlFlow(String controlFlow, @Nullable Object... args) Begin a control flow block with the specified format and arguments.- Parameters:
controlFlow- the control flow format string.args- the arguments for the control flow format string.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.beginControlFlow(String, Object...)
-
endControlFlow
@Contract("_, _ -> this") public LordOfTheStrings.CodeBlockBuilder endControlFlow(String controlFlow, @Nullable Object... args) End the current control flow block with the specified format and arguments.- Parameters:
controlFlow- the control flow format string.args- the arguments for the control flow format string.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.endControlFlow(String, Object...)
-
endControlFlow
End the current control flow block.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.endControlFlow()
-
nextControlFlow
@Contract("_, _ -> this") public LordOfTheStrings.CodeBlockBuilder nextControlFlow(String controlFlow, @Nullable Object... args) Begin the next control flow block with the specified format and arguments.- Parameters:
controlFlow- the control flow format string.args- the arguments for the control flow format string.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.nextControlFlow(String, Object...)
-
indent
Indent the current code block.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.indent()
-
unindent
Unindent the current code block.- Returns:
thisbuilder.- See Also:
-
CodeBlock.Builder.unindent()
-
build
Build theCodeBlockfrom the current state of the builder.- Returns:
- the constructed
CodeBlock.
-
clear
Clear the current state of the builder.- Returns:
thisbuilder.
-