예제 #1
0
  public void format(FmtExpr fmt, IndentedWriter writer) {
    boolean explicitDirection = false;
    boolean needParens = false;

    if (direction != Query.ORDER_DEFAULT) {
      // Need parens if the expression isn't going to add them anyway.
      if (expression.isVariable() || expression instanceof E_Function)
        // Bracketless by expression formatting
        needParens = true;
    }

    if (direction == Query.ORDER_ASCENDING) writer.print("ASC");

    if (direction == Query.ORDER_DESCENDING) writer.print("DESC");

    if (needParens) writer.print("(");

    fmt.format(expression);

    if (needParens) writer.print(")");
  }