Validates an expression being used as a {@code case} label in a {@code select}.
541455
static String validateSelectCaseLabel(ExprNode caseValue, ErrorReporter reporter) {
    boolean isNumeric;
    boolean isError;
    String value;
    if (caseValue instanceof StringNode) {
      value = ((StringNode) caseValue).getValue();
      // Validate that our select cases are argument names as required by the ICU MessageFormat
      // library. We can offer a much better user experience by doing this validation eagerly.
      // NOTE: in theory we could allow numeric select cases, but this is almost always an error
      // (they should have used plural), if there turns out to be some good reason for this (e.g.
      // the numbers are reflect ordinals instead of cardinals), then we can revisit this error.
      int argNumber = MessagePattern.validateArgumentName(value);
      if (argNumber != MessagePattern.ARG_NAME_NOT_NUMBER) {
        try {
          // there are more efficient ways to do this, but we are already in an error case so who
          // cares
          Long.parseLong(value);
          isNumeric = true;
        } catch (NumberFormatException nfe) {
          isNumeric = false;
        }
        isError = true;
      } else {
        isNumeric = false;
        isError = false;
      }
    } else {
      isNumeric = caseValue instanceof FloatNode || caseValue instanceof IntegerNode;
      isError = true;
      value = "";
    }
    if (isError) {
      reporter.report(
          caseValue.getSourceLocation(),
          SELECT_CASE_INVALID_VALUE,
          isNumeric ? "  Did you mean to use {plural} instead of {select}?" : "");
    }
    return value;
  }
736566
@Override
    public boolean validateLabel(String label) {
        Objects.requireNonNull(label, "label cannot be null");
        // check label is in set
        return !labels.contains(label);
    }
1101806
private String check() throws InvalidExpressionException {

        expression = expression.replaceAll("\\s","");
        expression = expression.toLowerCase();
        String var = "";

        if(expression.length() == 0) {
            throw new InvalidExpressionException("Empty Expression");
        }

        if(!expression.matches("[a-zA-Z0-9+*/^()-]+")) { // contains only operators, numbers, or letters
            throw new InvalidExpressionException("Syntax Error");
        }

        if(expression.matches("[+*/^()-]+")) { // doesn't contain any operands
            throw new InvalidExpressionException("Syntax Error");
        }

        String firstChar = expression.substring(0, 1);
        String lastChar = expression.substring(expression.length() - 1, expression.length());

        if(!firstChar.equals("-") && isOperator(firstChar) || firstChar.equals(")") || isOperator(lastChar) || lastChar.equals("(")) {
            throw new InvalidExpressionException("Syntax Error");
        }


        for(int i = 0; i < expression.length(); i++) {

            String temp = "";

            while(i < expression.length() && expression.substring(i, i + 1).matches("[a-zA-Z]")) {
                temp += expression.substring(i, i + 1);
                i++;
            }

            if(temp.length() == 1) {
                //i--; // ?? i must be decremented from the above while loop in this if block so the program can check the last character in the string
                if(var.length() == 0)
                    var = temp;
                if(!temp.equals(var)) {
                    throw new InvalidExpressionException("For now, expression must contain a single variable");
                }
                else if(i < expression.length() && expression.substring(i, i + 1).matches("[0-9]+")) {
                    throw new InvalidExpressionException("Syntax Error");
                }
            }
            else if(isFunction(temp)) {

                if(i < expression.length()) {
                    if(!expression.substring(i, i + 1).equals("(")) {
                        //System.out.println("Syntax Error: " + temp + " needs a parenthesis after it");// no parenthesis after function (EX: sin5)
                        throw new InvalidExpressionException("Syntax Error");
                    }
                }
                else {
                    //System.out.println("Syntax Error: " + temp + " needs an input"); // nothing after function (EX: 5 + sin)
                    throw new InvalidExpressionException("Syntax Error");
                }
            }
            else if(temp.length() != 0){
                //System.out.println(temp + ": function not found");
                throw new InvalidExpressionException(temp + ": function not found");
            }

            //i--; // ?? i must be decremented since it was left incremented in the above while loop
        }


        int cntOpenParen = 0;
        int cntCloseParen = 0;

        for(int i = 0; i < expression.length() - 1; i++) {

            String tmp1 = expression.substring(i, i + 1);
            String tmp2 = expression.substring(i + 1, i + 2);

            if(tmp1.equals("-")) {
                if(isOperator(tmp2) || tmp2.equals(")")) {
                    //System.out.println("Syntax Error: " + tmp1 + tmp2);
                    throw new InvalidExpressionException("Syntax Error");
                }
            }
            else if(tmp2.equals("-")) { // Also prevents next else if from rejecting an operator followed by a unary minus
                if(tmp1.equals("(")) {
                    //System.out.println("Syntax Error: " + tmp1 + tmp2);
                    throw new InvalidExpressionException("Syntax Error");
                }
            }
            else if((isOperator(tmp1) || tmp1.equals("(")) && (isOperator(tmp2) || tmp2.equals(")"))) {
                //System.out.println("Syntax Error: " + tmp1 + tmp2); // two operands in a row (examples: ++, (+, ())
                throw new InvalidExpressionException("Syntax Error");
            }
            else if(expression.substring(i, i + 1).equals("("))
                cntOpenParen++;
            else if(expression.substring(i, i + 1).equals(")"))
                cntCloseParen++;
        }

        if(cntOpenParen < cntCloseParen) { // found a ")" when the end of the expression was expected
            //System.out.println("Syntax Error: found ')' but expected end of expression");
            throw new InvalidExpressionException("Syntax Error");
        }

        return var;
    }
