Class TemplateBuilder


  • class TemplateBuilder
    extends java.lang.Object
    Generates boiler-plate files from templates. Only very basic template processing is supplied - if we need something more sophisticated I suggest we use a third-party library.
    Since:
    4.2
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean evaluate​(java.lang.String condition)  
      void generate​(java.io.PrintWriter writer)
      Generate the output file.
      private java.lang.String getLine​(java.io.BufferedReader in)  
      private java.lang.String peekLine​(java.io.BufferedReader in)  
      private void process​(java.io.BufferedReader in, java.io.PrintWriter out, boolean ignoring)  
      private void processIf​(java.io.BufferedReader in, java.io.PrintWriter out, boolean ignoring)  
      private java.lang.String substitute​(java.lang.String text)  
      private java.lang.String substituteWithConditional​(java.lang.String variableName, java.lang.String values)  
      private java.lang.String substituteWithDefault​(java.lang.String variableName, java.lang.String defaultValue)  
      private void write​(java.io.PrintWriter out, java.lang.String text)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • template

        private final java.lang.String template
      • currentLine

        private java.lang.String currentLine
    • Constructor Detail

      • TemplateBuilder

        TemplateBuilder​(java.lang.String template,
                        CodeGeneratorSettings options)
        Parameters:
        template - the template. E.g. "/templates/Token.template".
        options - the processing options in force, such as "STATIC=yes"
    • Method Detail

      • generate

        public void generate​(java.io.PrintWriter writer)
                      throws java.io.IOException
        Generate the output file.
        Parameters:
        writer -
        Throws:
        java.io.IOException
      • peekLine

        private java.lang.String peekLine​(java.io.BufferedReader in)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getLine

        private java.lang.String getLine​(java.io.BufferedReader in)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • evaluate

        private boolean evaluate​(java.lang.String condition)
      • substitute

        private java.lang.String substitute​(java.lang.String text)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • substituteWithConditional

        private java.lang.String substituteWithConditional​(java.lang.String variableName,
                                                           java.lang.String values)
                                                    throws java.io.IOException
        Parameters:
        substring -
        defaultValue -
        Returns:
        Throws:
        java.io.IOException
      • substituteWithDefault

        private java.lang.String substituteWithDefault​(java.lang.String variableName,
                                                       java.lang.String defaultValue)
                                                throws java.io.IOException
        Parameters:
        variableName -
        defaultValue -
        Returns:
        Throws:
        java.io.IOException
      • write

        private void write​(java.io.PrintWriter out,
                           java.lang.String text)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • process

        private void process​(java.io.BufferedReader in,
                             java.io.PrintWriter out,
                             boolean ignoring)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • processIf

        private void processIf​(java.io.BufferedReader in,
                               java.io.PrintWriter out,
                               boolean ignoring)
                        throws java.io.IOException
        Throws:
        java.io.IOException