Methods Summary |
---|
private void | beginNewClause()
if (!afterBeginBeforeEnd) {
if (afterOn) {
indent--;
afterOn=false;
}
indent--;
newline();
}
out();
beginLine = false;
afterBeginBeforeEnd = true;
|
private void | closeParen()
parensSinceSelect--;
if (parensSinceSelect<0) {
indent--;
parensSinceSelect = ( (Integer) parenCounts.removeLast() ).intValue();
afterByOrSetOrFromOrSelect = ( (Boolean) afterByOrFromOrSelects.removeLast() ).booleanValue();
}
if ( inFunction>0 ) {
inFunction--;
out();
}
else {
if (!afterByOrSetOrFromOrSelect) {
indent--;
newline();
}
out();
}
beginLine = false;
|
private void | commaAfterByOrFromOrSelect()
out();
newline();
|
private void | commaAfterOn()
out();
indent--;
newline();
afterOn = false;
afterByOrSetOrFromOrSelect = true;
|
private void | endNewClause()
if (!afterBeginBeforeEnd) {
indent--;
if (afterOn) {
indent--;
afterOn=false;
}
newline();
}
out();
if ( !"union".equals(lcToken) ) indent++;
newline();
afterBeginBeforeEnd = false;
afterByOrSetOrFromOrSelect = "by".equals(lcToken)
|| "set".equals(lcToken)
|| "from".equals(lcToken);
|
public java.lang.String | format()
result.append(initial);
while ( tokens.hasMoreTokens() ) {
token = tokens.nextToken();
lcToken = token.toLowerCase();
if ( "'".equals(token) ) {
String t;
do {
t = tokens.nextToken();
token += t;
}
while ( !"'".equals(t) && tokens.hasMoreTokens() ); // cannot handle single quotes
}
else if ( "\"".equals(token) ) {
String t;
do {
t = tokens.nextToken();
token += t;
}
while ( !"\"".equals(t) );
}
if ( afterByOrSetOrFromOrSelect && ",".equals(token) ) {
commaAfterByOrFromOrSelect();
}
else if ( afterOn && ",".equals(token) ) {
commaAfterOn();
}
else if ( "(".equals(token) ) {
openParen();
}
else if ( ")".equals(token) ) {
closeParen();
}
else if ( BEGIN_CLAUSES.contains(lcToken) ) {
beginNewClause();
}
else if ( END_CLAUSES.contains(lcToken) ) {
endNewClause();
}
else if ( "select".equals(lcToken) ) {
select();
}
else if ( DML.contains(lcToken) ) {
updateOrInsertOrDelete();
}
else if ( "values".equals(lcToken) ) {
values();
}
else if ( "on".equals(lcToken) ) {
on();
}
else if ( afterBetween && lcToken.equals("and") ) {
misc();
afterBetween = false;
}
else if ( LOGICAL.contains(lcToken) ) {
logical();
}
else if ( isWhitespace(token) ) {
white();
}
else {
misc();
}
if ( !isWhitespace( token ) ) lastToken = lcToken;
}
return result.toString();
|
private static boolean | isFunctionName(java.lang.String tok)
final char begin = tok.charAt(0);
final boolean isIdentifier = Character.isJavaIdentifierStart( begin ) || '""==begin;
return isIdentifier &&
!LOGICAL.contains(tok) &&
!END_CLAUSES.contains(tok) &&
!QUANTIFIERS.contains(tok) &&
!DML.contains(tok) &&
!MISC.contains(tok);
|
private static boolean | isWhitespace(java.lang.String token)
return StringHelper.WHITESPACE.indexOf(token)>=0;
|
private void | logical()
if ( "end".equals(lcToken) ) indent--;
newline();
out();
beginLine = false;
|
public static void | main(java.lang.String[] args)
if ( args.length>0 ) System.out.println(
new Formatter( StringHelper.join(" ", args) ).format()
);
|
private void | misc()
out();
if ( "between".equals(lcToken) ) {
afterBetween = true;
}
if (afterInsert) {
newline();
afterInsert = false;
}
else {
beginLine = false;
if ( "case".equals(lcToken) ) {
indent++;
}
}
|
private void | newline()
result.append("\n");
for ( int i=0; i<indent; i++ ) {
result.append(indentString);
}
beginLine = true;
|
private void | on()
indent++;
afterOn = true;
newline();
out();
beginLine = false;
|
private void | openParen()
if ( isFunctionName( lastToken ) || inFunction>0 ) {
inFunction++;
}
beginLine = false;
if ( inFunction>0 ) {
out();
}
else {
out();
if (!afterByOrSetOrFromOrSelect) {
indent++;
newline();
beginLine = true;
}
}
parensSinceSelect++;
|
private void | out()
result.append(token);
|
private void | select()
out();
indent++;
newline();
parenCounts.addLast( new Integer(parensSinceSelect) );
afterByOrFromOrSelects.addLast( new Boolean(afterByOrSetOrFromOrSelect) );
parensSinceSelect = 0;
afterByOrSetOrFromOrSelect = true;
|
public org.hibernate.pretty.Formatter | setIndentString(java.lang.String indent)
this.indentString = indent;
return this;
|
public org.hibernate.pretty.Formatter | setInitialString(java.lang.String initial)
this.initial = initial;
return this;
|
private void | updateOrInsertOrDelete()
out();
indent++;
beginLine = false;
if ( "update".equals(lcToken) ) newline();
if ( "insert".equals(lcToken) ) afterInsert = true;
|
private void | values()
indent--;
newline();
out();
indent++;
newline();
afterValues = true;
|
private void | white()
if ( !beginLine ) {
result.append(" ");
}
|