Strips an expression of the leading "${" or "#{" and the trailing "}".

@param expression the expression to strip.
@return the expression without the leading "${" or "#{" and the trailing "}".
962495
public String stripExpression(String expression) {
        if (expression == null) {
            throw new IllegalArgumentException("Cannot strip NULL expression!");
        }
        expression = expression.replaceAll("^\\$\\{", "").replaceAll("\\}$", "");
        expression = expression.replaceAll("^#\\{", "").replaceAll("\\}$", "");
        return expression;
    }
372812
public static boolean isValueReference(String expression)
  {
    if (null != expression)
    {
      int start = expression.indexOf("#{");
      if ((start >= 0) && (expression.indexOf('}', start + 1) >= 0))
      {
          return true;
      }
    }

    return false;
  }
1342363
public static Statement throwExpression(final Expression expression) {
    expression.checkAssignableTo(THROWABLE_TYPE);
    return new Statement() {
      @Override
      protected void doGen(CodeBuilder adapter) {
        expression.gen(adapter);
        adapter.throwException();
      }
    };
  }
851111
@Check
	public void checkBreakKeywordUse(SarlBreakExpression expression) {
		final EObject container = Utils.getFirstContainerForPredicate(expression,
				it -> !(it instanceof XExpression) || it instanceof XAbstractWhileExpression
				|| it instanceof XBasicForLoopExpression || it instanceof XForLoopExpression);
		if (container instanceof XExpression) {
			if (!isIgnored(DISCOURAGED_LOOP_BREAKING_KEYWORD_USE)
					&& container instanceof XBasicForLoopExpression) {
				addIssue(
						MessageFormat.format(Messages.SARLValidator_17, this.grammarAccess.getBreakKeyword()),
						expression,
						null,
						ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
						DISCOURAGED_LOOP_BREAKING_KEYWORD_USE);
			}
		} else {
			error(MessageFormat.format(Messages.SARLValidator_18, this.grammarAccess.getBreakKeyword()),
					expression,
					null,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
					INVALID_USE_OF_LOOP_BREAKING_KEYWORD);
		}
	}
175109
@NonNull
    public static Expression negated(@NonNull Expression expression) {
        if (expression == null) {
            throw new IllegalArgumentException("expression cannot be null.");
        }
        return new CompoundExpression(Arrays.asList(expression), CompoundExpression.OpType.Not);
    }
532329
private static ExpressionTree stripParensAndCasts(ExpressionTree expr) {
    boolean someChange = true;
    while (someChange) {
      someChange = false;
      if (expr.getKind().equals(PARENTHESIZED)) {
        expr = ((ParenthesizedTree) expr).getExpression();
        someChange = true;
      }
      if (expr.getKind().equals(TYPE_CAST)) {
        expr = ((TypeCastTree) expr).getExpression();
        someChange = true;
      }
    }
    return expr;
  }
641981
public static Expression ltrim(Expression expression, String characters) {
        return x("LTRIM(" + expression.toString() + ", \"" + characters + "\")");
    }
1278699
@Nonnull
  public static Value evalExpression(@Nonnull final String expression, @Nonnull final PreprocessorContext context) {
    try {
      final ExpressionTree tree = ExpressionParser.getInstance().parse(expression, context);
      return evalTree(tree, context);
    } catch (IOException unexpected) {
      throw context.makeException("[Expression]Wrong expression format detected [" + expression + ']', unexpected);
    }
  }
1181660
@Pure
	protected XExpression fromString(String expression) {
		if (!Strings.isEmpty(expression)) {
			ResourceSet resourceSet = this.context.eResource().getResourceSet();
			URI uri = computeUnusedUri(resourceSet);
			Resource resource = getResourceFactory().createResource(uri);
			resourceSet.getResources().add(resource);
			try (StringInputStream is = new StringInputStream(generateExpressionCode(expression))) {
				resource.load(is, null);
				SarlScript script = resource.getContents().isEmpty() ? null : (SarlScript) resource.getContents().get(0);
				SarlEvent topElement = (SarlEvent) script.getXtendTypes().get(0);
				SarlField member = (SarlField) topElement.getMembers().get(0);
				return member.getInitialValue();
			} catch (Throwable exception) {
				throw new RuntimeException(exception);
			} finally {
				resourceSet.getResources().remove(resource);
			}
		}
		throw new IllegalArgumentException("not a valid expression");
	}
