ca.quine.jcommons.sourcegen
Class FormattingRules

java.lang.Object
  |
  +--ca.quine.jcommons.sourcegen.FormattingRules

public class FormattingRules
extends Object

Holds information about the indenting and other formatting of generated source code, and provides helper methods for getting the length of source lines given the current settings. The default settings are Windows/DOS style line breaks (CRLF), 80 character lines, and 4 spaces per indent.

The FormattingRules class is general enough for most purposes. If greater flexibility in source code formatting is desired, Jalopy is recommended. It can run on all generated source after generation is complete. Since all method lines are added explicitly, brace style and indents within a method are left up to the user. SourceGen will not modify these. It is recommended (but not required) that tabs be used for the method lines. These will be converted into the appropriate number of spaces if space indents are requested.


Constructor Summary
FormattingRules()
           
FormattingRules(boolean useSpaces, int indentSize)
           
 
Method Summary
 String getIndent()
          Returns a String containing a number of spaces or a tab representing one indent level based on the current indent settings.
 int getIndentSize()
           
 int getLength(int indentLevel, String text)
          Calculates the length in characters of the input String after the given number of indents is applied.
 int getLength(String input)
          Using the indent size for each tab, figure out the length in characters of the input String.
 int getLineLength()
           
 int getMethodIndent()
          Returns the number of indents to use for a method (normally 1).
 boolean isUnixNewLine()
           
 boolean isUseSpaces()
           
 void methodCodeIndent(StringBuffer buffer)
          Appends an indent to the given buffer for code inside a method with the current indent settings.
 void methodIndent(StringBuffer buffer)
          Appends a method indent to the given buffer with the current indent settings.
 void newLine(StringBuffer buffer)
          Appends a new line to the given buffer with the current indent settings.
 void setIndentSize(int indentSize)
           
 void setLineLength(int lineLength)
           
 void setUnixNewLine(boolean isUnixNewLine)
           
 void setUseSpaces(boolean useSpaces)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormattingRules

public FormattingRules()

FormattingRules

public FormattingRules(boolean useSpaces,
                       int indentSize)
Method Detail

isUnixNewLine

public boolean isUnixNewLine()

setUnixNewLine

public void setUnixNewLine(boolean isUnixNewLine)

getIndentSize

public int getIndentSize()

setIndentSize

public void setIndentSize(int indentSize)

isUseSpaces

public boolean isUseSpaces()

setUseSpaces

public void setUseSpaces(boolean useSpaces)

getLineLength

public int getLineLength()

setLineLength

public void setLineLength(int lineLength)

methodIndent

public void methodIndent(StringBuffer buffer)
Appends a method indent to the given buffer with the current indent settings.

Parameters:
buffer -

methodCodeIndent

public void methodCodeIndent(StringBuffer buffer)
Appends an indent to the given buffer for code inside a method with the current indent settings.

Parameters:
buffer -

newLine

public void newLine(StringBuffer buffer)
Appends a new line to the given buffer with the current indent settings.

Parameters:
buffer -

getIndent

public String getIndent()
Returns a String containing a number of spaces or a tab representing one indent level based on the current indent settings.


getLength

public int getLength(String input)
Using the indent size for each tab, figure out the length in characters of the input String.

Parameters:
input - a String with initial tabs
Returns:
the length in characters, counting indentSize characters for each tab character found in the input

getLength

public int getLength(int indentLevel,
                     String text)
Calculates the length in characters of the input String after the given number of indents is applied.

Returns:
the length in characters, counting indentSize characters for each indent level, plus the length of the input text.

getMethodIndent

public int getMethodIndent()
Returns the number of indents to use for a method (normally 1). This method is for future use for inner classes.