Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Refine JOIN and function keyword rendering.

See #3692
  • Loading branch information
mp911de committed Jan 14, 2025
1 parent 237036c commit 4d1f401
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public QueryRendererBuilder visitJoin(HqlParser.JoinContext ctx) {

QueryRendererBuilder builder = QueryRenderer.builder();

builder.append(TOKEN_SPACE);
builder.appendExpression(visit(ctx.joinType()));
builder.append(QueryTokens.expression(ctx.JOIN()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ public QueryTokenStream visitEntityWithJoins(HqlParser.EntityWithJoinsContext ct

QueryRendererBuilder builder = QueryRenderer.builder();

builder.appendExpression(visit(ctx.fromRoot()));
builder.appendInline(QueryTokenStream.concat(ctx.joinSpecifier(), this::visit, TOKEN_SPACE));
builder.appendInline(visit(ctx.fromRoot()));
builder.appendInline(QueryTokenStream.concat(ctx.joinSpecifier(), this::visit, EMPTY_TOKEN));

return builder;
}
Expand Down Expand Up @@ -396,6 +396,7 @@ public QueryTokenStream visitJoin(HqlParser.JoinContext ctx) {

QueryRendererBuilder builder = QueryRenderer.builder();

builder.append(TOKEN_SPACE);
builder.append(visit(ctx.joinType()));
builder.append(QueryTokens.expression(ctx.JOIN()));

Expand Down Expand Up @@ -753,7 +754,7 @@ public QueryTokenStream visitOffsetClause(HqlParser.OffsetClauseContext ctx) {
QueryRendererBuilder builder = QueryRenderer.builder();

builder.append(QueryTokens.expression(ctx.OFFSET()));
builder.append(visit(ctx.parameterOrIntegerLiteral()));
builder.appendExpression(visit(ctx.parameterOrIntegerLiteral()));

if (ctx.ROW() != null) {
builder.append(QueryTokens.expression(ctx.ROW()));
Expand Down Expand Up @@ -3384,7 +3385,7 @@ public QueryTokenStream visitEveryFunction(HqlParser.EveryFunctionContext ctx) {
builder.append(TOKEN_CLOSE_PAREN);
} else {

builder.appendExpression(visit(ctx.collectionQuantifier()));
builder.append(visit(ctx.collectionQuantifier()));

builder.append(TOKEN_OPEN_PAREN);
builder.appendInline(visit(ctx.simplePath()));
Expand Down Expand Up @@ -3419,7 +3420,7 @@ public QueryTokenStream visitAnyFunction(HqlParser.AnyFunctionContext ctx) {
builder.append(TOKEN_CLOSE_PAREN);
} else {

builder.appendExpression(visit(ctx.collectionQuantifier()));
builder.append(visit(ctx.collectionQuantifier()));

builder.append(TOKEN_OPEN_PAREN);
builder.appendInline(visit(ctx.simplePath()));
Expand Down Expand Up @@ -3808,9 +3809,9 @@ public QueryTokenStream visitInList(HqlParser.InListContext ctx) {
if (ctx.simplePath() != null) {

if (ctx.ELEMENTS() != null) {
builder.append(QueryTokens.expression(ctx.ELEMENTS()));
builder.append(QueryTokens.token(ctx.ELEMENTS()));
} else if (ctx.INDICES() != null) {
builder.append(QueryTokens.expression(ctx.INDICES()));
builder.append(QueryTokens.token(ctx.INDICES()));
}

builder.append(TOKEN_OPEN_PAREN);
Expand Down Expand Up @@ -3843,9 +3844,9 @@ public QueryTokenStream visitExistsExpression(HqlParser.ExistsExpressionContext
builder.append(QueryTokens.expression(ctx.EXISTS()));

if (ctx.ELEMENTS() != null) {
builder.append(QueryTokens.expression(ctx.ELEMENTS()));
builder.append(QueryTokens.token(ctx.ELEMENTS()));
} else if (ctx.INDICES() != null) {
builder.append(QueryTokens.expression(ctx.INDICES()));
builder.append(QueryTokens.token(ctx.INDICES()));
}

builder.append(TOKEN_OPEN_PAREN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class QueryTokens {
/**
* Commonly use tokens.
*/
static final QueryToken EMPTY_TOKEN = token("");
static final QueryToken TOKEN_COMMA = token(", ");
static final QueryToken TOKEN_SPACE = token(" ");
static final QueryToken TOKEN_DOT = token(".");
Expand Down

0 comments on commit 4d1f401

Please sign in to comment.