Interface Gizmo


public sealed interface Gizmo
A simplified class file writer.
  • Method Details

    • create

      static Gizmo create(ClassOutput outputHandler)
      Returns a new Gizmo which outputs to the given handler by default.
      Parameters:
      outputHandler - the output handler (must not be null)
      Returns:
      a new Gizmo which outputs to the given handler by default
    • withOutput

      Gizmo withOutput(ClassOutput outputHandler)
      Returns a Gizmo instance which uses the given output handler.
      Parameters:
      outputHandler - the output handler (must not be null)
      Returns:
      a Gizmo instance which uses the given output handler
    • withDebugInfo

      Gizmo withDebugInfo(boolean debugInfo)
      Returns a Gizmo instance which has debug info output enabled or disabled.

      By default, debug info is included.

      Parameters:
      debugInfo - true to include debug info, or false to exclude debug info
      Returns:
      a Gizmo instance which has debug info output enabled or disabled
    • withParameters

      Gizmo withParameters(boolean parameters)
      Returns a Gizmo instance which has parameters output enabled or disabled. This setting affects whether method parameter names are recorded in a MethodParameters attribute, which is separate from debug info and appears when using runtime reflection. Some frameworks require this attribute to be present.

      By default, parameter name info is included.

      Parameters:
      parameters - true to include parameter name info, or false to exclude parameter name info
      Returns:
      a Gizmo instance which has parameters output enabled or disabled
    • withLambdasAsAnonymousClasses

      Gizmo withLambdasAsAnonymousClasses(boolean lambdasAsAnonymousClasses)
      Returns a Gizmo instance which emits lambdas as anonymous classes if the parameter is true. When enabled, lambda bodies are not generated into synthetic methods on the generated class, but into additional anonymous classes. Further, lambda instances are not obtained through invokedynamic, but through regular instantiation of the additional anonymous classes.

      This doesn't affect runtime semantics of generated code, but it does affect the number of generated classes and, as of this writing, also runtime memory consumption.

      By default, lambdas are not generated as anonymous classes.

      Parameters:
      lambdasAsAnonymousClasses - whether lambdas should be generated as anonymous classes
      Returns:
      a Gizmo instance which emits lambdas as anonymous classes if the parameter is true
    • withDefaultModifiers

      Gizmo withDefaultModifiers(Consumer<ModifierConfigurator> builder)
      Returns a Gizmo instance which uses the default modifiers configured by the given configurator.
      Parameters:
      builder - the builder for the defaults (must not be null)
      Returns:
      a Gizmo instance which uses the default modifiers configured by the given configurator
    • class_

      default ClassDesc class_(String name, Consumer<ClassCreator> builder)
      Add a new class.
      Parameters:
      name - the fully qualified (dot-separated) binary class name (must not be null)
      builder - the builder for the class (must not be null)
      Returns:
      the descriptor of the created class (not null)
    • class_

      ClassDesc class_(ClassDesc desc, Consumer<ClassCreator> builder)
      Add a new class.
      Parameters:
      desc - the class descriptor (must not be null)
      builder - the builder for the class (must not be null)
      Returns:
      the descriptor given for desc
    • interface_

      default ClassDesc interface_(String name, Consumer<InterfaceCreator> builder)
      Add a new interface.
      Parameters:
      name - the fully qualified (dot-separated) binary class name
      builder - the builder for the interface (must not be null)
      Returns:
      the descriptor of the created interface (not null)
    • interface_

      ClassDesc interface_(ClassDesc desc, Consumer<InterfaceCreator> builder)
      Add a new interface.
      Parameters:
      desc - the class descriptor (must not be null)
      builder - the builder for the class (must not be null)
      Returns:
      the descriptor given for desc