org.sourceflow
Class CodeStyle

java.lang.Object
  extended byorg.sourceflow.CodeStyle

public class CodeStyle
extends java.lang.Object

The base class for all code styles. The code style classes allows configuring some aspects of the source code generated. The code style classes also contain helper methods for the code generators. To create new code styles, this class should be subclassed.


Field Summary
static CodeStyle C
          The default C code style.
static CodeStyle CSHARP
          The default C# code style.
static CodeStyle JAVA
          The default Java code style.
static CodeStyle VISUAL_BASIC
          The default Visual Basic code style.
 
Constructor Summary
CodeStyle(int margin, java.lang.String indent)
          Creates a new code style.
 
Method Summary
 java.lang.String addStringEscapes(java.lang.String str, char escape)
          Adds escapes in front of all " characters in a string.
 java.lang.String getIndent(int level)
          Returns the indentation string for the specified level.
 java.lang.String getLowerCase(java.lang.String str)
          Returns the lower-case version of a string.
 int getMargin()
          Returns the right print margin.
 java.lang.String getMixedCase(java.lang.String str, boolean initialUpper)
          Returns the mixed-case version of a string.
 java.lang.String getStringConstant(java.lang.String str, char escape)
          Creates a string constant from the specified string.
 java.lang.String getUpperCase(java.lang.String str)
          Returns the upper-case version of a string.
 java.util.ArrayList lineBreak(java.lang.String str, int margin)
          Returns a list with all the lines in a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

C

public static final CodeStyle C
The default C code style.


CSHARP

public static final CodeStyle CSHARP
The default C# code style.


JAVA

public static final CodeStyle JAVA
The default Java code style.


VISUAL_BASIC

public static final CodeStyle VISUAL_BASIC
The default Visual Basic code style.

Constructor Detail

CodeStyle

public CodeStyle(int margin,
                 java.lang.String indent)
Creates a new code style.

Parameters:
margin - the print margin
indent - the indentation string
Method Detail

getMargin

public int getMargin()
Returns the right print margin.

Returns:
the print margin

getIndent

public java.lang.String getIndent(int level)
Returns the indentation string for the specified level.

Parameters:
level - the indentation level
Returns:
a string containing the indentation

getStringConstant

public java.lang.String getStringConstant(java.lang.String str,
                                          char escape)
Creates a string constant from the specified string. This will add " characters to start and the end, and all " character inside the string will be escaped. Also, any occurence of the escape character itself will be doubled (i.e. "\" becomes "\\").

Parameters:
str - the string to convert
escape - the escape character to use
Returns:
a string constant

getUpperCase

public java.lang.String getUpperCase(java.lang.String str)
Returns the upper-case version of a string. This method also handles transitions from a lower-case letter to an upper-case letter (inside the string) by appending a '_'. This will maintain the word stem separation, also in the upper-case string. Any characters outside the [A-Za-z0-9_] range will be removed from the string.

Parameters:
str - the string to transform
Returns:
the all upper-case version of the string

getLowerCase

public java.lang.String getLowerCase(java.lang.String str)
Returns the lower-case version of a string. This method also handles transitions from a lower-case letter to an upper-case letter (inside the string) by appending a '_'. This will maintain the word stem separation, also in the lower-case string. Any characters outside the [A-Za-z0-9_] range will be removed from the string.

Parameters:
str - the string to transform
Returns:
the all lower-case version of the string

getMixedCase

public java.lang.String getMixedCase(java.lang.String str,
                                     boolean initialUpper)
Returns the mixed-case version of a string. This method also handles '_' characters by adding a transition from a lower-case letter to an upper-case letter (in the result string). This will maintain the word stem separation, in mixed-case. Any characters outside the [A-Za-z0-9] range will be removed from the string.

Parameters:
str - the string to transform
initialUpper - the first character upper-case flag
Returns:
the mixed-case version of the string

addStringEscapes

public java.lang.String addStringEscapes(java.lang.String str,
                                         char escape)
Adds escapes in front of all " characters in a string. Any occurence of the escape character itself will also be escaped.

Parameters:
str - the string to convert
escape - the escape character to use
Returns:
the converted string

lineBreak

public java.util.ArrayList lineBreak(java.lang.String str,
                                     int margin)
Returns a list with all the lines in a string. The string will be line breaked either upon newline characters or reaching the specified margin. Note that this method will NOT remove any characters, which means that the lines will probably end with a whitespace character (newline or space).

Parameters:
str - the string to line break
margin - the maximum line length
Returns:
the list of lines