Class CodeGenerator<T>

Type Parameters:
T - The interface that results from compiling and merging the runtime code that is generated.

public class CodeGenerator<T> extends Object
A code generator is responsible for generating the Java source code required to complete the implementation of an abstract template. A code generator can contain one or more ClassGenerators that implement outer and inner classes associated with a particular runtime generated instance.

Drill supports two ways to generate and compile the code from a code generator: via byte-code manipulations or as "plain Java."

When using byte-code transformations, the code generator is used with a class transformer to merge precompiled template code with runtime generated and compiled query specific code to create a runtime instance.

The code generator can optionally be marked as "plain Java" capable. This means that the generated code can be compiled directly as a Java class without the normal byte-code manipulations. Plain Java allows the option to persist, and debug, the generated code when building new generated classes or otherwise working with generated code. To turn on debugging, see the explanation in ClassBuilder.

  • Method Details

    • plainJavaCapable

      public void plainJavaCapable(boolean flag)
      Indicates that the code for this class can be generated using the "Plain Java" mechanism based on inheritance. The byte-code method is more lenient, so some code is missing some features such as proper exception labeling, etc. Set this option to true once the generation mechanism for a class has been cleaned up to work via the plain Java mechanism.
      flag - true if the code generated from this instance is ready to be compiled as a plain Java class
    • preferPlainJava

      public void preferPlainJava(boolean flag)
      Identifies that this generated class should be generated via the plain Java mechanism. This flag only has meaning if the generated class is capable of plain Java generation.
      flag - true if the class should be generated and compiled as a plain Java class (rather than via byte-code manipulations)
    • supportsPlainJava

      public boolean supportsPlainJava()
    • isPlainJava

      public boolean isPlainJava()
    • saveCodeForDebugging

      public void saveCodeForDebugging(boolean persist)
      Debug-time option to persist the code for the generated class to permit debugging. Has effect only when code is generated using the plain Java option. Code is written to the code directory specified in ClassBuilder. To debug code, set this option, then point your IDE to the code directory when the IDE prompts you for the source code location.
      persist - true to write the code to disk, false (the default) to keep code only in memory.
    • isCodeToBeSaved

      public boolean isCodeToBeSaved()
    • getRoot

      public ClassGenerator<T> getRoot()
    • generate

      public void generate()
    • generateAndGet

      public String generateAndGet() throws IOException
    • getGeneratedCode

      public String getGeneratedCode()
    • getDefinition

      public TemplateClassDefinition<T> getDefinition()
    • getMaterializedClassName

      public String getMaterializedClassName()
    • getClassName

      public String getClassName()
    • get

      public static <T> CodeGenerator<T> get(TemplateClassDefinition<T> definition)
    • get

      public static <T> CodeGenerator<T> get(TemplateClassDefinition<T> definition, OptionSet optionManager)
    • getRoot

      public static <T> ClassGenerator<T> getRoot(TemplateClassDefinition<T> definition, OptionSet optionManager)
    • getRoot

      public static <T> ClassGenerator<T> getRoot(MappingSet mappingSet, TemplateClassDefinition<T> definition, OptionSet optionManager)
    • get

      public static <T> CodeGenerator<T> get(MappingSet mappingSet, TemplateClassDefinition<T> definition, OptionSet optionManager)
    • hashCode

      public int hashCode()
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      equals in class Object