Create a {@link Expression.PositionFactory} for the specified expression.

@param expr
@return {@link PositionFactory}
349872
public static <T> PositionFactory<T> at(String expr) {
        return new PositionFactory<>(Validate.notEmpty(expr, "expr"));
    }
996527
public static Expression position(String expression, String substring) {
        return position(x(expression), substring);
    }
94893
public static ExprFloat toExprFloat(Expression expr) {
	if (expr instanceof ExprFloat) return (ExprFloat) expr;
	if (expr instanceof Literal) {
	    Double dbl = ((Literal) expr).getDouble(null);
	    if (dbl != null) return expr.getFactory().createLitFloat((float) dbl.doubleValue(), expr.getStart(), expr.getEnd());
	}
	return new CastFloat(expr);
    }
847409
public static <T> JDOQuery<T> select(Expression<T> expr) {
        return new JDOQuery<Void>().select(expr);
    }
1011667
public static <T extends Enum<T>> EnumExpression<T> asEnum(Expression<T> expr) {
        Expression<T> underlyingMixin = ExpressionUtils.extract(expr);
        if (underlyingMixin instanceof PathImpl) {
            return new EnumPath<T>((PathImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof OperationImpl) {
            return new EnumOperation<T>((OperationImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof TemplateExpressionImpl) {
            return new EnumTemplate<T>((TemplateExpressionImpl<T>) underlyingMixin);
        } else {
            return new EnumExpression<T>(underlyingMixin) {

                private static final long serialVersionUID = 949681836002045152L;

                @Override
                public <R, C> R accept(Visitor<R, C> v, C context) {
                    return this.mixin.accept(v, context);
                }

            };
        }

    }
557158
public Tree build(String expression) throws TreeBuilderException {
		try {
			return createParser(expression).tree();
		} catch (ScanException e) {
			throw new TreeBuilderException(expression, e.position, e.encountered, e.expected, e.getMessage());
		} catch (ParseException e) {
			throw new TreeBuilderException(expression, e.position, e.encountered, e.expected, e.getMessage());
		}
	}
48155
public static <T extends Number & Comparable<?>> NumberExpression<T> asNumber(Expression<T> expr) {
        Expression<T> underlyingMixin = ExpressionUtils.extract(expr);
        if (underlyingMixin instanceof PathImpl) {
            return new NumberPath<T>((PathImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof OperationImpl) {
            return new NumberOperation<T>((OperationImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof TemplateExpressionImpl) {
            return new NumberTemplate<T>((TemplateExpressionImpl<T>) underlyingMixin);
        } else {
            return new NumberExpression<T>(underlyingMixin) {

                private static final long serialVersionUID = -8712299418891960222L;

                @Override
                public <R, C> R accept(Visitor<R, C> v, C context) {
                    return this.mixin.accept(v, context);
                }

            };
        }
    }
1296127
public static MethodExpression createMethodExpression(String p_expression, Class<?> returnType,
			Class<?>... parameterTypes) {
		FacesContext context = FacesContext.getCurrentInstance();
		ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
		ELContext elContext = context.getELContext();

		MethodExpression mex = expressionFactory.createMethodExpression(elContext, p_expression, returnType,
				parameterTypes);
		return mex;
	}
1081635
public static List<String> parse(String expr) {
        
        List<String> expressions = new ArrayList<>();
        
        int parenthesis = 0; // '(' and ')'
        int brackets = 0; // '{' and '}'
        int brackets2 = 0; // '[' and ']'

        String[] lines = expr.split("\n");
        StringBuilder sb = new StringBuilder();
        for(String line : lines) {
            line = line.trim();
            if(line.startsWith("#")) {
                // Ignore commented lines
            } else {
                char currentChar=0;
                for (int i = 0; i < line.length(); i++) {
                    currentChar = line.charAt(i);
                    if (currentChar == '#') {// Ignore rest of line
                        line = line.substring(0,i);
                        break; 
                    } else if (currentChar == '(') {
                        parenthesis++;
                    } else if (currentChar == ')') {
                        parenthesis--;
                    } else if (currentChar == '{') {
                        brackets++;
                    } else if (currentChar == '}') {
                        brackets--;
                    } else if (currentChar == '[') {
                        brackets2++;
                    } else if (currentChar == ']') {
                        brackets2--;
                    } else if (parenthesis == 0 && brackets == 0 && brackets2 == 0) {
                        if(currentChar == ';') {
                            String firstLine = line.substring(0, i+1);
                            sb.append(firstLine);                            
                            expressions.add(sb.toString());
                            sb = new StringBuilder();
                                                        
                            String remainder = line.substring(i+1);
                            line = remainder.trim()+"\n";
                            i=0;
                        }
                    }
                }
                if(line.trim().length()>0) {
                    sb.append(line);
                    if(parenthesis == 0 && brackets == 0 && brackets2 == 0) {
                        expressions.add(sb.toString());
                        sb = new StringBuilder();
                    } else {
                        if (currentChar!=',' && currentChar!='+' && currentChar!='-' && currentChar!='*' &&currentChar!='/' &&currentChar!='=')
                        sb.append(";\n");
                    }
                }
            }
        }
        
        return expressions;
    }
933304
@Override
    public Q addFlag(Position position, String prefix, Expression<?> expr) {
        Expression<?> flag = Expressions.template(expr.getType(), prefix + "{0}", expr);
        return queryMixin.addFlag(new QueryFlag(position, flag));
    }
562958
public static <T extends Comparable<?>> ComparableExpression<T> asComparable(Expression<T> expr) {
        Expression<T> underlyingMixin = ExpressionUtils.extract(expr);
        if (underlyingMixin instanceof PathImpl) {
            return new ComparablePath<T>((PathImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof OperationImpl) {
            return new ComparableOperation<T>((OperationImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof TemplateExpressionImpl) {
            return new ComparableTemplate<T>((TemplateExpressionImpl<T>) underlyingMixin);
        } else {
            return new ComparableExpression<T>(underlyingMixin) {

                private static final long serialVersionUID = 389920618099394430L;

                @Override
                public <R, C> R accept(Visitor<R, C> v, C context) {
                    return this.mixin.accept(v, context);
                }

            };
        }

    }
1134921
public static ExprDouble toExprDouble(Expression expr) {
	if (expr instanceof ExprDouble) return (ExprDouble) expr;
	if (expr instanceof Literal) {
	    Double dbl = ((Literal) expr).getDouble(null);
	    if (dbl != null) return expr.getFactory().createLitDouble(dbl.doubleValue(), expr.getStart(), expr.getEnd());
	}
	return new CastDouble(expr);
    }
89088
@SuppressWarnings("unchecked")
    public static <T> Expression<T> extract(Expression<T> expr) {
        if (expr != null) {
            final Class<?> clazz = expr.getClass();
            if (clazz == PathImpl.class || clazz == PredicateOperation.class || clazz == ConstantImpl.class) {
                return expr;
            } else {
                return (Expression<T>) expr.accept(ExtractorVisitor.DEFAULT, null);
            }
        } else {
            return null;
        }
    }
219543
public static Expression regexpPosition(Expression expression, String pattern) {
        return x("REGEXP_POSITION(" + expression.toString() + ", \"" + pattern + "\")");
    }
1137840
public static ParsedScheduleExpression parse(ScheduleExpression expr)
    {
        ParsedScheduleExpression parsedExpr = new ParsedScheduleExpression(expr);
        parse(parsedExpr);
        return parsedExpr;
    }
1203672
public static Expression position(Expression expression, String substring) {
        return x("POSITION(" + expression.toString() + ", \"" + substring + "\")");
    }
439718
static ExpressionFactory getExpressionFactory() {

        ClassLoader tccl;
        if (System.getSecurityManager() != null) {
            tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
                @Override
                public ClassLoader run() {
                    return Thread.currentThread().getContextClassLoader();
                }
            });
        } else {
            tccl = Thread.currentThread().getContextClassLoader();
        }

        CacheValue cacheValue = null;
        ExpressionFactory factory = null;

        if (tccl == null) {
            cacheValue = nullTcclFactory;
        } else {
            CacheKey key = new CacheKey(tccl);
            cacheValue = factoryCache.get(key);
            if (cacheValue == null) {
                CacheValue newCacheValue = new CacheValue();
                cacheValue = factoryCache.putIfAbsent(key, newCacheValue);
                if (cacheValue == null) {
                    cacheValue = newCacheValue;
                }
            }
        }

        final Lock readLock = cacheValue.getLock().readLock();
        readLock.lock();
        try {
            factory = cacheValue.getExpressionFactory();
        } finally {
            readLock.unlock();
        }

        if (factory == null) {
            final Lock writeLock = cacheValue.getLock().writeLock();
            writeLock.lock();
            try {
                factory = cacheValue.getExpressionFactory();
                if (factory == null) {
                    factory = ExpressionFactory.newInstance();
                    cacheValue.setExpressionFactory(factory);
                }
            } finally {
                writeLock.unlock();
            }
        }

        return factory;
    }