768077
private void validateModality(SqlNode query) {
		final SqlModality modality = deduceModality(query);
		if (query instanceof SqlSelect) {
			final SqlSelect select = (SqlSelect) query;
			validateModality(select, modality, true);
		} else if (query.getKind() == SqlKind.VALUES) {
			switch (modality) {
				case STREAM:
					throw newValidationError(query, Static.RESOURCE.cannotStreamValues());
			}
		} else {
			assert query.isA(SqlKind.SET_QUERY);
			final SqlCall call = (SqlCall) query;
			for (SqlNode operand : call.getOperandList()) {
				if (deduceModality(operand) != modality) {
					throw newValidationError(operand,
						Static.RESOURCE.streamSetOpInconsistentInputs());
				}
				validateModality(operand);
			}
		}
	}
206797
function validateExpression(node) {
            if (node.body.type === "BlockStatement") {
                return;
            }

            const arrowToken = sourceCode.getTokenBefore(node.body, isNotOpeningParenToken);
            const firstTokenOfBody = sourceCode.getTokenAfter(arrowToken);

            if (arrowToken.loc.end.line === firstTokenOfBody.loc.start.line && option === "below") {
                context.report({
                    node: firstTokenOfBody,
                    messageId: "expected",
                    fix: fixer => fixer.insertTextBefore(firstTokenOfBody, "\n")
                });
            } else if (arrowToken.loc.end.line !== firstTokenOfBody.loc.start.line && option === "beside") {
                context.report({
                    node: firstTokenOfBody,
                    messageId: "unexpected",
                    fix(fixer) {
                        if (sourceCode.getFirstTokenBetween(arrowToken, firstTokenOfBody, { includeComments: true, filter: isCommentToken })) {
                            return null;
                        }

                        return fixer.replaceTextRange([arrowToken.range[1], firstTokenOfBody.range[0]], " ");
                    }
                });
            }
        }
860099
private boolean isValidTaxonomy(final String label, final Double score) {
    return !StringUtils.isBlank(label)
           || score != null;
  }
