Class JSourceCode


  • public class JSourceCode
    extends java.lang.Object
    A class for holding in-memory Java source code.
    Version:
    $Revision$ $Date$
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private short currentIndent
      The current indent size
      private short indentSize
      The indent size
      private java.util.List<JCodeStatement> source
      A list of JCodeStatements
    • Constructor Summary

      Constructors 
      Constructor Description
      JSourceCode()
      Creates an empty JSourceCode
      JSourceCode​(java.lang.String sourceCode)
      Creates a JSourceCode and adds the given String to it's contents
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void add​(java.lang.String statement)
      Adds the given statement to this JSourceCode.
      void add​(java.lang.String statement, short indentSize)
      Deprecated.
      this method is not here any mode in castor codegen 1.3rc1
      private void addCodeStatement​(JCodeStatement jcs)
      Adds the given JCodeStatement to this JSourceCode
      void addIndented​(java.lang.String statement)
      Adds the given statement to this JSourceCode.
      void append​(java.lang.String segment)
      Appends the given String to the last line in this JSourceCode
      void clear()
      Clears all the code statements from this JSourceCode
      void copyInto​(JSourceCode jsc)
      Copies the contents of this JSourceCode into the given JSourceCode
      void indent()
      Increases the current indent level by 1
      boolean isEmpty()
      Returns true if this JSourceCode is empty (ie.
      void print​(JSourceWriter jsw)
      Prints this JSourceCode to the given JSourceWriter
      java.lang.String toString()
      Returns the String representation of this JSourceCode
      void unindent()
      Decreases the indent level by 1
      • Methods inherited from class java.lang.Object

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

      • source

        private java.util.List<JCodeStatement> source
        A list of JCodeStatements
      • indentSize

        private short indentSize
        The indent size
      • currentIndent

        private short currentIndent
        The current indent size
    • Constructor Detail

      • JSourceCode

        public JSourceCode()
        Creates an empty JSourceCode
      • JSourceCode

        public JSourceCode​(java.lang.String sourceCode)
        Creates a JSourceCode and adds the given String to it's contents
        Parameters:
        sourceCode - the source to add
    • Method Detail

      • add

        public void add​(java.lang.String statement)
        Adds the given statement to this JSourceCode. The statement will be added on a new line.
        Parameters:
        statement - the statement to add
      • add

        public void add​(java.lang.String statement,
                        short indentSize)
        Deprecated.
        this method is not here any mode in castor codegen 1.3rc1
        Adds the given statement to this JSourceCode. The statement will be added on a new line.
        Parameters:
        statement - the statement to add
        indentSize - the indentSize is the size of the indentation to use when printing this JSourceCode
        See Also:
        print(org.codehaus.modello.plugin.java.javasource.JSourceWriter)
      • addIndented

        public void addIndented​(java.lang.String statement)
        Adds the given statement to this JSourceCode. The statement will be added on a new line and added with increased indent. This is a convenience method for the sequence indent(); add(statement); unindent();
        Parameters:
        statement - the statement to add
      • append

        public void append​(java.lang.String segment)
        Appends the given String to the last line in this JSourceCode
        Parameters:
        segment - the String to append
      • clear

        public void clear()
        Clears all the code statements from this JSourceCode
      • copyInto

        public void copyInto​(JSourceCode jsc)
        Copies the contents of this JSourceCode into the given JSourceCode
        Parameters:
        jsc - the JSourceCode to copy this JSourceCode into
      • indent

        public void indent()
        Increases the current indent level by 1
      • isEmpty

        public boolean isEmpty()
        Returns true if this JSourceCode is empty (ie. no source).
        Returns:
        true if this JSourceCode is empty.
      • print

        public void print​(JSourceWriter jsw)
        Prints this JSourceCode to the given JSourceWriter
        Parameters:
        jsw - the JSourceWriter to print to
      • unindent

        public void unindent()
        Decreases the indent level by 1
      • toString

        public java.lang.String toString()
        Returns the String representation of this JSourceCode
        Overrides:
        toString in class java.lang.Object
        Returns:
        the String representation of this JSourceCode
      • addCodeStatement

        private void addCodeStatement​(JCodeStatement jcs)
        Adds the given JCodeStatement to this JSourceCode
        Parameters:
        jcs - the JCodeStatement to add