Class AbstractJavaCodeProducer

    • Field Detail

      • JAVA_KEYWORDS

        public static final String[] JAVA_KEYWORDS
        Java keywords.
      • m_OutputBuffer

        protected StringBuilder m_OutputBuffer
        the buffer for assembling the help.
      • m_Copyright

        protected String m_Copyright
        the copyright string.
      • m_Package

        protected String m_Package
        the package of the class.
      • m_SimpleName

        protected String m_SimpleName
        the simple name of the class.
      • m_OutputDefaultValues

        protected boolean m_OutputDefaultValues
        whether to output default values as well.
      • m_Indentation

        protected int m_Indentation
        the indentation level.
      • m_ShortenedImports

        protected Map<String,​String> m_ShortenedImports
        for keeping track of the shortened imports.
      • m_AdditionalImportsInsertLocation

        protected int m_AdditionalImportsInsertLocation
        for inserting any additional imports.
      • m_VarNames

        protected NamedCounter m_VarNames
        the named counter for the variables.
      • m_JavaKeywords

        protected HashSet<String> m_JavaKeywords
        for checking the keywords.
    • Constructor Detail

      • AbstractJavaCodeProducer

        public AbstractJavaCodeProducer()
    • Method Detail

      • setCopyright

        public void setCopyright​(String value)
        Sets the copyright entity.
        Parameters:
        value - the entity owning the copyright
      • getCopyright

        public String getCopyright()
        Returns the copyright entity.
        Returns:
        the entity owning the copyright
      • copyrightTipText

        public String copyrightTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setOutputDefaultValues

        public void setOutputDefaultValues​(boolean value)
        Sets whether to output default values as well.
        Parameters:
        value - if true then default values are output as well
      • getOutputDefaultValues

        public boolean getOutputDefaultValues()
        Returns whyether default values are output as well.
        Returns:
        true if default values are output as well
      • outputDefaultValuesTipText

        public String outputDefaultValuesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setSimpleName

        protected void setSimpleName​(String value)
        Sets the simple name (without package) of the class to generate.
        Parameters:
        value - the simple name
      • getSimpleName

        protected String getSimpleName()
        Returns the simple name to use.
        Returns:
        the simple name
      • simpleNameTipText

        public String simpleNameTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPackage

        protected void setPackage​(String value)
        Sets the package name of the class to generate.
        Parameters:
        value - the package name
      • getPackage

        protected String getPackage()
        Returns the package name to use.
        Returns:
        the package name
      • packageTipText

        public String packageTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getOuterVariableName

        protected abstract String getOuterVariableName()
        The outer most variable name.
        Returns:
        the variable name
      • getCurrentVariable

        protected String getCurrentVariable()
        Returns the current variable name.
        Returns:
        the variable name
        See Also:
        getOuterVariableName()
      • getIndentation

        protected abstract String getIndentation()
        Returns the indentation for code inside the try-catch-block.
        Returns:
        the indentation string
      • shortenClassname

        protected String shortenClassname​(String name)
        Tries to shorten the classname. If it's possible, the class is added as an additional import and the simple name of the class is used (no package).
        Parameters:
        name - the classname to shorten
        Returns:
        the potentially shortened classname
      • getClassname

        protected String getClassname​(Class cls)
        Creates the class name.
        Parameters:
        cls - the class to create the class name string for
        Returns:
        the class name string
        See Also:
        shortenClassname(String)
      • getClassname

        protected String getClassname​(AbstractArgumentOption option)
        Creates the class name.
        Parameters:
        option - the option to create the class name string for
        Returns:
        the class name string
      • getClassname

        protected String getClassname​(Object obj)
        Creates the class name.
        Parameters:
        obj - the object to create the class name string for
        Returns:
        the class name string
      • getCast

        protected String getCast​(AbstractArgumentOption option)
        Creates the casting string.
        Parameters:
        option - the option to create the casting string for
        Returns:
        the casting string
      • getNextTmpVariable

        protected String getNextTmpVariable​(String base)
        Generates the next name for a temporary variable.
        Parameters:
        base - the base name of the temp variable
        Returns:
        the actual name of the temp variable
      • getNextTmpVariable

        protected String getNextTmpVariable​(AbstractOption option)
        Generates the next name for a temporary variable.
        Parameters:
        option - the option to generate the variable for
        Returns:
        the name of the temp variable
      • getNextTmpVariable

        protected String getNextTmpVariable​(Class cls)
        Generates the next name for a temporary variable.
        Parameters:
        cls - the class this temp variable is for
        Returns:
        the name of the temp variable
      • isClassName

        protected boolean isClassName​(String s)
        Checks whether a string represents a classname. Simply tries to instantiate a class with that name.
        Parameters:
        s - the string to check
        Returns:
        true if string resembles a class name
      • preIndent

        protected void preIndent​(Object value)
        Hook method that gets called before indentation is increased.
        Default implementation does nothing.
        Parameters:
        value - the current object
      • postIndent

        protected void postIndent​(Object value)
        Hook method that gets called just after the indentation got decreased.
        Default implementation does nothing.
        Parameters:
        value - the current object
      • processClassOption

        protected void processClassOption​(String variable,
                                          Object value)
        Processes the value of a class option.
        Parameters:
        variable - the name of the tmp variable to use
        value - the actual value
      • escapeDoubleQuotes

        protected String escapeDoubleQuotes​(String s)
        Properly escapes double quotes.
        Parameters:
        s - the string to process
        Returns:
        the processed string
      • preProduce

        protected void preProduce​(OptionManager manager,
                                  int index)
        Hook method that gets called just before an option gets produced.

        Default implementation does nothing
        Overrides:
        preProduce in class AbstractOptionProducer<String,​String>
        Parameters:
        manager - the option manager
        index - the index of the option
      • getRequiredImports

        protected List<String> getRequiredImports()
        Returns other necessary imports.
        Returns:
        the class names
      • addLicensePreamble

        protected void addLicensePreamble()
        Adds the license preamble.
      • addCopyright

        protected void addCopyright()
        Adds the copyright notice.
      • addPackage

        protected void addPackage()
        Adds the package for the generated code.
      • addImports

        protected void addImports()
        Adds the imports.
      • addClassJavadoc

        protected void addClassJavadoc()
        Adds the Javadoc for the class.
      • addClassStart

        protected void addClassStart()
        Adds the start of the enclosing "class" statement.

        Default implementation does not derive the class from another superclass.
      • addConstructor

        protected void addConstructor()
        Adds the constructor.

        Default implementation merely adds a default constructor.
      • addAdditionalMethods

        protected void addAdditionalMethods()
        Hook-method for adding additional methods necessary to make the class compile.

        Default implementation adds nothgin.
      • addMethodStart

        protected abstract void addMethodStart()
        Adds the method that encloses the generated code.
      • addMethodEnd

        protected abstract void addMethodEnd()
        Closes the method with the generated code.
      • addMainMethod

        protected void addMainMethod()
        Hook method for adding a main method.

        Default implementation merely instantiates a new instance of the class.
      • addClassEnd

        protected void addClassEnd()
        Adds the end of the enclosing "class" statement.
      • insertAdditionalImports

        protected void insertAdditionalImports()
        Inserts any additional imports, if necessary.