com.github.abrarsyed.jastyle
Class ASBeautifier

java.lang.Object
  extended by com.github.abrarsyed.jastyle.AbstractASBase
      extended by com.github.abrarsyed.jastyle.ASBeautifier
Direct Known Subclasses:
ASFormatter

public class ASBeautifier
extends AbstractASBase


Field Summary
protected  int inLineNumber
           
protected  boolean isNonInStatementArray
           
protected  boolean isSharpAccessor
           
protected  boolean lineCommentNoBeautify
           
 
Fields inherited from class com.github.abrarsyed.jastyle.AbstractASBase
fileType
 
Constructor Summary
ASBeautifier()
          ASBeautifier's constructor
Por default fileType = FileType.JAVA_TYPE
ASBeautifier(ASBeautifier other)
          ASBeautifier's copy constructor must explicitly call the base class copy constructor
 
Method Summary
protected  java.lang.StringBuilder beautify(java.lang.StringBuilder originalLine)
          beautify a line of source code.
protected  java.lang.String findHeader(java.lang.StringBuilder line, int i, java.util.List<java.lang.String> possibleHeaders)
           
protected  java.lang.String findOperator(java.lang.String line, int i, java.util.List<java.lang.String> possibleOperators)
           
 SourceMode getFileType()
          get the file type.
 int getIndentLength()
          get the number of spaces per indent
 java.lang.String getIndentString()
          get the char used for indentation, space or tab
 boolean hasMoreLines()
          check if there are any indented lines ready to be read by nextLine()
 void init(ASSourceIterator iter)
          initialize the ASBeautifier.
 boolean isBlockIndent()
          get the state of the block indentation option.
 boolean isBracketIndent()
          get the state of the bracket indentation option.
 boolean isCaseIndent()
          get the state of the case indentation option.
 boolean isEmptyLineFill()
          get the state of the empty line fill option.
 java.lang.StringBuilder nextLine()
          get the next indented line.
 char peekNextChar(java.lang.StringBuilder line, int i)
          peek at the next unread character.
 void setBlockIndent(boolean state)
          set the state of the block indentation option.
 void setBracketIndent(boolean state)
          set the state of the bracket indentation option.
 void setCaseIndent(boolean state)
          set the state of the case indentation option.
 void setClassIndent(boolean state)
          set the state of the class indentation option.
 void setEmptyLineFill(boolean state)
          set the state of the empty line fill option.
 void setLabelIndent(boolean state)
          set the state of the label indentation option.
 void setMaxInStatementIndentLength(int max)
          set the maximum indentation between two lines in a multi-line statement.
 void setMinConditionalIndentLength(int min)
          set the minimum indentation between two lines in a multi-line condition.
 void setNamespaceIndent(boolean state)
          set the state of the namespace indentation option.
 void setPreprocessorIndent(boolean state)
          set the state of the preprocessor indentation option.
 void setSourceStyle(SourceMode mode)
          set indentation style to C/C++.
 void setSpaceIndentation(int length)
          indent using a number of spaces per indentation.
 void setSwitchIndent(boolean state)
          set the state of the switch indentation option.
 void setTabIndentation(int length)
          indent using one tab per indentation
 void setTabIndentation(int length, boolean forceTabs)
          indent using one tab per indentation
 
Methods inherited from class com.github.abrarsyed.jastyle.AbstractASBase
findKeyword, getCurrentWord, init, isCharPotentialHeader, isCharPotentialOperator, isCStyle, isJavaStyle, isLegalNameChar, isSharpStyle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inLineNumber

protected int inLineNumber

lineCommentNoBeautify

protected boolean lineCommentNoBeautify

isNonInStatementArray

protected boolean isNonInStatementArray

isSharpAccessor

protected boolean isSharpAccessor
Constructor Detail

ASBeautifier

public ASBeautifier()
ASBeautifier's constructor
Por default fileType = FileType.JAVA_TYPE


ASBeautifier

public ASBeautifier(ASBeautifier other)
ASBeautifier's copy constructor must explicitly call the base class copy constructor

Parameters:
other -
Method Detail

init

public void init(ASSourceIterator iter)
initialize the ASBeautifier.

init() should be called every time a ABeautifier object is to start beautifying a NEW source file. init() recieves a pointer to a DYNAMICALLY CREATED ASSourceIterator object that will be used to iterate through the source code. This object will be deleted during the ASBeautifier's destruction, and thus should not be deleted elsewhere.

Parameters:
iter - a pointer to the DYNAMICALLY CREATED ASSourceIterator object.

setSourceStyle

public void setSourceStyle(SourceMode mode)
set indentation style to C/C++.


