net.percederberg.grammatica.code
Class CodeStyle

java.lang.Object
  |
  +--net.percederberg.grammatica.code.CodeStyle

public class CodeStyle
extends java.lang.Object

The abstract 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.


Field Summary
static CodeStyle CSHARP
          The default C# code style.
static CodeStyle JAVA
          The default Java 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)
          Adds '\' escapes in front of all '"' and '\' 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)
          Creates a string constant from the specified string.
 java.lang.String getUpperCase(java.lang.String str)
          Returns the upper-case version of a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA

public static final CodeStyle JAVA
The default Java code style.


CSHARP

public static final CodeStyle CSHARP
The default C# 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)
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, all \ characters will be escaped.

Parameters:
str - the string to convert
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)
Adds '\' escapes in front of all '"' and '\' characters in a string.

Parameters:
str - the string to convert
Returns:
the converted string