improved sql format output

This commit is contained in:
shaojin.wensj
2015-07-11 14:27:29 +08:00
parent 60b7139911
commit b36374f7bf
26 changed files with 612 additions and 35 deletions
@@ -66,7 +66,7 @@ public class ParameterizedOutputVisitorUtils {
stmt.accept(visitor);
}
if (visitor.getReplaceCount() == 0 && !parser.getLexer().isHasComment()) {
if (visitor.getReplaceCount() == 0 && !parser.getLexer().hasComment()) {
return sql;
}
@@ -350,6 +350,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
visitBinaryLeft(item, x.getOperator());
if (relational) {
if (isPrettyFormat() && item.hasAfterComment()) {
print(' ');
printComment(item.getAfterCommentsDirect(), "\n");
}
println();
} else {
print(" ");
@@ -684,6 +688,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
}
public boolean visit(SQLSelectQueryBlock x) {
if (isPrettyFormat() && x.hasBeforeComment()) {
printComment(x.getBeforeCommentsDirect(), "\n");
}
print("SELECT ");
if (SQLSetQuantifier.ALL == x.getDistionOption()) {
@@ -763,11 +771,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
public boolean visit(SQLExprTableSource x) {
x.getExpr().accept(this);
if (x.getAlias() != null) {
print(' ');
print(x.getAlias());
}
if (isPrettyFormat() && x.hasAfterComment()) {
print(' ');
printComment(x.getAfterCommentsDirect(), "\n");
}
return false;
}
@@ -2182,4 +2195,16 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
}
return false;
}
protected void printComment(List<String> comments, String seperator) {
if (comments != null) {
for (int i = 0; i < comments.size(); ++i) {
if (i != 0) {
print(seperator);
}
String comment = comments.get(i);
print(comment);
}
}
}
}