Skip to content

Commit 159c28e

Browse files
fix: don't insert space after certain punctuation
Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
1 parent c9d1eae commit 159c28e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/java/net/sf/jsqlparser/parser/ASTNodeAccessImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
package net.sf.jsqlparser.parser;
1111

12+
import java.util.Set;
13+
import java.util.TreeSet;
14+
1215
public class ASTNodeAccessImpl implements ASTNodeAccess {
1316

1417
private transient SimpleNode node;
@@ -24,11 +27,20 @@ public void setASTNode(SimpleNode node) {
2427
}
2528

2629
public StringBuilder appendTo(StringBuilder builder) {
30+
// don't add spaces around the following punctuation
31+
final Set<String> punctuation = new TreeSet<>(Set.of(".", "[", "]"));
32+
2733
SimpleNode simpleNode = getASTNode();
2834
Token token = simpleNode.jjtGetFirstToken();
2935
Token lastToken = simpleNode.jjtGetLastToken();
36+
Token prevToken = null;
3037
while (token.next != null && token.absoluteEnd <= lastToken.absoluteEnd) {
31-
builder.append(" ").append(token.image);
38+
if (!punctuation.contains(token.image)
39+
&& (prevToken == null || !punctuation.contains(prevToken.image))) {
40+
builder.append(" ");
41+
}
42+
builder.append(token.image);
43+
prevToken = token;
3244
token = token.next;
3345
}
3446
return builder;

0 commit comments

Comments
 (0)