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
@@ -15,6 +15,7 @@
*/
package com.alibaba.druid.sql.ast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -107,4 +108,70 @@ public abstract class SQLObjectImpl implements SQLObject {
public Map<String, Object> getAttributesDirect() {
return attributes;
}
@SuppressWarnings("unchecked")
public void addBeforeComment(String comment) {
if (attributes == null) {
attributes = new HashMap<String, Object>(1);
}
List<String> comments = (List<String>) attributes.get("format.before_comment");
if (comments == null) {
comments = new ArrayList<String>(2);
attributes.put("format.before_comment", comments);
}
comments.add(comment);
}
@SuppressWarnings("unchecked")
public List<String> getBeforeCommentsDirect() {
if (attributes == null) {
return null;
}
return (List<String>) attributes.get("format.before_comment");
}
@SuppressWarnings("unchecked")
public void addAfterComment(String comment) {
if (attributes == null) {
attributes = new HashMap<String, Object>(1);
}
List<String> comments = (List<String>) attributes.get("format.after_comment");
if (comments == null) {
comments = new ArrayList<String>(2);
attributes.put("format.after_comment", comments);
}
comments.add(comment);
}
@SuppressWarnings("unchecked")
public List<String> getAfterCommentsDirect() {
if (attributes == null) {
return null;
}
return (List<String>) attributes.get("format.after_comment");
}
public boolean hasBeforeComment() {
List<String> comments = getBeforeCommentsDirect();
if (comments == null) {
return false;
}
return !comments.isEmpty();
}
public boolean hasAfterComment() {
List<String> comments = getAfterCommentsDirect();
if (comments == null) {
return false;
}
return !comments.isEmpty();
}
}