Class CodeBlock.Builder

java.lang.Object
io.micronaut.sourcegen.javapoet.CodeBlock.Builder
Enclosing class:
CodeBlock

public static final class CodeBlock.Builder extends Object
  • Method Details

    • isEmpty

      public boolean isEmpty()
    • addNamed

      public CodeBlock.Builder addNamed(String format, Map<String,?> arguments)
      Adds code using named 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.

    • add

      public CodeBlock.Builder add(String format, Object... args)
      Add code with positional or relative arguments.

      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.

    • beginControlFlow

      public CodeBlock.Builder beginControlFlow(String controlFlow, Object... args)
      Parameters:
      controlFlow - the control flow construct and its code, such as "if (foo == 5)". Shouldn't contain braces or newline characters.
    • nextControlFlow

      public CodeBlock.Builder nextControlFlow(String controlFlow, Object... args)
      Parameters:
      controlFlow - the control flow construct and its code, such as "else if (foo == 10)". Shouldn't contain braces or newline characters.
    • endControlFlow

      public CodeBlock.Builder endControlFlow()
    • endControlFlow

      public CodeBlock.Builder endControlFlow(String controlFlow, Object... args)
      Parameters:
      controlFlow - the optional control flow construct and its code, such as "while(foo == 20)". Only used for "do/while" control flows.
    • addStatement

      public CodeBlock.Builder addStatement(String format, Object... args)
    • addStatement

      public CodeBlock.Builder addStatement(CodeBlock codeBlock)
    • add

      public CodeBlock.Builder add(CodeBlock codeBlock)
    • indent

      public CodeBlock.Builder indent()
    • unindent

      public CodeBlock.Builder unindent()
    • clear

      public CodeBlock.Builder clear()
    • build

      public CodeBlock build()