Class JSourceCode

java.lang.Object
org.exolab.javasource.JSourceCode

public final class JSourceCode extends Object
A class for holding in-memory Java source code.
Version:
$Revision: 7943 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $
Author:
Keith Visco
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default indentation size.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty JSourceCode.
    JSourceCode(String sourceCode)
    Creates a JSourceCode and adds the given String to its contents.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String statement)
    Adds the given statement to this JSourceCode.
    void
    add(String pattern, Object argument)
    Adds statement generated by replacing parameters of given pattern with given argument to this JSourceCode.
    void
    add(String pattern, Object[] arguments)
    Adds statements generated by replacing parameters of given pattern with given arguments to this JSourceCode.
    void
    add(String pattern, Object argument1, Object argument2)
    Adds statement generated by replacing parameters of given pattern with given arguments to this JSourceCode.
    void
    addIndented(String statement)
    Adds the given statement to this JSourceCode.
    void
    append(String segment)
    Appends the given String to the last line in this JSourceCode.
    void
    Clears all the code statements from this JSourceCode.
    void
    Copies the contents of this JSourceCode into the given JSourceCode.
    Returns a vector of source lines.
    void
    Increases the current indent level by 1.
    boolean
    Returns true if this JSourceCode is empty (ie.
    void
    Prints this JSourceCode to the given JSourceWriter.
    int
    Returns the number of source code lines (aka JCodeStatements) set so far.
    void
    Decreases the indent level by 1.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_INDENT_SIZE

      public static final int DEFAULT_INDENT_SIZE
      Default indentation size.
      See Also:
  • Constructor Details

    • JSourceCode

      public JSourceCode()
      Creates an empty JSourceCode.
    • JSourceCode

      public JSourceCode(String sourceCode)
      Creates a JSourceCode and adds the given String to its contents.
      Parameters:
      sourceCode - the source to add
  • Method Details

    • add

      public void add(String pattern, Object argument)
      Adds statement generated by replacing parameters of given pattern with given argument to this JSourceCode. The statement will be added on a new line.
      Parameters:
      pattern - Pattern for the statement.
      argument - Argument to replace first parameter in pattern.
    • add

      public void add(String pattern, Object argument1, Object argument2)
      Adds statement generated by replacing parameters of given pattern with given arguments to this JSourceCode. The statement will be added on a new line.
      Parameters:
      pattern - Pattern for the statement.
      argument1 - Argument to replace first parameter in pattern.
      argument2 - Argument to replace second parameter in pattern.
    • add

      public void add(String pattern, Object[] arguments)
      Adds statements generated by replacing parameters of given pattern with given arguments to this JSourceCode. Multiple statements can be separated by '\n' characters. Each statement will be added on a new line. If that statement starts with whitespace characters it will be indented.
      Parameters:
      pattern - Pattern for the statement.
      arguments - Arguments to replace parameters in pattern.
    • add

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

      public void addIndented(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(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.
    • size

      public int size()
      Returns the number of source code lines (aka JCodeStatements) set so far.
      Returns:
      The number of source code lines set so far.
    • getSource

      public Vector<JCodeStatement> getSource()
      Returns a vector of source lines.
      Returns:
      A vector of source lines.
    • toString

      public String toString()
      Overrides:
      toString in class Object