1324225
private boolean validConditionalExpression(Node expr) {
    // The expression must have four children:
    // - The cond keyword
    // - A boolean expression
    // - A type transformation expression with the 'if' branch
    // - A type transformation expression with the 'else' branch
    if (!checkParameterCount(expr, Keywords.COND)) {
      return false;
    }
    // Check for the validity of the boolean and the expressions
    if (!validBooleanExpression(getCallArgument(expr, 0))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    if (!validTypeTransformationExpression(getCallArgument(expr, 1))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    if (!validTypeTransformationExpression(getCallArgument(expr, 2))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    return true;
  }
770383
function validatePrintMax(candidate, lowerBound, label) {
  if (typeof candidate !== 'number' || Number.isNaN(candidate)) {
    throw new Error('"' + label + '" must be a number');
  } else if (candidate < lowerBound) {
    throw new Error('"' + label + '" too small');
  }
}
185136
public static void validate(SpiExpressionList<?> expressions,
                                ListExpressionValidation validation,
                                boolean ignoreUnknown) {
        if (expressions == null) return;
        List<SpiExpression> list = expressions.getUnderlyingList();
        Iterator<SpiExpression> it = list.iterator();
        while (it.hasNext()) {
            it.next().validate(validation);
            if (ignoreUnknown && !validation.lastValid()) {
                it.remove();
            }
        }
    }
622721
private void validateDefaultValue(Node n) {
    if (n.isDefaultValue() && n.getParent().isParamList()) {
      Node targetNode = n.getFirstChild();
      JSDocInfo info = targetNode.getJSDocInfo();
      if (info == null) {
        return;
      }

      JSTypeExpression typeExpr = info.getType();
      if (typeExpr == null) {
        return;
      }

      Node typeNode = typeExpr.getRoot();
      if (typeNode.getToken() != Token.EQUALS) {
        report(typeNode, DEFAULT_PARAM_MUST_BE_MARKED_OPTIONAL);
      }
    }
  }
135427
protected void validateOrderList(SqlSelect select) {
		// ORDER BY is validated in a scope where aliases in the SELECT clause
		// are visible. For example, "SELECT empno AS x FROM emp ORDER BY x"
		// is valid.
		SqlNodeList orderList = select.getOrderList();
		if (orderList == null) {
			return;
		}
		if (!shouldAllowIntermediateOrderBy()) {
			if (!cursorSet.contains(select)) {
				throw newValidationError(select, RESOURCE.invalidOrderByPos());
			}
		}
		final SqlValidatorScope orderScope = getOrderScope(select);
		Objects.requireNonNull(orderScope);

		List<SqlNode> expandList = new ArrayList<>();
		for (SqlNode orderItem : orderList) {
			SqlNode expandedOrderItem = expand(orderItem, orderScope);
			expandList.add(expandedOrderItem);
		}

		SqlNodeList expandedOrderList = new SqlNodeList(
			expandList,
			orderList.getParserPosition());
		select.setOrderBy(expandedOrderList);

		for (SqlNode orderItem : expandedOrderList) {
			validateOrderItem(select, orderItem);
		}
	}
89225
public void validate() {
    if (id == null || id.isEmpty()) {
      throw new IllegalArgumentException("missing or empty id");
    }
    Query.validateId(id);
    
    if (expr == null || expr.isEmpty()) {
      throw new IllegalArgumentException("missing or empty expr");
    }
    
    // parse it just to make sure we're happy and extract the variable names. 
    // Will throw JexlException
    parsed_expression = ExpressionIterator.JEXL_ENGINE.createScript(expr);
    variables = new HashSet<String>();
    for (final List<String> exp_list : 
      ExpressionIterator.JEXL_ENGINE.getVariables(parsed_expression)) {
      for (final String variable : exp_list) {
        variables.add(variable);
      }
    }
    
    // others are optional
    if (join == null) {
      join = Join.Builder().setOperator(SetOperator.UNION).build();
    }
  }
305364
function validateExpression( node ) {
		var args,
			len,
			re,
			i;

		if ( node.callee.name === 'RegExp' ) {
			len = node.arguments.length;
			args = new Array( node.arguments.length );
			for ( i = 0; i < len; i++ ) {
				// NOTE: we only support literals ATM. Otherwise, we may need to walk and implement an entire tree.
				if ( node.arguments[ i ].type !== 'Literal' ) {
					return;
				}
				args[ i ] = node.arguments[ i ].value;
			}
			re = RegExp.apply( null, args );
			if ( !safe( re ) ) {
				context.report( node, 'Unsafe regular expression' );
			}
		}
	}
582334
@Override
  public ValidationResult validateCode(String system, String code, String display) {
    Coding c = new Coding(system, code, display);
    return validateCode(c, null);
  }
411585
private boolean validOperationExpression(Node expr) {
    String name = getCallName(expr);
    Keywords keyword = nameToKeyword(name);
    switch (keyword) {
      case COND:
        return validConditionalExpression(expr);
      case MAPUNION:
        return validMapunionExpression(expr);
      case MAPRECORD:
        return validMaprecordExpression(expr);
      case TYPEOFVAR:
        return validTypeOfVarExpression(expr);
      case INSTANCEOF:
        return validInstanceOfExpression(expr);
      case PRINTTYPE:
        return validPrintTypeExpression(expr);
      case PROPTYPE:
        return validPropTypeExpression(expr);
      default:
        throw new IllegalStateException("Invalid type transformation operation");
    }
  }
697473
public static String validate(String attributeName, String expression) {
        return EVALUATOR.validate(attributeName, expression);
    }
1351539
public BooleanExpression containsIgnoreCase(Expression<String> str) {
        return Expressions.booleanOperation(Ops.STRING_CONTAINS_IC, mixin, str);
    }