3232/**
3333 * An ANTLR {@link org.antlr.v4.runtime.tree.ParseTreeVisitor} that renders an HQL query without making any changes.
3434 *
35+ * @author TaeHyun Kang(polyglot-k)
3536 * @author Greg Turnquist
3637 * @author Christoph Strobl
3738 * @author Oscar Fanchin
@@ -48,37 +49,42 @@ class HqlQueryRenderer extends HqlBaseVisitor<QueryTokenStream> {
4849 */
4950 static boolean isSubquery (ParserRuleContext ctx ) {
5051
51- if (ctx instanceof HqlParser .SubqueryContext || ctx instanceof HqlParser .CteContext ) {
52- return true ;
53- } else if (ctx instanceof HqlParser .SelectStatementContext ) {
54- return false ;
55- } else if (ctx instanceof HqlParser .InsertStatementContext ) {
56- return false ;
57- } else if (ctx instanceof HqlParser .DeleteStatementContext ) {
58- return false ;
59- } else if (ctx instanceof HqlParser .UpdateStatementContext ) {
60- return false ;
61- } else {
62- return ctx .getParent () != null && isSubquery (ctx .getParent ());
63- }
52+ while (ctx != null ) {
53+ if (ctx instanceof HqlParser .SubqueryContext || ctx instanceof HqlParser .CteContext ) {
54+ return true ;
55+ }
56+ if (ctx instanceof HqlParser .SelectStatementContext ||
57+ ctx instanceof HqlParser .InsertStatementContext ||
58+ ctx instanceof HqlParser .DeleteStatementContext ||
59+ ctx instanceof HqlParser .UpdateStatementContext
60+ ) {
61+ return false ;
62+ }
63+ ctx = ctx .getParent ();
64+ }
65+ return false ;
6466 }
6567
6668 /**
6769 * Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}?
6870 *
6971 * @return boolean
7072 */
71- static boolean isSetQuery (ParserRuleContext ctx ) {
72-
73- if (ctx instanceof HqlParser .OrderedQueryContext
74- && ctx .getParent () instanceof HqlParser .QueryExpressionContext qec ) {
75- if (qec .orderedQuery ().indexOf (ctx ) != 0 ) {
76- return true ;
77- }
78- }
79-
80- return ctx .getParent () != null && isSetQuery (ctx .getParent ());
81- }
73+ static boolean isSetQuery (ParserRuleContext ctx ) {
74+ while (ctx != null ) {
75+ ParserRuleContext parent = ctx .getParent ();
76+
77+ if (ctx instanceof HqlParser .OrderedQueryContext
78+ && parent instanceof HqlParser .QueryExpressionContext qec ) {
79+ if (qec .orderedQuery ().indexOf (ctx ) != 0 ) {
80+ return true ;
81+ }
82+ }
83+
84+ ctx = parent ;
85+ }
86+ return false ;
87+ }
8288
8389 @ Override
8490 public QueryTokenStream visitStart (HqlParser .StartContext ctx ) {
0 commit comments