mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -253,7 +253,20 @@ public class SQLUtils {
|
||||
SQLStatement stmt = statementList.get(i);
|
||||
|
||||
if (i > 0) {
|
||||
visitor.println(";");
|
||||
visitor.print(";");
|
||||
|
||||
SQLStatement preStmt = statementList.get(i - 1);
|
||||
List<String> comments = preStmt.getAfterCommentsDirect();
|
||||
if (comments != null){
|
||||
for (int j = 0; j < comments.size(); ++j) {
|
||||
String comment = comments.get(j);
|
||||
if (j != 0) {
|
||||
visitor.println();
|
||||
}
|
||||
visitor.print(comment);
|
||||
}
|
||||
}
|
||||
visitor.println();
|
||||
}
|
||||
{
|
||||
List<String> comments = stmt.getBeforeCommentsDirect();
|
||||
@@ -268,9 +281,9 @@ public class SQLUtils {
|
||||
if (i == statementList.size() - 1) {
|
||||
Boolean semi = (Boolean) stmt.getAttribute("format.semi");
|
||||
if (semi != null && semi.booleanValue()) {
|
||||
if (stmt.hasAfterComment()) {
|
||||
visitor.println();
|
||||
}
|
||||
// if (stmt.hasAfterComment()) {
|
||||
// visitor.println();
|
||||
// }
|
||||
visitor.print(";");
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ public class OdpsLexer extends Lexer {
|
||||
for (;;) {
|
||||
if (ch == '\r') {
|
||||
if (charAt(pos + 1) == '\n') {
|
||||
line++;
|
||||
bufPos += 2;
|
||||
scanChar();
|
||||
break;
|
||||
@@ -150,6 +151,7 @@ public class OdpsLexer extends Lexer {
|
||||
}
|
||||
|
||||
if (ch == '\n') {
|
||||
line++;
|
||||
scanChar();
|
||||
bufPos++;
|
||||
break;
|
||||
|
||||
@@ -77,6 +77,8 @@ public class Lexer {
|
||||
protected boolean endOfComment = false;
|
||||
|
||||
protected boolean keepComments = false;
|
||||
|
||||
protected int line = 0;
|
||||
|
||||
public Lexer(String input){
|
||||
this(input, null);
|
||||
@@ -293,6 +295,10 @@ public class Lexer {
|
||||
|
||||
for (;;) {
|
||||
if (isWhitespace(ch)) {
|
||||
if (ch == '\n') {
|
||||
line++;
|
||||
}
|
||||
|
||||
scanChar();
|
||||
continue;
|
||||
}
|
||||
@@ -831,6 +837,7 @@ public class Lexer {
|
||||
for (;;) {
|
||||
if (ch == '\r') {
|
||||
if (charAt(pos + 1) == '\n') {
|
||||
line++;
|
||||
scanChar();
|
||||
break;
|
||||
}
|
||||
@@ -839,6 +846,7 @@ public class Lexer {
|
||||
}
|
||||
|
||||
if (ch == '\n') {
|
||||
line++;
|
||||
scanChar();
|
||||
break;
|
||||
}
|
||||
@@ -1185,4 +1193,8 @@ public class Lexer {
|
||||
}
|
||||
comments.add(stringVal);
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,9 +159,15 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.SEMI) {
|
||||
int line0 = lexer.getLine();
|
||||
lexer.nextToken();
|
||||
if (lexer.isKeepComments()) {
|
||||
int line1 = lexer.getLine();
|
||||
|
||||
if (lexer.isKeepComments() && statementList.size() > 0) {
|
||||
SQLStatement stmt = statementList.get(statementList.size() - 1);
|
||||
if (line1 - line0 <= 1) {
|
||||
stmt.addAfterComment(lexer.readAndResetComments());
|
||||
}
|
||||
stmt.getAttributes().put("format.semi", Boolean.TRUE);
|
||||
}
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user