mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql format output
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user