542591
public static Expression rtrim(String expression, String characters) {
        return rtrim(x(expression), characters);
    }
1222168
public static Query withField(String expression) {
        String[] parts = split(expression);
        if (parts != null) {
            String field = parts[0];
            String operator = parts[1];
            String rfield = parts[2];

            BinOp binOp = BinOp.getOp(operator);
            if (binOp != null) {
                return withField(field, binOp, rfield);
            }
            NaryOp naryOp = NaryOp.getOp(operator);
            if (naryOp != null) {
                return withFieldValues(field, naryOp, rfield);
            }
        }
        throw new IllegalArgumentException("'" + expression + "' is incorrect");
    }
169370
public static String print(Expression expression) {
        return expression.match(new Expression.MatchBlock<String>() {

            @Override
            public String _case(LiteralExpression x) {
                return print(x.literal);
            }

            @Override
            public String _case(VariableExpression x) {
                return x.selector.match(new Optional.MatchBlock<Expression, String>() {
                    @Override
                    public String _case(Some<Expression> x) {
                        return print(x.value) + ".";
                    }

                    @Override
                    public String _case(None<Expression> x) {
                        return "";
                    }
                }) + x.identifier;
            }

            @Override
            public String _case(NestedExpression x) {
                return "( " + print(x.expression) + " )";
            }

            @Override
            public String _case(ClassReference x) {
                return print(x.type) + ".class";
            }

            @Override
            public String _case(TernaryExpression x) {
                return print(x.cond) + " ? " + print(x.trueExpression) + " : " + print (x.falseExpression);
            }

            @Override
            public String _case(BinaryExpression x) {
                return print(x.left) + " " + print(x.op) + " " +  print(x.right);
            }
        });
    }
1204156
public static Set<String> getFreeVariables(Expression2 expression) {
    Set<String> freeVariables = Sets.newHashSet();
    ScopeSet scopes = getScopes(expression);
    for (int i = 0; i < expression.size(); i++) {
      Scope scope = scopes.getScope(i);
      String varName = getFreeVariable(expression, i, scope);
      if (varName != null) {
        freeVariables.add(varName);
      }
    }
    return freeVariables;
  }
504956
public OptionalSyntax where(Expression<?>... expression) {
		for (Expression<?> exp : expression) {
			getMessage().getOptional().add(exp.toString());
			LOG.debug("expression: " + exp);
		}
		QueryMessage mess = getMessage();
		return new OptionalSyntax(mess);
	}
447976
public static Expression ltrim(String expression, String characters) {
        return ltrim(x(expression), characters);
    }
1090338
public static String rewrite(String expression) throws InvalidExpressionException {

        ExpressionTree expTree = parseToTree(expression);

        expTree.reduce();

        return expTree.toString();
    }
1365076
public static String normalize(Object expression) {
        if (expression == null) {
            return null;
        }

        // If it's a number it's not an expression
        if (expression instanceof Number){
            return String.valueOf(expression);
        }

        String replacement;
        String conditionStr = StringUtils.mergeToSingleUnderscore(String.valueOf(expression));
        Matcher matcher = PATTERN.matcher(conditionStr);
        StringBuffer result = new StringBuffer(conditionStr.length());
        while (matcher.find()) {
            if (OPERATORS.containsKey(matcher.group())) {
                replacement = (String) OPERATORS.get(matcher.group());
            } else if (PREDEFINED_VARS.containsKey(matcher.group())) {
                replacement = (String) PREDEFINED_VARS.get(matcher.group());
            } else {
                replacement = matcher.group();
            }
            matcher.appendReplacement(result, replacement);
        }
        matcher.appendTail(result);
        return result.toString();
    }