Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,13 @@ public <S> StringBuilder visit(AliasedExpression expression, S context) {

@Override
public <S> StringBuilder visit(Addition addition, S context) {
deparse(addition, " + ", null);
deparse(addition, " + ", context);
return builder;
}

@Override
public <S> StringBuilder visit(AndExpression andExpression, S context) {
deparse(andExpression, andExpression.isUseOperator() ? " && " : " AND ",
null);
deparse(andExpression, andExpression.isUseOperator() ? " && " : " AND ", context);
return builder;
}

Expand Down Expand Up @@ -225,19 +224,19 @@ public <S> StringBuilder visit(OverlapsCondition overlapsCondition, S context) {

@Override
public <S> StringBuilder visit(EqualsTo equalsTo, S context) {
deparse(equalsTo, " = ", null);
deparse(equalsTo, " = ", context);
return builder;
}

@Override
public <S> StringBuilder visit(Division division, S context) {
deparse(division, " / ", null);
deparse(division, " / ", context);
return builder;
}

@Override
public <S> StringBuilder visit(IntegerDivision division, S context) {
deparse(division, " DIV ", null);
deparse(division, " DIV ", context);
return builder;
}

Expand Down Expand Up @@ -266,13 +265,13 @@ public <S> StringBuilder visit(NotExpression notExpr, S context) {

@Override
public <S> StringBuilder visit(BitwiseRightShift expr, S context) {
deparse(expr, " >> ", null);
deparse(expr, " >> ", context);
return builder;
}

@Override
public <S> StringBuilder visit(BitwiseLeftShift expr, S context) {
deparse(expr, " << ", null);
deparse(expr, " << ", context);
return builder;
}

Expand Down Expand Up @@ -303,13 +302,13 @@ public <S> StringBuilder deparse(

@Override
public <S> StringBuilder visit(GreaterThan greaterThan, S context) {
deparse(greaterThan, " > ", null);
deparse(greaterThan, " > ", context);
return builder;
}

@Override
public <S> StringBuilder visit(GreaterThanEquals greaterThanEquals, S context) {
deparse(greaterThanEquals, " >= ", null);
deparse(greaterThanEquals, " >= ", context);

return builder;
}
Expand Down Expand Up @@ -616,53 +615,51 @@ public <S> StringBuilder visit(LongValue longValue, S context) {

@Override
public <S> StringBuilder visit(MinorThan minorThan, S context) {
deparse(minorThan, " < ", null);
deparse(minorThan, " < ", context);

return builder;
}

@Override
public <S> StringBuilder visit(MinorThanEquals minorThanEquals, S context) {
deparse(minorThanEquals, " <= ", null);
deparse(minorThanEquals, " <= ", context);

return builder;
}

@Override
public <S> StringBuilder visit(Multiplication multiplication, S context) {
deparse(multiplication, " * ", null);
deparse(multiplication, " * ", context);

return builder;
}

@Override
public <S> StringBuilder visit(NotEqualsTo notEqualsTo, S context) {
deparse(notEqualsTo,
" " + notEqualsTo.getStringExpression() + " ", null);
" " + notEqualsTo.getStringExpression() + " ", context);

return builder;
}

@Override
public <S> StringBuilder visit(DoubleAnd doubleAnd, S context) {
deparse(doubleAnd, " " + doubleAnd.getStringExpression() + " ",
null);
deparse(doubleAnd, " " + doubleAnd.getStringExpression() + " ", context);

return builder;
}

@Override
public <S> StringBuilder visit(Contains contains, S context) {
deparse(contains, " " + contains.getStringExpression() + " ",
null);
deparse(contains, " " + contains.getStringExpression() + " ", context);

return builder;
}

@Override
public <S> StringBuilder visit(ContainedBy containedBy, S context) {
deparse(containedBy,
" " + containedBy.getStringExpression() + " ", null);
" " + containedBy.getStringExpression() + " ", context);

return builder;
}
Expand All @@ -676,14 +673,14 @@ public <S> StringBuilder visit(NullValue nullValue, S context) {

@Override
public <S> StringBuilder visit(OrExpression orExpression, S context) {
deparse(orExpression, " OR ", null);
deparse(orExpression, " OR ", context);

return builder;
}

@Override
public <S> StringBuilder visit(XorExpression xorExpression, S context) {
deparse(xorExpression, " XOR ", null);
deparse(xorExpression, " XOR ", context);

return builder;
}
Expand All @@ -708,7 +705,7 @@ public <S> StringBuilder visit(BooleanValue booleanValue, S context) {

@Override
public <S> StringBuilder visit(Subtraction subtraction, S context) {
deparse(subtraction, " - ", null);
deparse(subtraction, " - ", context);
return builder;
}

Expand All @@ -727,7 +724,7 @@ public <S> StringBuilder visit(Select select, S context) {
builder.append("WITH ");
for (Iterator<WithItem<?>> iter = select.getWithItemsList().iterator(); iter
.hasNext();) {
iter.next().accept(selectVisitor, null);
iter.next().accept(selectVisitor, context);
if (iter.hasNext()) {
builder.append(", ");
}
Expand All @@ -736,7 +733,7 @@ public <S> StringBuilder visit(Select select, S context) {
builder.append(" ");
}

select.accept(selectVisitor, null);
select.accept(selectVisitor, context);
}
return builder;
}
Expand Down Expand Up @@ -908,6 +905,15 @@ public <S> StringBuilder visit(Column tableColumn, S context) {
return builder;
}

private <S> void deParseOrderByElement(OrderByDeParser deParser,
OrderByElement element, S context) {
if (context == null) {
deParser.deParseElement(element);
} else {
deParser.deParseElement(element, context);
}
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public <S> StringBuilder visit(Function function, S context) {
Expand Down Expand Up @@ -966,7 +972,7 @@ public <S> StringBuilder visit(Function function, S context) {
} else {
comma = true;
}
orderByDeParser.deParseElement(orderByElement);
deParseOrderByElement(orderByDeParser, orderByElement, context);
}
}

Expand All @@ -975,7 +981,7 @@ public <S> StringBuilder visit(Function function, S context) {
}

if (function.getLimit() != null) {
new LimitDeparser(this, builder).deParse(function.getLimit());
new LimitDeparser(this, builder).deParse(function.getLimit(), context);
}

// Generic keyword arguments (e.g. SEPARATOR ',', USING utf8)
Expand Down Expand Up @@ -1096,7 +1102,7 @@ public <S> StringBuilder visit(AnyComparisonExpression anyComparisonExpression,

@Override
public <S> StringBuilder visit(Concat concat, S context) {
deparse(concat, " || ", null);
deparse(concat, " || ", context);
return builder;
}

Expand Down Expand Up @@ -1151,25 +1157,25 @@ public void visit(Concat concat) {

@Override
public <S> StringBuilder visit(Matches matches, S context) {
deparse(matches, " @@ ", null);
deparse(matches, " @@ ", context);
return builder;
}

@Override
public <S> StringBuilder visit(BitwiseAnd bitwiseAnd, S context) {
deparse(bitwiseAnd, " & ", null);
deparse(bitwiseAnd, " & ", context);
return builder;
}

@Override
public <S> StringBuilder visit(BitwiseOr bitwiseOr, S context) {
deparse(bitwiseOr, " | ", null);
deparse(bitwiseOr, " | ", context);
return builder;
}

@Override
public <S> StringBuilder visit(BitwiseXor bitwiseXor, S context) {
deparse(bitwiseXor, " ^ ", null);
deparse(bitwiseXor, " ^ ", context);
return builder;
}

Expand Down Expand Up @@ -1202,7 +1208,7 @@ public <S> StringBuilder visit(CastExpression cast, S context) {

@Override
public <S> StringBuilder visit(Modulo modulo, S context) {
deparse(modulo, " % ", null);
deparse(modulo, " % ", context);
return builder;
}

Expand Down Expand Up @@ -1269,7 +1275,7 @@ public <S> StringBuilder visit(AnalyticExpression analyticExpression, S context)
}

if (analyticExpression.getLimit() != null) {
new LimitDeparser(this, builder).deParse(analyticExpression.getLimit());
new LimitDeparser(this, builder).deParse(analyticExpression.getLimit(), context);
}

builder.append(") ");
Expand Down Expand Up @@ -1347,7 +1353,7 @@ public <S> StringBuilder visit(AnalyticExpression analyticExpression, S context)
if (i > 0) {
builder.append(", ");
}
orderByDeParser.deParseElement(orderByElements.get(i));
deParseOrderByElement(orderByDeParser, orderByElements.get(i), context);
}
}

Expand Down Expand Up @@ -1446,7 +1452,8 @@ public <S> StringBuilder visit(OracleHierarchicalExpression hierarchicalExpressi

@Override
public <S> StringBuilder visit(RegExpMatchOperator regExpMatchOperator, S context) {
deparse(regExpMatchOperator, " " + regExpMatchOperator.getStringExpression() + " ", null);
deparse(regExpMatchOperator, " " + regExpMatchOperator.getStringExpression() + " ",
context);
return builder;
}

Expand All @@ -1459,7 +1466,7 @@ public <S> StringBuilder visit(JsonExpression jsonExpr, S context) {

@Override
public <S> StringBuilder visit(JsonOperator jsonExpr, S context) {
deparse(jsonExpr, " " + jsonExpr.getStringExpression() + " ", null);
deparse(jsonExpr, " " + jsonExpr.getStringExpression() + " ", context);
return builder;
}

Expand Down Expand Up @@ -1497,7 +1504,7 @@ public <S> StringBuilder visit(MySQLGroupConcat groupConcat, S context) {
public <S> StringBuilder visit(ExpressionList<? extends Expression> expressionList, S context) {
ExpressionListDeParser<?> expressionListDeParser =
new ExpressionListDeParser<>(this, builder);
expressionListDeParser.deParse(expressionList);
expressionListDeParser.deParse(expressionList, context);
return builder;
}

Expand All @@ -1508,7 +1515,7 @@ public <S> StringBuilder visit(RowConstructor<?> rowConstructor, S context) {
}
ExpressionListDeParser<?> expressionListDeParser =
new ExpressionListDeParser<>(this, builder);
expressionListDeParser.deParse(rowConstructor);
expressionListDeParser.deParse(rowConstructor, context);
return builder;
}

Expand Down Expand Up @@ -1827,25 +1834,25 @@ public <S> StringBuilder visit(IsDistinctExpression isDistinctExpression, S cont
@Override
public <S> StringBuilder visit(GeometryDistance geometryDistance, S context) {
deparse(geometryDistance,
" " + geometryDistance.getStringExpression() + " ", null);
" " + geometryDistance.getStringExpression() + " ", context);
return builder;
}

@Override
public <S> StringBuilder visit(Intersects intersects, S context) {
deparse(intersects, " # ", null);
deparse(intersects, " # ", context);
return builder;
}

@Override
public <S> StringBuilder visit(TSQLLeftJoin tsqlLeftJoin, S context) {
this.deparse(tsqlLeftJoin, " *= ", null);
this.deparse(tsqlLeftJoin, " *= ", context);
return builder;
}

@Override
public <S> StringBuilder visit(TSQLRightJoin tsqlRightJoin, S context) {
this.deparse(tsqlRightJoin, " =* ", null);
this.deparse(tsqlRightJoin, " =* ", context);
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public ExpressionListDeParser(ExpressionVisitor<StringBuilder> expressionVisitor

@Override
public void deParse(ExpressionList<?> expressionList) {
deParse(expressionList, null);
}

public <S> void deParse(ExpressionList<?> expressionList, S context) {
// @todo: remove this NameExpressionList related part
String comma = expressionList instanceof NamedExpressionList
? " "
Expand All @@ -55,7 +59,7 @@ public void deParse(ExpressionList<?> expressionList) {
builder.append(name);
builder.append(" ");
}
expression.accept(expressionVisitor, null);
expression.accept(expressionVisitor, context);
i++;
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/sf/jsqlparser/util/deparser/LimitDeparser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public LimitDeparser(ExpressionVisitor<StringBuilder> expressionVisitor, StringB

@Override
public void deParse(Limit limit) {
deParse(limit, null);
}

public <S> void deParse(Limit limit, S context) {
builder.append(" LIMIT ");
if (limit.isLimitNull()) {
builder.append("NULL");
Expand All @@ -30,19 +34,19 @@ public void deParse(Limit limit) {
builder.append("ALL");
} else {
if (null != limit.getOffset()) {
limit.getOffset().accept(expressionVisitor, null);
limit.getOffset().accept(expressionVisitor, context);
builder.append(", ");
}

if (null != limit.getRowCount()) {
limit.getRowCount().accept(expressionVisitor, null);
limit.getRowCount().accept(expressionVisitor, context);
}
}
}

if (limit.getByExpressions() != null) {
builder.append(" BY ");
limit.getByExpressions().accept(expressionVisitor, null);
limit.getByExpressions().accept(expressionVisitor, context);
}
}

Expand Down
Loading
Loading