Class MultiStatement

java.lang.Object
org.springframework.javapoet.support.MultiStatement

public final class MultiStatement extends Object
A CodeBlock wrapper for multiple statements.
Since:
6.0
Author:
Stephane Nicoll
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Consumer<org.springframework.javapoet.CodeBlock.Builder> code)
    Add a CodeBlock rendered as-is using the specified callback.
    add(org.springframework.javapoet.CodeBlock codeBlock)
    Add the specified codeblock rendered as-is.
    addAll(Iterable<T> items, Function<T,org.springframework.javapoet.CodeBlock> itemGenerator)
    Add the statements produced from the itemGenerator 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
    Specify if this instance is empty.
    org.springframework.javapoet.CodeBlock
    Return a CodeBlock that applies all the statements of this instance.
    org.springframework.javapoet.CodeBlock
    Return a CodeBlock that applies all the statements of this instance in the context of a lambda.
    org.springframework.javapoet.CodeBlock
    toCodeBlock(org.springframework.javapoet.CodeBlock lambda)
    Return a CodeBlock that applies all the statements of this instance in the context of a lambda.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public MultiStatement add(org.springframework.javapoet.CodeBlock codeBlock)
      Add the specified codeblock rendered as-is.
      Parameters:
      codeBlock - the code block to add
      Returns:
      this, to facilitate method chaining
      See Also:
    • add

      public MultiStatement add(Consumer<org.springframework.javapoet.CodeBlock.Builder> code)
      Add a CodeBlock rendered as-is using the specified callback.
      Parameters:
      code - the callback to use
      Returns:
      this, to facilitate method chaining
      See Also:
    • addStatement

      public MultiStatement addStatement(org.springframework.javapoet.CodeBlock statement)
      Add a statement.
      Parameters:
      statement - the statement to add
      Returns:
      this, to facilitate method chaining
    • addStatement

      public MultiStatement addStatement(Consumer<org.springframework.javapoet.CodeBlock.Builder> code)
      Add a statement using the specified callback.
      Parameters:
      code - the callback to use
      Returns:
      this, to facilitate method chaining
    • addStatement

      public MultiStatement addStatement(String code, Object... args)
      Add a statement using the specified formatted String and the specified arguments.
      Parameters:
      code - the code of the statement
      args - 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 the itemGenerator 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 statement
      itemGenerator - the item generator
      Returns:
      this, to facilitate method chaining
    • toCodeBlock

      public org.springframework.javapoet.CodeBlock toCodeBlock()
      Return a CodeBlock that applies all the statements 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 a CodeBlock that applies all the statements of this instance in the context of a lambda.
      Parameters:
      lambda - the context of the lambda, must end with ->
      Returns:
      the lambda body
    • toCodeBlock

      public org.springframework.javapoet.CodeBlock toCodeBlock(String lambda)
      Return a CodeBlock that applies all the statements of this instance in the context of a lambda.
      Parameters:
      lambda - the context of the lambda, must end with ->
      Returns:
      the lambda body