Package org.apache.commons.jexl2

Examples of org.apache.commons.jexl2.JexlTestCase


        return Boolean.TRUE;
    }

    /** {@inheritDoc} */
    public Object visit(ASTUnaryMinusNode node, Object data) {
        JexlNode valNode = node.jjtGetChild(0);
        Object val = valNode.jjtAccept(this, data);
        if (val instanceof Byte) {
            byte valueAsByte = ((Byte) val).byteValue();
            return Byte.valueOf((byte) -valueAsByte);
        } else if (val instanceof Short) {
            short valueAsShort = ((Short) val).shortValue();
View Full Code Here


        }
        // synthetize expr using register
        expr = "#0" + (expr.charAt(0) == '[' ? "" : ".") + expr + ";";
        try {
            parser.ALLOW_REGISTERS = true;
            JexlNode tree = parse(expr, null);
            JexlNode node = tree.jjtGetChild(0);
            Interpreter interpreter = createInterpreter(context);
            // set register
            interpreter.setRegisters(bean);
            return node.jjtAccept(interpreter, null);
        } catch (JexlException xjexl) {
            if (silent) {
                logger.warn(xjexl.getMessage(), xjexl.getCause());
                return null;
            }
View Full Code Here

        }
        // synthetize expr using registers
        expr = "#0" + (expr.charAt(0) == '[' ? "" : ".") + expr + "=" + "#1" + ";";
        try {
            parser.ALLOW_REGISTERS = true;
            JexlNode tree = parse(expr, null);
            JexlNode node = tree.jjtGetChild(0);
            Interpreter interpreter = createInterpreter(context);
            // set the registers
            interpreter.setRegisters(bean, value);
            node.jjtAccept(interpreter, null);
        } catch (JexlException xjexl) {
            if (silent) {
                logger.warn(xjexl.getMessage(), xjexl.getCause());
                return;
            }
View Full Code Here

        Debugger dbg = new Debugger();
        // iterate over all expression in cache
        Iterator<Map.Entry<String,ASTJexlScript>> inodes = jexl.cache.entrySet().iterator();
        while (inodes.hasNext()) {
            Map.Entry<String,ASTJexlScript> entry = inodes.next();
            JexlNode node = entry.getValue();
            // recreate expr string from AST
            dbg.debug(node);
            String expressiondbg = dbg.data();
            // recreate expr from string
            Expression exprdbg = jdbg.createExpression(expressiondbg);
            // make arg cause become the root cause
            JexlNode root = ((ExpressionImpl) exprdbg).script;
            while (root.jjtGetParent() != null) {
                root = root.jjtGetParent();
            }
            // test equality
            String reason = JexlTestCase.checkEquals(root, node);
            if (reason != null) {
                throw new RuntimeException("debugger equal failed: "
View Full Code Here

    /** {@inheritDoc} */
    public Object visit(ASTWhileStatement node, Object data) {
        Object result = null;
        /* first objectNode is the expression */
        Node expressionNode = node.jjtGetChild(0);
        while (arithmetic.toBoolean(expressionNode.jjtAccept(this, data))) {
            // execute statement
            result = node.jjtGetChild(1).jjtAccept(this, data);
        }

        return result;
View Full Code Here

    {
        JexlContext jc = new MapContext();
        jc.set("aString", "Hello");
        Foo foo = new Foo();
        jc.set("foo", foo);
        Parser parser = new Parser(new StringReader(";"));
        parser.parse(new StringReader("aString = 'World';"), null);
       
        assertExpression(jc, "hello = 'world'", "world");
        assertEquals("hello variable not changed", "world", jc.get("hello"));
        assertExpression(jc, "result = 1 + 1", new Integer(2));
        assertEquals("result variable not changed", new Integer(2), jc.get("result"));
View Full Code Here

     * @throws InvalidSearchConditionException in case of errors retrieving identifiers
     */
    private Set<String> getWhereClause(final String expression, final String value, final AttributableUtil attrUtil)
            throws InvalidSearchConditionException {

        final Parser parser = new Parser(new StringReader(expression));

        // Schema names
        final List<String> identifiers = new ArrayList<String>();

        // Literals
        final List<String> literals = new ArrayList<String>();

        // Get schema names and literals
        Token token;
        while ((token = parser.getNextToken()) != null && StringUtils.hasText(token.toString())) {
            if (token.kind == ParserConstants.STRING_LITERAL) {
                literals.add(token.toString().substring(1, token.toString().length() - 1));
            }

            if (token.kind == ParserConstants.IDENTIFIER) {
View Full Code Here

     * @return where clauses to use to build the query.
     * @throws InvalidSearchConditionException in case of errors retrieving identifiers.
     */
    private Set<String> getWhereClause(final String expression, final String value)
            throws InvalidSearchConditionException {
        final Parser parser = new Parser(new StringReader(expression));

        // Schema names
        final List<String> identifiers = new ArrayList<String>();

        // Literals
        final List<String> literals = new ArrayList<String>();

        // Get schema names and literals
        Token token;
        while ((token = parser.getNextToken()) != null && StringUtils.isNotBlank(token.toString())) {
            if (token.kind == ParserConstants.STRING_LITERAL) {
                literals.add(token.toString().substring(1, token.toString().length() - 1));
            }

            if (token.kind == ParserConstants.IDENTIFIER) {
View Full Code Here

        // Literals
        final List<String> literals = new ArrayList<String>();

        // Get schema names and literals
        Token token;
        while ((token = parser.getNextToken()) != null && StringUtils.hasText(token.toString())) {
            if (token.kind == ParserConstants.STRING_LITERAL) {
                literals.add(token.toString().substring(1, token.toString().length() - 1));
            }

            if (token.kind == ParserConstants.IDENTIFIER) {
                identifiers.add(token.toString());
            }
        }

        // Sort literals in order to process later literals included into others
        Collections.sort(literals, new Comparator<String>() {
View Full Code Here

        // Literals
        final List<String> literals = new ArrayList<String>();

        // Get schema names and literals
        Token token;
        while ((token = parser.getNextToken()) != null && StringUtils.isNotBlank(token.toString())) {
            if (token.kind == ParserConstants.STRING_LITERAL) {
                literals.add(token.toString().substring(1, token.toString().length() - 1));
            }

            if (token.kind == ParserConstants.IDENTIFIER) {
                identifiers.add(token.toString());
            }
        }

        // Sort literals in order to process later literals included into others
        Collections.sort(literals, new Comparator<String>() {
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl2.JexlTestCase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.