svn commit: r981610 - /ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r981610 - /ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj

doogie-3
Author: doogie
Date: Mon Aug  2 17:41:23 2010
New Revision: 981610

URL: http://svn.apache.org/viewvc?rev=981610&view=rev
Log:
FORMAT: Re-indent; couldn't find a standard for indentation, so this is an
attempt to have some sort of common pattern for doing so.

Modified:
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj

Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj?rev=981610&r1=981609&r2=981610&view=diff
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj (original)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj Mon Aug  2 17:41:23 2010
@@ -17,11 +17,11 @@
  * under the License.
  */
 options {
-  JAVA_UNICODE_ESCAPE = false;
-  ERROR_REPORTING = true;
-  STATIC = false;
+    JAVA_UNICODE_ESCAPE = false;
+    ERROR_REPORTING = true;
+    STATIC = false;
 //  MULTI = true;
-  JDK_VERSION = "1.5";
+    JDK_VERSION = "1.5";
 //  VISITOR = true;
 //  BUILD_NODE_FILES = true;
 //  NODE_FACTORY = false;
@@ -31,10 +31,10 @@ options {
 //  DEBUG_PARSER = true;
 //  DEBUG_LOOKAHEAD = true;
 //  DEBUG_TOKEN_MANAGER = true;
-  LOOKAHEAD = 1;
+    LOOKAHEAD = 1;
 //  CHOICE_AMBIGUITY_CHECK = 3;
 //  OTHER_AMBIGUITY_CHECK = 3;
-  IGNORE_CASE = true;
+    IGNORE_CASE = true;
 }
 PARSER_BEGIN(Parser)
 
@@ -85,66 +85,66 @@ TOKEN_MGR_DECLS: {
 }
 
 TOKEN: {
-    <OPEN_PAREN: "(">
-|    <CLOSE_PAREN: ")">
-|    <AND: "AND">
-|    <OR: "OR">
-|    <PERIOD: ".">
-|    <JOIN: "JOIN">
-|    <LEFT: "LEFT">
-|    <AS: "AS">
-|    <COUNT: "COUNT">
-|    <DISTINCT: "DISTINCT">
-|    <WHERE: "WHERE">
-|    <HAVING: "HAVING">
-|    <GROUP: "GROUP">
-|    <ORDER: "ORDER">
-//|    <UNION: "UNION">
-|    <BY: "BY">
-|    <ON: "ON">
-|    <USING: "USING">
-|    <LIMIT: "LIMIT">
-|    <OFFSET: "OFFSET">
-|    <SELECT: "SELECT">
-|    <DELETE: "DELETE">
-|    <UPDATE: "UPDATE">
-|    <INSERT: "INSERT">
-|    <RELATION: "RELATION">
-|    <EXCLUDE: "EXCLUDE">
-|    <UPPER: "UPPER">
-|    <LOWER: "LOWER">
-|    <TYPE: "TYPE">
-|    <TITLE: "TITLE">
-|    <SET: "SET">
-|    <FROM: "FROM">
-|    <SEMI: ";">
-|    <STAR: "*">
-|    <COMMA: ",">
-|    <PLUS: "+">
-|    <MINUS: "-">
-|    <DESC: "DESC">
-|    <ASC: "ASC">
-|    <EQUALS: "=">
-|    <BETWEEN: "BETWEEN">
-|    <INTO: "INTO">
-|    <VALUES: "VALUES">
-|    <CREATE: "CREATE">
-|    <VIEW: "VIEW">
-|    <IS: "IS">
-|    <NOT: "NOT">
-|    <NULL: "NULL">
-|    <START_DQUOTE: "\""> { pushState(IN_DQUOTE); }
-|    <START_SQUOTE: "'"> { pushState(IN_SQUOTE); }
-|    <INTEGER:
-    "0" (
-        "x" (["0"-"9","a"-"b"])+
-        | (["0"-"7"])+
-    )
-    | ["1"-"9"] (["0"-"9"])*
+      <OPEN_PAREN: "(">
+    | <CLOSE_PAREN: ")">
+    | <AND: "AND">
+    | <OR: "OR">
+    | <PERIOD: ".">
+    | <JOIN: "JOIN">
+    | <LEFT: "LEFT">
+    | <AS: "AS">
+    | <COUNT: "COUNT">
+    | <DISTINCT: "DISTINCT">
+    | <WHERE: "WHERE">
+    | <HAVING: "HAVING">
+    | <GROUP: "GROUP">
+    | <ORDER: "ORDER">
+//  | <UNION: "UNION">
+    | <BY: "BY">
+    | <ON: "ON">
+    | <USING: "USING">
+    | <LIMIT: "LIMIT">
+    | <OFFSET: "OFFSET">
+    | <SELECT: "SELECT">
+    | <DELETE: "DELETE">
+    | <UPDATE: "UPDATE">
+    | <INSERT: "INSERT">
+    | <RELATION: "RELATION">
+    | <EXCLUDE: "EXCLUDE">
+    | <UPPER: "UPPER">
+    | <LOWER: "LOWER">
+    | <TYPE: "TYPE">
+    | <TITLE: "TITLE">
+    | <SET: "SET">
+    | <FROM: "FROM">
+    | <SEMI: ";">
+    | <STAR: "*">
+    | <COMMA: ",">
+    | <PLUS: "+">
+    | <MINUS: "-">
+    | <DESC: "DESC">
+    | <ASC: "ASC">
+    | <EQUALS: "=">
+    | <BETWEEN: "BETWEEN">
+    | <INTO: "INTO">
+    | <VALUES: "VALUES">
+    | <CREATE: "CREATE">
+    | <VIEW: "VIEW">
+    | <IS: "IS">
+    | <NOT: "NOT">
+    | <NULL: "NULL">
+    | <START_DQUOTE: "\""> { pushState(IN_DQUOTE); }
+    | <START_SQUOTE: "'"> { pushState(IN_SQUOTE); }
+    | <INTEGER:
+        "0" (
+            "x" (["0"-"9","a"-"b"])+
+            | (["0"-"7"])+
+        )
+        | ["1"-"9"] (["0"-"9"])*
     >
-|    <NAME:    ["a"-"z"] (["a"-"z","0"-"9","_","-"])*>
-|    <PARAMETER: "?" (["a"-"z"])+>
-//|    <WORD: (~["'", "\"", "/", " ", "\f", "\n", "\r", "\t", "*"])+>
+    | <NAME: ["a"-"z"] (["a"-"z","0"-"9","_","-"])*>
+    | <PARAMETER: "?" (["a"-"z"])+>
+//  | <WORD: (~["'", "\"", "/", " ", "\f", "\n", "\r", "\t", "*"])+>
 }
 
 <DEFAULT>
@@ -159,8 +159,8 @@ MORE: {
 
 <IN_COMMENT>
 MORE: {
-    <(~[])>
-|    <COMMENT_END: "*/"> { popState(); }
+      <(~[])>
+    | <COMMENT_END: "*/"> { popState(); }
 }
 
 <IN_DQUOTE,IN_SQUOTE>
@@ -175,8 +175,8 @@ TOKEN: {
 
 <IN_SQUOTE>
 TOKEN: {
-    <ESCAPE_SQUOTE: "''">
-|    <END_SQUOTE: "'"> { popState(); }
+      <ESCAPE_SQUOTE: "''">
+    | <END_SQUOTE: "'"> { popState(); }
 }
 
 <DEFAULT,IN_DQUOTE,IN_SQUOTE>
@@ -186,97 +186,82 @@ TOKEN: {
 
 // -------------------
 
-public List<SQLStatement<?>> SQLFile():
-{
+public List<SQLStatement<?>> SQLFile(): {
     List<SQLStatement<?>> list = FastList.newInstance();
     SQLStatement<?> statement;
-}
-{
-    ( statement=Statement() ( <SEMI> )? { list.add(statement); } )*
+} {
+    (
+        statement=Statement() ( <SEMI> )?
+        { list.add(statement); }
+    )*
     <EOF>
     { return list; }
 }
 
-public SQLStatement StandaloneStatement():
-{
+public SQLStatement StandaloneStatement(): {
     SQLStatement statement;
-}
-{
-    statement=Statement() ( <SEMI> )? <EOF> { return statement; }
+} {
+    statement=Statement() ( <SEMI> )? <EOF>
+    { return statement; }
 }
 
-public SQLView ViewStatement():
-{
+public SQLView ViewStatement(): {
     SQLView sqlView;
-}
-{
-    sqlView=View() ( <SEMI> )? <EOF> { return sqlView; }
+} {
+    sqlView=View() ( <SEMI> )? <EOF>
+    { return sqlView; }
 }
 
-public SQLSelect SelectStatement():
-{
+public SQLSelect SelectStatement(): {
     SQLSelect sqlSelect;
-}
-{
+} {
     sqlSelect=Select() ( <SEMI> )? <EOF> { return sqlSelect; }
 }
 
-public SQLDelete DeleteStatement():
-{
+public SQLDelete DeleteStatement(): {
     SQLDelete sqlDelete;
-}
-{
+} {
     sqlDelete=Delete() ( <SEMI> )? <EOF> { return sqlDelete; }
 }
 
-public SQLUpdate UpdateStatement():
-{
+public SQLUpdate UpdateStatement(): {
     SQLUpdate sqlUpdate;
-}
-{
+} {
     sqlUpdate=Update() ( <SEMI> )? <EOF> { return sqlUpdate; }
 }
 
-public SQLInsert InsertStatement():
-{
+public SQLInsert InsertStatement(): {
     SQLInsert sqlInsert;
-}
-{
+} {
     sqlInsert=Insert() ( <SEMI> )? <EOF> { return sqlInsert; }
 }
 
-public Condition Condition():
-{ Condition c; }
-{
+public Condition Condition(): {
+    Condition c;
+} {
     c=ConditionExpression() <EOF> { return c; }
 }
 
-private SQLStatement Statement():
-{
+private SQLStatement Statement(): {
     SQLStatement statement;
-}
-{
+} {
     (
-        statement=Select() { return statement; }
-    |    statement=Delete() { return statement; }
-    |    statement=Update() { return statement; }
-    |    statement=Insert() { return statement; }
-    |    statement=View() { return statement; }
+          statement=Select() { return statement; }
+        | statement=Delete() { return statement; }
+        | statement=Update() { return statement; }
+        | statement=Insert() { return statement; }
+        | statement=View() { return statement; }
     )
 }
 
-private SQLView View():
-{
+private SQLView View(): {
     String name;
     SQLSelect sqlSelect;
-}
-{
-    <CREATE> <VIEW> name=NamePart() <AS> sqlSelect=Select()
-    { return new SQLView(name, sqlSelect); }
+} {
+    <CREATE> <VIEW> name=NamePart() <AS> sqlSelect=Select() { return new SQLView(name, sqlSelect); }
 }
 
-private SQLSelect Select():
-{
+private SQLSelect Select(): {
     Integer i;
     boolean isDistinct = false;
     List<OrderByItem> orderBy = null;
@@ -288,8 +273,7 @@ private SQLSelect Select():
     Map<String, Relation> relations = FastMap.newInstance();
     Condition whereCondition = null, havingCondition = null;
     int offset = -1, limit = -1;
-}
-{
+} {
     <SELECT> (<DISTINCT> { isDistinct = true; })? (
         FieldDef(fieldDefs, fieldAlls, fieldAllAliases)
         ( <COMMA> FieldDef(fieldDefs, fieldAlls, fieldAllAliases) )*
@@ -305,12 +289,10 @@ private SQLSelect Select():
     { return new SQLSelect(isDistinct, fieldAlls, fieldDefs, table, relations, whereCondition, havingCondition, groupBy, orderBy, offset, limit); }
 }
 
-private void Relation(Map<String, Relation> relations):
-{
+private void Relation(Map<String, Relation> relations): {
     String type = null, title = null, entityName;
     List<KeyMap> keyMaps;
-}
-{
+} {
     ( <TYPE> type=NamePart() )?
     ( <TITLE> title=NamePart() )?
     <NAME> { entityName = getToken(0).image; }
@@ -322,17 +304,14 @@ private void Relation(Map<String, Relati
     }
 }
 
-
-private SQLUpdate Update():
-{
+private SQLUpdate Update(): {
     TableName tableName;
     List<Table> tableList = null;
     Condition whereCondition = null;
     List<SetField> allSetFields = FastList.newInstance();
     List<SetField> setFields;
     Joined joined = null;
-}
-{
+} {
     <UPDATE> tableName=TableName()
     <SET>
     setFields=SetField() { allSetFields.addAll(setFields); }
@@ -342,28 +321,24 @@ private SQLUpdate Update():
     { return new SQLUpdate(new Table(tableName, joined), allSetFields, whereCondition); }
 }
 
-private SQLDelete Delete():
-{
+private SQLDelete Delete(): {
     TableName tableName;
     List<Table> tableList = null;
     Condition whereCondition = null;
     Joined joined = null;
-}
-{
+} {
     <DELETE> <FROM> tableName=TableName()
     ( LOOKAHEAD(<USING>, {deleteSupportsUsing}) <USING> joined=JoinedRest(false, tableName) )?
     ( <WHERE> whereCondition=ConditionExpression() )?
     { return new SQLDelete(new Table(tableName, joined), whereCondition); }
 }
 
-private SQLInsert Insert():
-{
+private SQLInsert Insert(): {
     TableName tableName;
     List<String> columns = FastList.newInstance();
     String n;
     InsertSource source;
-}
-{
+} {
     <INSERT> <INTO> tableName=TableName() (
         <OPEN_PAREN>
         n=NamePart() { columns.add(n); }
@@ -374,24 +349,20 @@ private SQLInsert Insert():
     { return new SQLInsert(tableName, source, columns); }
 }
 
-private InsertValues InsertValues():
-{
+private InsertValues InsertValues(): {
     List<InsertRow> list = FastList.newInstance();
     InsertRow row;
-}
-{
+} {
     <VALUES>
     row=InsertRow() { list.add(row); }
     ( <COMMA> row=InsertRow() { list.add(row); } )*
     { return new InsertValues(list); }
 }
 
-private InsertRow InsertRow():
-{
+private InsertRow InsertRow(): {
     List<Value> list = FastList.newInstance();
     Value v;
-}
-{
+} {
     <OPEN_PAREN>
     v=InsertValue() { list.add(v); }
     ( <COMMA> v=InsertValue() { list.add(v); } )*
@@ -399,112 +370,96 @@ private InsertRow InsertRow():
     { return new InsertRow(list); }
 }
 
-private Value InsertValue():
-{
+private Value InsertValue(): {
     Value v;
     Integer i;
     String s;
-}
-{
-    v=ParameterValue() { return v; }
-|    i=Integer() { return new NumberValue<Integer>(i); }
-|    s=SQuoted() { return new StringValue(s); }
+} {
+      v=ParameterValue() { return v; }
+    | i=Integer() { return new NumberValue<Integer>(i); }
+    | s=SQuoted() { return new StringValue(s); }
 }
 
-private List<SetField> SetField():
-{
+private List<SetField> SetField(): {
     List<SetField> setFields = FastList.newInstance();
     String n;
     Value v;
     List<String> columnList = FastList.newInstance();
     List<Value> valueList = FastList.newInstance();
-}
-{
+} {
     (
-        n=NamePart() <EQUALS> (
-            v=Value() { setFields.add(new SetField(n, v)); }
-        |    v=MathValue() { setFields.add(new SetField(n, v)); }
-        )
-    |    <OPEN_PAREN>
-        n=NamePart() { columnList.add(n); }
-        ( <COMMA> n=NamePart() { columnList.add(n); } )*
-        <CLOSE_PAREN>
-        <EQUALS>
-        <OPEN_PAREN>
-        (v=Value()|v=MathValue()) { valueList.add(v); }
-        ( <COMMA> (v=Value()|v=MathValue()) { valueList.add(v); } )*
-        <CLOSE_PAREN> {
+          n=NamePart() <EQUALS> (
+              v=Value() { setFields.add(new SetField(n, v)); }
+            | v=MathValue() { setFields.add(new SetField(n, v)); }
+          )
+        | <OPEN_PAREN>
+          n=NamePart() { columnList.add(n); }
+          ( <COMMA> n=NamePart() { columnList.add(n); } )*
+          <CLOSE_PAREN>
+          <EQUALS>
+          <OPEN_PAREN>
+          ( v=Value() | v=MathValue() ) { valueList.add(v); }
+          ( <COMMA> (v=Value()|v=MathValue()) { valueList.add(v); } )*
+          <CLOSE_PAREN> {
             if (columnList.size() != valueList.size()) throw new ParseException();
             for (int i = 0; i < columnList.size(); i++) {
                 setFields.add(new SetField(columnList.get(i), valueList.get(i)));
             }
-        }
+          }
     )
     { return setFields; }
 }
 
-private Table Table():
-{
+private Table Table(): {
     TableName tableName;
     Joined joined = null;
-}
-{
+} {
     tableName=TableName()
     ( joined=Joined(tableName) )?
     { return new Table(tableName, joined); }
 }
 
-private Joined Joined(TableName leftTableName):
-{
+private Joined Joined(TableName leftTableName): {
     Boolean isOptional;
     Joined joined = null;
-}
-{
+} {
     isOptional=Joiner() joined=JoinedRest(isOptional, leftTableName)
     { return joined; }
 }
 
-private Joined JoinedRest(boolean isOptional, TableName leftTableName):
-{
+private Joined JoinedRest(boolean isOptional, TableName leftTableName): {
     TableName rightTableName;
     List<KeyMap> keyMaps;
     Joined joined = null;
-}
-{
+} {
     rightTableName=TableName()
     keyMaps=KeyMaps(leftTableName.getAlias(), rightTableName.getAlias())
     ( joined=Joined(rightTableName) )?
     { return new Joined(isOptional, rightTableName, keyMaps, joined); }
 }
 
-private List<KeyMap> KeyMaps(String leftAlias, String rightAlias):
-{
+private List<KeyMap> KeyMaps(String leftAlias, String rightAlias): {
     List<KeyMap> keyMaps = FastList.newInstance();
     String n;
-}
-{
+} {
     (
-        <ON>
-        KeyMap(keyMaps, leftAlias, rightAlias)
-        ( <AND> KeyMap(keyMaps, leftAlias, rightAlias) )*
-    |
-        <USING>
-        n=NamePart() { keyMaps.add(new KeyMap(n, n)); }
-        ( <COMMA> n=NamePart() { keyMaps.add(new KeyMap(n, n)); } )*
+          <ON>
+          KeyMap(keyMaps, leftAlias, rightAlias)
+          ( <AND> KeyMap(keyMaps, leftAlias, rightAlias) )*
+        | <USING>
+          n=NamePart() { keyMaps.add(new KeyMap(n, n)); }
+          ( <COMMA> n=NamePart() { keyMaps.add(new KeyMap(n, n)); } )*
     )
     { return keyMaps; }
 }
 
-private void KeyMap(List<KeyMap> keyMaps, String leftAlias, String rightAlias):
-{
+private void KeyMap(List<KeyMap> keyMaps, String leftAlias, String rightAlias): {
     String alias1, field1;
     String alias2, field2;
-}
-{
+} {
     alias1=NamePart() <PERIOD> field1=NamePart()
     <EQUALS>
-    alias2=NamePart() <PERIOD> field2=NamePart()
-    {
+    alias2=NamePart() <PERIOD> field2=NamePart() {
         if (alias1.equals(leftAlias)) {
             if (!alias2.equals(rightAlias)) throw new ParseException("invalid right alias(" + alias2 + "), expected(" + rightAlias + ")");
             keyMaps.add(new KeyMap(field1, field2));
@@ -517,36 +472,30 @@ private void KeyMap(List<KeyMap> keyMaps
     }
 }
 
-private TableName TableName():
-{
+private TableName TableName(): {
     String tableName, alias = null;
-}
-{
+} {
     tableName=NamePart()
-    ( (<AS>)? alias=NamePart() )?
+    ( ( <AS> )? alias=NamePart() )?
     { return new TableName(tableName, alias); }
 }
 
-private Boolean Joiner():
-{}
-{
-    <LEFT> <JOIN> { return Boolean.TRUE; }
-|    <JOIN> { return Boolean.FALSE; }
+private Boolean Joiner(): {
+} {
+      <LEFT> <JOIN> { return Boolean.TRUE; }
+    | <JOIN> { return Boolean.FALSE; }
 }
 
-private void FieldDef(Map<String, FieldDef> fieldDefs, List<FieldAll> fieldAlls, Set<String> fieldAllAliases):
-{
+private void FieldDef(Map<String, FieldDef> fieldDefs, List<FieldAll> fieldAlls, Set<String> fieldAllAliases): {
     StaticValue v;
     String n, fieldAlias = null, fieldName, exc;
     FieldDef def;
     Set<String> excludeList = FastSet.newInstance();
-}
-{
+} {
     (
-        n=NamePart() (
-            <PERIOD> (
-                <STAR>
-                (
+          n=NamePart() (
+              <PERIOD> (
+                <STAR> (
                     { if (fieldAllAliases.contains(n)) throw new ParseException("Duplicate aliasAll(" + n + ")"); }
                     <EXCLUDE> <OPEN_PAREN>
                     exc=NamePart() { excludeList.add(exc); }
@@ -554,304 +503,264 @@ private void FieldDef(Map<String, FieldD
                     <CLOSE_PAREN>
                 )?
                 { fieldAlls.add(new FieldAll(n, excludeList)); return; }
-            | fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(n, fieldName), fieldAlias); }
-            )
-        |    v=FunctionCallRest(n) ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
-        |    ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(null, n), fieldAlias); }
-        )
-    |    v=MathValue() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
-    |   v=Count() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
+              | fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(n, fieldName), fieldAlias); }
+              )
+            | v=FunctionCallRest(n) ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
+            | ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(null, n), fieldAlias); }
+          )
+        | v=MathValue() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
+        | v=Count() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
     ) {
         if (fieldDefs.containsKey(def.getAlias())) throw new ParseException("duplicate alias(" + def.getAlias() + ")");
         fieldDefs.put(def.getAlias(), def);
     }
 }
 
-private StaticValue Count():
-{
+private StaticValue Count(): {
     String n, fieldName;
-}
-{
-    <COUNT> <OPEN_PAREN>
-    (
-        n=NamePart() (
-            <PERIOD> (
-                <STAR> <CLOSE_PAREN> { return new CountAllFunction(); }
-            | fieldName=NamePart() <CLOSE_PAREN> { return new CountFunction(false, new FieldValue(n, fieldName)); }
-            )
-        | <CLOSE_PAREN> { return new CountFunction(false, new FieldValue(null, n)); }
-        )
-    |   <DISTINCT> n=NamePart() (
-        <PERIOD> fieldName=NamePart() <CLOSE_PAREN> { return new CountFunction(true, new FieldValue(n, fieldName)); }
-        | <CLOSE_PAREN> { return new CountFunction(true, new FieldValue(null, n)); }
+} {
+    <COUNT> <OPEN_PAREN> (
+          n=NamePart() (
+              <PERIOD> (
+                  <STAR> <CLOSE_PAREN> { return new CountAllFunction(); }
+                | fieldName=NamePart() <CLOSE_PAREN> { return new CountFunction(false, new FieldValue(n, fieldName)); }
+              )
+            | <CLOSE_PAREN> { return new CountFunction(false, new FieldValue(null, n)); }
+          )
+        | <DISTINCT> n=NamePart() (
+              <PERIOD> fieldName=NamePart() <CLOSE_PAREN> { return new CountFunction(true, new FieldValue(n, fieldName)); }
+            | <CLOSE_PAREN> { return new CountFunction(true, new FieldValue(null, n)); }
         )
     )
 }
 
-private StaticValue MathValue():
-{
+private StaticValue MathValue(): {
     ConstantValue v;
     List<ConstantValue> values = FastList.newInstance();
     String operator = null, newOperator;
-}
-{
-    <OPEN_PAREN>
-        v=ConstantValue() { values.add(v); }
-        (
-            newOperator=MathOperator()
-            v=ConstantValue() {
-                if (operator == null) {
-                    operator = newOperator;
-                } else if (!newOperator.equals(operator)) {
-                    throw new ParseException("Different operators in complex alias(" + operator + ":" + newOperator + ")");
-                }
-                values.add(v);
+} {
+    <OPEN_PAREN> v=ConstantValue() { values.add(v); } (
+        newOperator=MathOperator() v=ConstantValue() {
+            if (operator == null) {
+                operator = newOperator;
+            } else if (!newOperator.equals(operator)) {
+                throw new ParseException("Different operators in complex alias(" + operator + ":" + newOperator + ")");
             }
-        )*
-    <CLOSE_PAREN>
-    {
+            values.add(v);
+        }
+    )*
+    <CLOSE_PAREN> {
         if (values.size() == 1 && values.get(0) instanceof StaticValue) return (StaticValue) values.get(0);
         return new MathValue(operator, values);
     }
 }
 
-private FunctionCall FunctionCallRest(String name):
-{
+private FunctionCall FunctionCallRest(String name): {
     Value arg;
     List<Value> args = FastList.newInstance();
-}
-{
-    <OPEN_PAREN>
-    (
+} {
+    <OPEN_PAREN> (
         arg=Value() { args.add(arg); }
         ( <COMMA> arg=Value() { args.add(arg); } )*
-    ) ?
+    )?
     <CLOSE_PAREN>
     { return new FunctionCall(name, args); }
 }
 
-private ConstantValue ConstantValue():
-{
+private ConstantValue ConstantValue(): {
     String n;
     ConstantValue v;
     int i;
     String s;
+} {
+      n=NamePart() (
+          v=FunctionCallRest(n) { return v; }
+        | v=FieldValue(n) { return v; }
+      )
+    | i=Integer() { return new NumberValue<Integer>(i); }
+    | s=SQuoted() { return new StringValue(s); }
+    | v=MathValue() { return v; }
+}
+
+private String NamePart(): {
+} {
+      <NAME> { return getToken(0).image; }
+    | <TYPE> { return getToken(0).image; }
 }
-{
-    n=NamePart() (
-        v=FunctionCallRest(n) { return v; }
-    | v=FieldValue(n) { return v; }
-    )
-|    i=Integer() { return new NumberValue<Integer>(i); }
-|    s=SQuoted() { return new StringValue(s); }
-|    v=MathValue() { return v; }
-}
-
-private String NamePart():
-{}
-{
-    <NAME> { return getToken(0).image; }
-|    <TYPE> { return getToken(0).image; }
-}
-
-private String DQuoted():
-{ StringBuilder sb = new StringBuilder(); }
-{
-    <START_DQUOTE> (<TEXT> { sb.append(getToken(0).image); } | <ESCAPED> { sb.append(getToken(0).image); })* <END_DQUOTE>
+
+private String DQuoted(): {
+    StringBuilder sb = new StringBuilder();
+} {
+    <START_DQUOTE> (
+          <TEXT> { sb.append(getToken(0).image); }
+        | <ESCAPED> { sb.append(getToken(0).image); }
+    )* <END_DQUOTE>
     { return sb.toString(); }
 }
 
-private String SQuoted():
-{ StringBuilder sb = new StringBuilder(); }
-{
+private String SQuoted(): {
+    StringBuilder sb = new StringBuilder();
+} {
     <START_SQUOTE> (
-        <TEXT> { sb.append(getToken(0).image); }
-    |    <ESCAPED> { sb.append(getToken(0).image); }
-    |    <ESCAPE_SQUOTE> { sb.append("'"); }
+          <TEXT> { sb.append(getToken(0).image); }
+        | <ESCAPED> { sb.append(getToken(0).image); }
+        | <ESCAPE_SQUOTE> { sb.append("'"); }
     )* <END_SQUOTE>
     { return sb.toString(); }
 }
 
-private String Text():
-{
+private String Text(): {
     StringBuilder sb = new StringBuilder();
-}
-{
+} {
     ( <TEXT> { sb.append(getToken(0).image); } )+
     { return sb.toString(); }
 }
-private List<String> FieldList():
-{
+
+private List<String> FieldList(): {
     List<String> list = FastList.newInstance();
     String n;
-}
-{
+} {
     n=NamePart() { list.add(n); }
     ( <COMMA> n=NamePart() { list.add(n); } )*
     { return list; }
 }
 
-private FieldValue FieldValue(String fieldName):
-{
+private FieldValue FieldValue(String fieldName): {
     String s;
-}
-{
+} {
     ( <PERIOD> s=NamePart() { return new FieldValue(fieldName, s); } )?
-    {
-        return new FieldValue(fieldName);
-    }
+    { return new FieldValue(fieldName); }
 }
 
-private List<OrderByItem> OrderByList():
-{
+private List<OrderByItem> OrderByList(): {
     List<OrderByItem> orderBy = FastList.newInstance();
     OrderByItem obi;
-}
-{
+} {
     obi=OrderByItem() { orderBy.add(obi); }
     ( <COMMA> obi=OrderByItem() { orderBy.add(obi); } )*
     { return orderBy; }
 }
 
-private OrderByItem OrderByItem():
-{
+private OrderByItem OrderByItem(): {
     String functionName = null, fieldName = null;
     boolean descending = false, orderingSet = false;
     OrderByItem.Order ordering = OrderByItem.Order.DEFAULT;
-}
-{
+} {
     (
-        <PLUS> { ordering = OrderByItem.Order.ASCENDING; }
+          <PLUS> { ordering = OrderByItem.Order.ASCENDING; }
         | <MINUS> { ordering = OrderByItem.Order.DESCENDING; }
     )?
     (
-        ( <UPPER> | <LOWER> ) { functionName = getToken(0).image; }
-        <OPEN_PAREN> fieldName=NamePart() <CLOSE_PAREN>
+          ( <UPPER> | <LOWER> ) { functionName = getToken(0).image; } <OPEN_PAREN> fieldName=NamePart() <CLOSE_PAREN>
         | fieldName=NamePart()
     )
     LOOKAHEAD({!orderingSet}) (
-        <DESC> { ordering = OrderByItem.Order.DESCENDING; }
+          <DESC> { ordering = OrderByItem.Order.DESCENDING; }
         | <ASC> { ordering = OrderByItem.Order.ASCENDING; }
     )?
     { return new OrderByItem(ordering, functionName, fieldName); }
 }
 
-private Integer Integer():
-{}
-{
+private Integer Integer(): {
+} {
     <INTEGER> { return Integer.decode(getToken(0).image); }
 }
 
-private Value Value():
-{
+private Value Value(): {
     String n;
     Value v;
     int i;
     String s;
-}
-{
-    n=NamePart() (
-        v=FunctionCallRest(n) { return v; }
-    |    v=FieldValue(n) { return v; }
-    )
-|    i=Integer() { return new NumberValue<Integer>(i); }
-|    s=SQuoted() { return new StringValue(s); }
+} {
+      n=NamePart() (
+          v=FunctionCallRest(n) { return v; }
+        | v=FieldValue(n) { return v; }
+      )
+    | i=Integer() { return new NumberValue<Integer>(i); }
+    | s=SQuoted() { return new StringValue(s); }
 }
 
-private Condition ConditionExpression():
-{ Condition c; }
-{
+private Condition ConditionExpression(): {
+    Condition c;
+} {
     c=OrExpression() { return c; }
 }
 
-private Condition AndExpression():
-{
+private Condition AndExpression(): {
     List<Condition> list = FastList.newInstance();
     Condition c;
-}
-{
+} {
     c=BooleanExpression() { list.add(c); }
-        ( <AND> c=BooleanExpression() { list.add(c); } )*
+    ( <AND> c=BooleanExpression() { list.add(c); } )*
     { return reduce(list, Joiner.AND); }
 }
 
-private Condition OrExpression():
-{
+private Condition OrExpression(): {
     List<Condition> list = FastList.newInstance();
     Condition c;
-}
-{
+} {
     c=AndExpression() { list.add(c); }
-        ( <OR> c=AndExpression() { list.add(c); } )*
+    ( <OR> c=AndExpression() { list.add(c); } )*
     { return reduce(list, Joiner.OR); }
 }
 
-private Value RightValue():
-{
+private Value RightValue(): {
     Value v;
-}
-{
-    v=Value() { return v; }
-|    v=ParameterValue() { return v; }
+} {
+      v=Value() { return v; }
+    | v=ParameterValue() { return v; }
 }
 
-private ParameterValue ParameterValue():
-{}
-{
+private ParameterValue ParameterValue(): {
+} {
     <PARAMETER> { return new ParameterValue(getToken(0).image.substring(1)); }
 }
 
-private Condition BooleanExpression():
-{
+private Condition BooleanExpression(): {
     Value v1, v2, v, r1, r2;
     String op;
     Condition c;
     List<Value> list = FastList.newInstance();
-}
-{
+} {
     v1=Value() (
-        <BETWEEN>
-        r1=RightValue()
-        <AND>
-        r2=RightValue()
-        { return new BetweenCondition(v1, r1, r2); }
-    | <IS> (
-        <NULL> { op = "="; v2 = Value.NULL; }
-        | <NOT> <NULL> { op = "!="; v2 = Value.NULL; }
-    )
-    |    op=ComparisonOperator() (
-            v2=RightValue()
-        |    <OPEN_PAREN>
-            v=RightValue() { list.add(v); }
-            ( <COMMA> v=RightValue() { list.add(v); } )*
-            <CLOSE_PAREN>
-            { return new ListCondition(v1, op, list); }
+          <BETWEEN> r1=RightValue() <AND> r2=RightValue()
+          { return new BetweenCondition(v1, r1, r2); }
+        | <IS> (
+              <NULL> { op = "="; v2 = Value.NULL; }
+            | <NOT> <NULL> { op = "!="; v2 = Value.NULL; }
         )
-    )
-    { return new BooleanCondition(v1, op, v2); }
-|    <OPEN_PAREN> c=ConditionExpression() <CLOSE_PAREN> { return c; }
+    | op=ComparisonOperator() (
+          v2=RightValue()
+        | <OPEN_PAREN>
+          v=RightValue() { list.add(v); }
+          (
+            <COMMA> v=RightValue() { list.add(v); }
+          )*
+          <CLOSE_PAREN>
+          { return new ListCondition(v1, op, list); }
+        )
+      )
+      { return new BooleanCondition(v1, op, v2); }
+    | <OPEN_PAREN> c=ConditionExpression() <CLOSE_PAREN> { return c; }
 }
 
-private String ComparisonOperator():
-{
+private String ComparisonOperator(): {
     StringBuilder sb = new StringBuilder();
     String s;
-}
-{
-    s=Text() { sb.append(s); }
-    (
+} {
+      s=Text() { sb.append(s); }
+      (
         <EQUALS> { sb.append(getToken(0).image); }
-        (s=Text() { sb.append(s); })?
-    )* { return sb.toString(); }
-|    <NAME> { return getToken(0).image; }
-|    <EQUALS> { return getToken(0).image; }
+        ( s=Text() { sb.append(s); } )?
+      )*
+      { return sb.toString(); }
+    | <NAME> { return getToken(0).image; }
+    | <EQUALS> { return getToken(0).image; }
 }
 
-private String MathOperator():
-{
+private String MathOperator(): {
     String s;
-}
-{
-    s=Text() { return s; }
-|    <NAME> { return getToken(0).image; }
+} {
+      s=Text() { return s; }
+    | <NAME> { return getToken(0).image; }
 }