hql.g:564:1: whenClause : ( WHEN ^ logicalExpression THEN ! expression ) ;
324796
public final hqlParser.whenClause_return whenClause() throws RecognitionException {
		hqlParser.whenClause_return retval = new hqlParser.whenClause_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token WHEN216=null;
		Token THEN218=null;
		ParserRuleReturnScope logicalExpression217 =null;
		ParserRuleReturnScope expression219 =null;

		CommonTree WHEN216_tree=null;
		CommonTree THEN218_tree=null;

		try {
			// hql.g:565:2: ( ( WHEN ^ logicalExpression THEN ! expression ) )
			// hql.g:565:4: ( WHEN ^ logicalExpression THEN ! expression )
			{
			root_0 = (CommonTree)adaptor.nil();


			// hql.g:565:4: ( WHEN ^ logicalExpression THEN ! expression )
			// hql.g:565:5: WHEN ^ logicalExpression THEN ! expression
			{
			WHEN216=(Token)match(input,WHEN,FOLLOW_WHEN_in_whenClause2651);
			WHEN216_tree = (CommonTree)adaptor.create(WHEN216);
			root_0 = (CommonTree)adaptor.becomeRoot(WHEN216_tree, root_0);

			pushFollow(FOLLOW_logicalExpression_in_whenClause2654);
			logicalExpression217=logicalExpression();
			state._fsp--;

			adaptor.addChild(root_0, logicalExpression217.getTree());

			THEN218=(Token)match(input,THEN,FOLLOW_THEN_in_whenClause2656);
			pushFollow(FOLLOW_expression_in_whenClause2659);
			expression219=expression();
			state._fsp--;

			adaptor.addChild(root_0, expression219.getTree());

			}

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
931315
public final void mWHERE() throws RecognitionException {
		try {
			int _type = WHERE;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// hql.g:71:7: ( 'where' )
			// hql.g:71:9: 'where'
			{
			match("where"); if (state.failed) return;

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
945892
private Pair<List<BooleanExpression>, Optional<BooleanExpression>> extractWhereConditions(SelectQueryAware selectQueryAware) {
        
        List<BooleanExpression> whereConditions = new ArrayList<>();
        Optional<BooleanExpression> whereExpressionCandidate = selectQueryAware.getWhereExpression();
        if (whereExpressionCandidate.isPresent()) {
            whereConditions.add(whereExpressionCandidate.get());
        }
        
        boolean noGroupByTaskExists = selectQueryAware.getGroupByExpressions().isEmpty();
        Optional<BooleanExpression> havingExpressionCandidate = selectQueryAware.getHavingExpression();
        if (havingExpressionCandidate.isPresent() && noGroupByTaskExists) {
            whereConditions.add(havingExpressionCandidate.get());
            return new Pair<>(whereConditions, Optional.empty());
        } else {
            return new Pair<>(whereConditions, havingExpressionCandidate);
        }
    }
740383
public final hqlParser.withClause_return withClause() throws RecognitionException {
		hqlParser.withClause_return retval = new hqlParser.withClause_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token WITH86=null;
		ParserRuleReturnScope logicalExpression87 =null;

		CommonTree WITH86_tree=null;

		try {
			// hql.g:285:2: ( WITH ^ logicalExpression )
			// hql.g:285:4: WITH ^ logicalExpression
			{
			root_0 = (CommonTree)adaptor.nil();


			WITH86=(Token)match(input,WITH,FOLLOW_WITH_in_withClause1288);
			WITH86_tree = (CommonTree)adaptor.create(WITH86);
			root_0 = (CommonTree)adaptor.becomeRoot(WITH86_tree, root_0);

			pushFollow(FOLLOW_logicalExpression_in_withClause1291);
			logicalExpression87=logicalExpression();
			state._fsp--;

			adaptor.addChild(root_0, logicalExpression87.getTree());

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
1104268
@Override
    public StringBuilder getFilterClause() {
        StringBuilder builder = new StringBuilder();
        builder.append(columnName);
        builder.append(" LIKE ");
        builder.append(':').append(name);
        if (condition != null) {
            builder.append(" AND ");
            builder.append(condition);
        }
        return builder;
    }
1116819
public final hqlParser.intoClause_return intoClause() throws RecognitionException {
		hqlParser.intoClause_return retval = new hqlParser.intoClause_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token INTO30=null;
		ParserRuleReturnScope path31 =null;
		ParserRuleReturnScope insertablePropertySpec32 =null;

		CommonTree INTO30_tree=null;

		try {
			// hql.g:221:2: ( INTO ^ path insertablePropertySpec )
			// hql.g:221:4: INTO ^ path insertablePropertySpec
			{
			root_0 = (CommonTree)adaptor.nil();


			INTO30=(Token)match(input,INTO,FOLLOW_INTO_in_intoClause847);
			INTO30_tree = (CommonTree)adaptor.create(INTO30);
			root_0 = (CommonTree)adaptor.becomeRoot(INTO30_tree, root_0);

			pushFollow(FOLLOW_path_in_intoClause850);
			path31=path();
			state._fsp--;

			adaptor.addChild(root_0, path31.getTree());

			 WeakKeywords();
			pushFollow(FOLLOW_insertablePropertySpec_in_intoClause854);
			insertablePropertySpec32=insertablePropertySpec();
			state._fsp--;

			adaptor.addChild(root_0, insertablePropertySpec32.getTree());

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
1311879
public final hqlParser.logicalExpression_return logicalExpression() throws RecognitionException {
		hqlParser.logicalExpression_return retval = new hqlParser.logicalExpression_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		ParserRuleReturnScope expression153 =null;


		try {
			// hql.g:405:2: ( expression )
			// hql.g:405:4: expression
			{
			root_0 = (CommonTree)adaptor.nil();


			pushFollow(FOLLOW_expression_in_logicalExpression1866);
			expression153=expression();
			state._fsp--;

			adaptor.addChild(root_0, expression153.getTree());

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
223861
private void lhs( RuleDescrBuilder rule ) throws RecognitionException {
        match( input,
               DRL5Lexer.ID,
               DroolsSoftKeywords.WHEN,
               null,
               DroolsEditorType.KEYWORD );
        if ( state.failed ) return;

        if ( input.LA( 1 ) == DRL5Lexer.COLON ) {
            match( input,
                   DRL5Lexer.COLON,
                   null,
                   null,
                   DroolsEditorType.SYMBOL );
            if ( state.failed ) return;
        }

        lhsExpression( rule != null ? rule.lhs() : null );

    }
341457
StatementDMQL compileUpdateStatement(RangeVariable[] outerRanges) {

        read();

        Expression[]   updateExpressions;
        int[]          columnMap;
        boolean[]      columnCheckList;
        OrderedHashSet colNames = new OrderedHashSet();
        HsqlArrayList  exprList = new HsqlArrayList();
        RangeVariable[] rangeVariables = {
            readSimpleRangeVariable(StatementTypes.UPDATE_WHERE) };
        Table table     = rangeVariables[0].rangeTable;
        Table baseTable = table.getBaseTable();

        readThis(Tokens.SET);
        readSetClauseList(rangeVariables, colNames, exprList);

        columnMap         = table.getColumnIndexes(colNames);
        columnCheckList   = table.getColumnCheckList(columnMap);
        updateExpressions = new Expression[exprList.size()];

        exprList.toArray(updateExpressions);

        Expression condition = null;

        if (token.tokenType == Tokens.WHERE) {
            read();

            condition = XreadBooleanValueExpression();

            HsqlList unresolved =
                condition.resolveColumnReferences(outerRanges, null);

            unresolved = Expression.resolveColumnSet(rangeVariables,
                    unresolved, null);

            ExpressionColumn.checkColumnsResolved(unresolved);
            condition.resolveTypes(session, null);

            if (condition.isParam()) {
                condition.dataType = Type.SQL_BOOLEAN;
            } else if (condition.getDataType() != Type.SQL_BOOLEAN) {
                throw Error.error(ErrorCode.X_42568);
            }
        }

        resolveUpdateExpressions(table, rangeVariables, columnMap,
                                 updateExpressions, outerRanges);

        if (baseTable != null && table != baseTable) {
            QuerySpecification select =
                ((TableDerived) table).getQueryExpression().getMainSelect();

            if (condition != null) {
                condition =
                    condition.replaceColumnReferences(rangeVariables[0],
                                                      select.exprColumns);
            }

            rangeVariables[0] = new RangeVariable(select.rangeVariables[0]);
            condition = ExpressionLogical.andExpressions(select.queryCondition,
                    condition);
        }

        if (condition != null) {
            RangeVariableResolver resolver =
                new RangeVariableResolver(rangeVariables, condition,
                                          compileContext);

            resolver.processConditions();

            rangeVariables = resolver.rangeVariables;
        }

        if (baseTable != null && table != baseTable) {
            int[] baseColumnMap = table.getBaseTableColumnMap();
            int[] newColumnMap  = new int[columnMap.length];

            ArrayUtil.projectRow(baseColumnMap, columnMap, newColumnMap);

            columnMap = newColumnMap;
        }

        StatementDMQL cs = new StatementDML(session, table, rangeVariables,
                                            columnMap, updateExpressions,
                                            columnCheckList, compileContext);

        return cs;
    }
891185
private static void checkNesting(final BooleanExpression expression,
			final List<BooleanExpression> visitedExpressions) {
		if (visitedExpressions.contains(expression)) {
			// Unfortunately, we can't give much more information - even calling toString() will overflow the stack.
			throw new SyntaxException("An expression can not contain itself.");
		}

		visitedExpressions.add(expression);

		if (expression instanceof GroupExpression) {
			GroupExpression group = (GroupExpression) expression;
			for (BooleanExpression operand : group.getOperands()) {
				checkNesting(operand, visitedExpressions);
			}
		}
	}
638362
public final hqlParser.orderByClause_return orderByClause() throws RecognitionException {
		hqlParser.orderByClause_return retval = new hqlParser.orderByClause_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token ORDER126=null;
		Token string_literal127=null;
		Token COMMA129=null;
		ParserRuleReturnScope orderElement128 =null;
		ParserRuleReturnScope orderElement130 =null;

		CommonTree ORDER126_tree=null;
		CommonTree string_literal127_tree=null;
		CommonTree COMMA129_tree=null;

		try {
			// hql.g:336:2: ( ORDER ^ 'by' ! orderElement ( COMMA ! orderElement )* )
			// hql.g:336:4: ORDER ^ 'by' ! orderElement ( COMMA ! orderElement )*
			{
			root_0 = (CommonTree)adaptor.nil();


			ORDER126=(Token)match(input,ORDER,FOLLOW_ORDER_in_orderByClause1603);
			ORDER126_tree = (CommonTree)adaptor.create(ORDER126);
			root_0 = (CommonTree)adaptor.becomeRoot(ORDER126_tree, root_0);

			string_literal127=(Token)match(input,LITERAL_by,FOLLOW_LITERAL_by_in_orderByClause1606);
			pushFollow(FOLLOW_orderElement_in_orderByClause1609);
			orderElement128=orderElement();
			state._fsp--;

			adaptor.addChild(root_0, orderElement128.getTree());

			// hql.g:336:30: ( COMMA ! orderElement )*
			loop40:
			while (true) {
				int alt40=2;
				int LA40_0 = input.LA(1);
				if ( (LA40_0==COMMA) ) {
					alt40=1;
				}

				switch (alt40) {
				case 1 :
					// hql.g:336:32: COMMA ! orderElement
					{
					COMMA129=(Token)match(input,COMMA,FOLLOW_COMMA_in_orderByClause1613);
					pushFollow(FOLLOW_orderElement_in_orderByClause1616);
					orderElement130=orderElement();
					state._fsp--;

					adaptor.addChild(root_0, orderElement130.getTree());

					}
					break;

				default :
					break loop40;
				}
			}

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
1139897
public function WhenClause()
    {
        $this->match(Lexer::T_WHEN);
        $conditionalExpression = $this->ConditionalExpression();
        $this->match(Lexer::T_THEN);

        return new AST\WhenClause($conditionalExpression, $this->ScalarExpression());
    }
897775
function isHeadOfExpressionStatement(node) {
			var parent = node.parent;

			while (parent) {
				switch (parent.type) {
					case "SequenceExpression":
						if (parent.expressions[0] !== node || isParenthesised(node)) {
							return false;
						}
						break;

					case "UnaryExpression":
					case "UpdateExpression":
						if (parent.prefix || isParenthesised(node)) {
							return false;
						}
						break;

					case "BinaryExpression":
					case "LogicalExpression":
						if (parent.left !== node || isParenthesised(node)) {
							return false;
						}
						break;

					case "ConditionalExpression":
						if (parent.test !== node || isParenthesised(node)) {
							return false;
						}
						break;

					case "CallExpression":
						if (parent.callee !== node || isParenthesised(node)) {
							return false;
						}
						break;

					case "MemberExpression":
						if (parent.object !== node || isParenthesised(node)) {
							return false;
						}
						break;

					case "ExpressionStatement":
						return true;

					default:
						return false;
				}

				node = parent;
				parent = parent.parent;
			}

			/* istanbul ignore next */
			throw new Error("unreachable");
		}
708367
protected void buildExpression(String expression) throws ParseException {
        expressionParsed = true;

        try {

            if (seconds == null) {
                seconds = new TreeSet<Integer>();
            }
            if (minutes == null) {
                minutes = new TreeSet<Integer>();
            }
            if (hours == null) {
                hours = new TreeSet<Integer>();
            }
            if (daysOfMonth == null) {
                daysOfMonth = new TreeSet<Integer>();
            }
            if (months == null) {
                months = new TreeSet<Integer>();
            }
            if (daysOfWeek == null) {
                daysOfWeek = new TreeSet<Integer>();
            }
            if (years == null) {
                years = new TreeSet<Integer>();
            }

            int exprOn = SECOND;

            StringTokenizer exprsTok = new StringTokenizer(expression, " \t",
                    false);

            while (exprsTok.hasMoreTokens() && exprOn <= YEAR) {
                String expr = exprsTok.nextToken().trim();

                // throw an exception if L is used with other days of the month
                if(exprOn == DAY_OF_MONTH && expr.indexOf('L') != -1 && expr.length() > 1 && expr.indexOf(",") >= 0) {
                    throw new ParseException("Support for specifying 'L' and 'LW' with other days of the month is not implemented", -1);
                }
                // throw an exception if L is used with other days of the week
                if(exprOn == DAY_OF_WEEK && expr.indexOf('L') != -1 && expr.length() > 1  && expr.indexOf(",") >= 0) {
                    throw new ParseException("Support for specifying 'L' with other days of the week is not implemented", -1);
                }
                if(exprOn == DAY_OF_WEEK && expr.indexOf('#') != -1 && expr.indexOf('#', expr.indexOf('#') +1) != -1) {
                    throw new ParseException("Support for specifying multiple \"nth\" days is not imlemented.", -1);
                }
                
                StringTokenizer vTok = new StringTokenizer(expr, ",");
                while (vTok.hasMoreTokens()) {
                    String v = vTok.nextToken();
                    storeExpressionVals(0, v, exprOn);
                }

                exprOn++;
            }

            if (exprOn <= DAY_OF_WEEK) {
                throw new ParseException("Unexpected end of expression.",
                            expression.length());
            }

            if (exprOn <= YEAR) {
                storeExpressionVals(0, "*", YEAR);
            }

            TreeSet<Integer> dow = getSet(DAY_OF_WEEK);
            TreeSet<Integer> dom = getSet(DAY_OF_MONTH);

            // Copying the logic from the UnsupportedOperationException below
            boolean dayOfMSpec = !dom.contains(NO_SPEC);
            boolean dayOfWSpec = !dow.contains(NO_SPEC);

            if (dayOfMSpec && !dayOfWSpec) { 
                // skip
            } else if (dayOfWSpec && !dayOfMSpec) { 
                // skip
            } else {
                throw new ParseException(
                        "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.", 0);
            }
        } catch (ParseException pe) {
            throw pe;
        } catch (Exception e) {
            throw new ParseException("Illegal cron expression format ("
                    + e.toString() + ")", 0);
        }
    }
1140134
public final void mWITH() throws RecognitionException {
		try {
			int _type = WITH;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// hql.g:72:6: ( 'with' )
			// hql.g:72:8: 'with'
			{
			match("with"); if (state.failed) return;

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
567570
public final void conditionalOrExpression() throws RecognitionException {
		int conditionalOrExpression_StartIndex = input.index();

		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 111) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1142:5: ( conditionalAndExpression ( '||' conditionalAndExpression )* )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1142:9: conditionalAndExpression ( '||' conditionalAndExpression )*
			{
			pushFollow(FOLLOW_conditionalAndExpression_in_conditionalOrExpression5074);
			conditionalAndExpression();
			state._fsp--;
			if (state.failed) return;
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1142:34: ( '||' conditionalAndExpression )*
			loop143:
			while (true) {
				int alt143=2;
				int LA143_0 = input.LA(1);
				if ( (LA143_0==124) ) {
					alt143=1;
				}

				switch (alt143) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1142:36: '||' conditionalAndExpression
					{
					match(input,124,FOLLOW_124_in_conditionalOrExpression5078); if (state.failed) return;
					pushFollow(FOLLOW_conditionalAndExpression_in_conditionalOrExpression5080);
					conditionalAndExpression();
					state._fsp--;
					if (state.failed) return;
					}
					break;

				default :
					break loop143;
				}
			}

			}

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 111, conditionalOrExpression_StartIndex); }

		}
	}
471809
public static boolean hasWhereClause(JPQLExpression jpqlExpression)
    {
        if (isSelectStatement(jpqlExpression))
        {
            return ((SelectStatement) jpqlExpression.getQueryStatement()).hasWhereClause();
        }
        else if (isUpdateStatement(jpqlExpression))
        {
            return ((UpdateStatement) jpqlExpression.getQueryStatement()).hasWhereClause();
        }
        if (isDeleteStatement(jpqlExpression))
        {
            return ((DeleteStatement) jpqlExpression.getQueryStatement()).hasWhereClause();
        }
        return false;
    }