Skip to content

Commit

Permalink
style: fix Q/A exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
  • Loading branch information
manticore-projects committed Apr 8, 2024
1 parent b2ffd2b commit 2b57ca6
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/main/java/com/manticore/jsqlformatter/JSQLFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.joining;

/**
* A powerful Java SQL Formatter based on the JSQLParser.
*
Expand Down Expand Up @@ -1879,8 +1877,8 @@ private static void appendSelect(Select select, StringBuilder builder, int inden
builder.append(indentString);
}
builder.append("WINDOW ");
int k=0;
for (WindowDefinition w: plainSelect.getWindowDefinitions()) {
int k = 0;
for (WindowDefinition w : plainSelect.getWindowDefinitions()) {
appendNormalizedLineBreak(builder);
for (int j = 0; j < indent + 1; j++) {
builder.append(indentString);
Expand All @@ -1896,21 +1894,21 @@ private static void appendSelect(Select select, StringBuilder builder, int inden
}

appendNormalizedLineBreak(builder);
for (int j = 0; j < indent+2; j++) {
for (int j = 0; j < indent + 2; j++) {
builder.append(indentString);
}
w.getPartitionBy().toStringPartitionBy(builder);

appendNormalizedLineBreak(builder);
for (int j = 0; j < indent+2; j++) {
for (int j = 0; j < indent + 2; j++) {
builder.append(indentString);
}
w.getOrderBy().toStringOrderByElements(builder);

if (w.getWindowElement() != null) {
if (w.getOrderBy().getOrderByElements() != null) {
appendNormalizedLineBreak(builder);
for (int j = 0; j < indent+2; j++) {
for (int j = 0; j < indent + 2; j++) {
builder.append(indentString);
}
}
Expand Down Expand Up @@ -2893,7 +2891,7 @@ private static void appendExpression(Expression expression, Alias alias, StringB
if (castExpression.isImplicitCast()) {
appendKeyWord(builder, outputFormat, castExpression.getColDataType().toString(), "", " ");
appendExpression(castExpression.getLeftExpression(), null, builder, indent, i, n, false,
BreakLine.NEVER);
BreakLine.NEVER);
} else if (castExpression.isUseCastKeyword()) {
if (castExpression.getColumnDefinitions().size() > 1) {
appendFunction(builder, outputFormat, castExpression.keyword, " ", "( ");
Expand Down Expand Up @@ -2971,12 +2969,15 @@ private static void appendExpression(Expression expression, Alias alias, StringB
TranscodingFunction transcodingFunction = (TranscodingFunction) expression;
appendFunction(builder, outputFormat, "Convert", "", "(");
if (transcodingFunction.isTranscodeStyle()) {
appendExpression(transcodingFunction.getExpression(), null, builder, indent, 0, 1, false, BreakLine.AS_NEEDED);
appendExpression(transcodingFunction.getExpression(), null, builder, indent, 0, 1, false,
BreakLine.AS_NEEDED);
appendKeyWord(builder, outputFormat, "USING", " ", "");
appendKeyWord(builder, outputFormat, transcodingFunction.getTranscodingName(), " ", " )");
} else {
appendKeyWord(builder, outputFormat, transcodingFunction.getColDataType().toString(), " ", ", ");
appendExpression(transcodingFunction.getExpression(), null, builder, indent, 0, 1, false, BreakLine.AS_NEEDED);
appendKeyWord(builder, outputFormat, transcodingFunction.getColDataType().toString(), " ",
", ");
appendExpression(transcodingFunction.getExpression(), null, builder, indent, 0, 1, false,
BreakLine.AS_NEEDED);

String transcodingName = transcodingFunction.getTranscodingName();
if (transcodingName != null && !transcodingName.isEmpty()) {
Expand All @@ -2985,7 +2986,7 @@ private static void appendExpression(Expression expression, Alias alias, StringB
builder.append(" )");
}
}
} else if(expression instanceof AnalyticExpression) {
} else if (expression instanceof AnalyticExpression) {
AnalyticExpression analyticExpression = (AnalyticExpression) expression;

int subIndent = getSubIndent(builder, false);
Expand All @@ -2999,10 +3000,12 @@ private static void appendExpression(Expression expression, Alias alias, StringB
appendExpression(expr, null, builder, indent, 0, 1, false, BreakLine.NEVER);
if (analyticExpression.getOffset() != null) {
builder.append(", ");
appendExpression(analyticExpression.getOffset(), null, builder, indent, 0, 1, true, BreakLine.NEVER);
if (analyticExpression.getDefaultValue()!= null) {
appendExpression(analyticExpression.getOffset(), null, builder, indent, 0, 1, true,
BreakLine.NEVER);
if (analyticExpression.getDefaultValue() != null) {
builder.append(", ");
appendExpression(analyticExpression.getDefaultValue(), null, builder, indent, 0, 1, true, BreakLine.NEVER);
appendExpression(analyticExpression.getDefaultValue(), null, builder, indent, 0, 1,
true, BreakLine.NEVER);
}
}
} else if (analyticExpression.isAllColumns()) {
Expand All @@ -3025,7 +3028,8 @@ private static void appendExpression(Expression expression, Alias alias, StringB

if (analyticExpression.getFuncOrderBy() != null) {
builder.append(" ORDER BY ");
builder.append(analyticExpression.getFuncOrderBy().stream().map(OrderByElement::toString).collect(Collectors.joining(", ")));
builder.append(analyticExpression.getFuncOrderBy().stream().map(OrderByElement::toString)
.collect(Collectors.joining(", ")));
}

if (analyticExpression.getLimit() != null) {
Expand All @@ -3035,15 +3039,15 @@ private static void appendExpression(Expression expression, Alias alias, StringB

if (analyticExpression.getKeep() != null) {
appendNormalizedLineBreak(builder);
for (int j = 0; j < subIndent+1; j++) {
for (int j = 0; j < subIndent + 1; j++) {
builder.append(indentString);
}
builder.append(analyticExpression.getKeep()).append(" ");
}

if (analyticExpression.getFilterExpression() != null) {
appendNormalizedLineBreak(builder);
for (int j = 0; j < subIndent+1; j++) {
for (int j = 0; j < subIndent + 1; j++) {
builder.append(indentString);
}
builder.append("FILTER ( WHERE ");
Expand All @@ -3063,14 +3067,14 @@ private static void appendExpression(Expression expression, Alias alias, StringB
return;
case WITHIN_GROUP:
appendNormalizedLineBreak(builder);
for (int j = 0; j < subIndent+1; j++) {
for (int j = 0; j < subIndent + 1; j++) {
builder.append(indentString);
}
builder.append("WITHIN GROUP");
break;
case WITHIN_GROUP_OVER:
appendNormalizedLineBreak(builder);
for (int j = 0; j < subIndent+1; j++) {
for (int j = 0; j < subIndent + 1; j++) {
builder.append(indentString);
}
builder.append("WITHIN GROUP ( ");
Expand All @@ -3081,7 +3085,7 @@ private static void appendExpression(Expression expression, Alias alias, StringB
break;
default:
appendNormalizedLineBreak(builder);
for (int j = 0; j < subIndent+1; j++) {
for (int j = 0; j < subIndent + 1; j++) {
builder.append(indentString);
}
builder.append("OVER");
Expand Down

0 comments on commit 2b57ca6

Please sign in to comment.