setTabIndentation

public void setTabIndentation(int length)
indent using one tab per indentation

Parameters:
length -
forceTabs -

setTabIndentation

public void setTabIndentation(int length,
                              boolean forceTabs)
indent using one tab per indentation

Parameters:
length -
forceTabs -

setSpaceIndentation

public void setSpaceIndentation(int length)
indent using a number of spaces per indentation.

Parameters:
length - number of spaces per indent.

setMaxInStatementIndentLength

public void setMaxInStatementIndentLength(int max)
set the maximum indentation between two lines in a multi-line statement.

Parameters:
max - maximum indentation length.

setMinConditionalIndentLength

public void setMinConditionalIndentLength(int min)
set the minimum indentation between two lines in a multi-line condition.

Parameters:
min - minimal indentation length.

setBracketIndent

public void setBracketIndent(boolean state)
set the state of the bracket indentation option. If true, brackets will be indented one additional indent.

Parameters:
state - state of option.

setBlockIndent

public void setBlockIndent(boolean state)
set the state of the block indentation option. If true, entire blocks will be indented one additional indent, similar to the GNU indent style.

Parameters:
state - state of option.

setClassIndent

public void setClassIndent(boolean state)
set the state of the class indentation option. If true, C++ class definitions will be indented one additional indent.

Parameters:
state - state of option.

setSwitchIndent

public void setSwitchIndent(boolean state)
set the state of the switch indentation option. If true, blocks of 'switch' statements will be indented one additional indent.

Parameters:
state - state of option.

setCaseIndent

public void setCaseIndent(boolean state)
set the state of the case indentation option. If true, lines of 'case' statements will be indented one additional indent.

Parameters:
state - state of option.

setNamespaceIndent

public void setNamespaceIndent(boolean state)
set the state of the namespace indentation option. If true, blocks of 'namespace' statements will be indented one additional indent. Otherwise, NO indentation will be added.

Parameters:
state - state of option.

setLabelIndent

public void setLabelIndent(boolean state)
set the state of the label indentation option. If true, labels will be indented one indent LESS than the current indentation level. If false, labels will be flushed to the left with NO indent at all.

Parameters:
state - state of option.

setPreprocessorIndent

public void setPreprocessorIndent(boolean state)
set the state of the preprocessor indentation option. If true, multiline #define statements will be indented.

Parameters:
state - state of option.

setEmptyLineFill

public void setEmptyLineFill(boolean state)
set the state of the empty line fill option. If true, empty lines will be filled with the whitespace. of their previous lines. If false, these lines will remain empty.

Parameters:
state - state of option.

getFileType

public SourceMode getFileType()
get the file type.

Returns:

getIndentLength

public int getIndentLength()
get the number of spaces per indent

Returns:
value of indentLength option.

getIndentString

public java.lang.String getIndentString()
get the char used for indentation, space or tab

Returns:
the char used for indentation.

isBlockIndent

public boolean isBlockIndent()
get the state of the block indentation option.

Returns:
state of blockIndent option.

isBracketIndent

public boolean isBracketIndent()
get the state of the bracket indentation option.

Returns:
state of bracketIndent option.

isCaseIndent

public boolean isCaseIndent()
get the state of the case indentation option. If true, lines of 'case' statements will be indented one additional indent.

Returns:
state of caseIndent option.

isEmptyLineFill

public boolean isEmptyLineFill()
get the state of the empty line fill option. If true, empty lines will be filled with the whitespace. of their previous lines. If false, these lines will remain empty.

Returns:
state of emptyLineFill option.

hasMoreLines

public boolean hasMoreLines()
check if there are any indented lines ready to be read by nextLine()

Returns:
are there any indented lines ready?

nextLine

public java.lang.StringBuilder nextLine()
get the next indented line.

Returns:
indented line.

beautify

protected java.lang.StringBuilder beautify(java.lang.StringBuilder originalLine)
beautify a line of source code. every line of source code in a source code file should be sent one after the other to the beautify method.

Parameters:
originalLine - the original unindented line.
Returns:
the indented line.

findHeader

protected java.lang.String findHeader(java.lang.StringBuilder line,
                                      int i,
                                      java.util.List<java.lang.String> possibleHeaders)

findOperator

protected java.lang.String findOperator(java.lang.String line,
                                        int i,
                                        java.util.List<java.lang.String> possibleOperators)

peekNextChar

public char peekNextChar(java.lang.StringBuilder line,
                         int i)
peek at the next unread character.

Overrides:
peekNextChar in class AbstractASBase
Parameters:
line - the line to check.
i - the current char position on the line.
Returns:
the next unread character.