Class JavaCodeBuilder

java.lang.Object
com.northconcepts.datapipeline.sourcecode.JavaCodeBuilder

public class JavaCodeBuilder extends Object
A simple model containing generated Java code, imports, and variable names.
  • Constructor Details

    • JavaCodeBuilder

      public JavaCodeBuilder()
  • Method Details

    • getPackage

      public String getPackage()
      Returns the package declared in the generated source; classes in it are not imported by addImport(Class).
    • setPackage

      public JavaCodeBuilder setPackage(String packageName)
      Sets the package declared in the generated source; set it before addImport(Class) so classes in it are not imported.
    • addImport

      public JavaCodeBuilder addImport(String packageOrClass)
      Add an import for a package, package wildcard, or individual class.
    • addImport

      public JavaCodeBuilder addImport(Class<?> importClass)
      Add an import for an individual class.
    • addImport

      public JavaCodeBuilder addImport(Class<?> importClass, boolean allClassesInPackage)
      Add an import for an individual class or all all classes in the specified class' package (if allClassesInPackage is true).
    • getImports

      public Set<String> getImports()
    • createVariable

      public String createVariable(String variable)
      Reserves and returns a unique variable name: the given name if unused, otherwise the name plus the first free suffix from 0 to 99 (throws when all are taken).
    • getSourceWriter

      public CodeWriter getSourceWriter()
      Returns the writer for the code body, which getSource() places after the package and import lines.
    • getSource

      public String getSource()
      Returns the package line, the sorted imports and the code body; closes the source writer, so call it once all code is written.