Package org.auraframework.expression

Examples of org.auraframework.expression.Expression


    public ExpressionTest(String name) {
        super(name);
    }

    public void testNumberExpression() throws Exception {
        Expression e = new FunctionCallImpl(ADD, ImmutableList.<Expression> of(i314, i235325), l);
        Object o = e.evaluate(values);
        assertEquals(314 + 235325, o);

        // (i314 + i235325) - (i314 + i314)
        e = new FunctionCallImpl(SUBTRACT, ImmutableList.<Expression> of(e,
                new FunctionCallImpl(ADD, ImmutableList.<Expression> of(i314, i314), l)), l);
        o = e.evaluate(values);
        assertEquals((314.0 + 235325) - (314 + 314), o);

        e = new FunctionCallImpl(SUBTRACT, ImmutableList.<Expression> of(e, new LiteralImpl(new BigDecimal(17), l)), l);
        o = e.evaluate(values);
        assertEquals(((314.0 + 235325) - (314 + 314)) - 17, o);
    }
View Full Code Here


        o = e.evaluate(values);
        assertEquals(((314.0 + 235325) - (314 + 314)) - 17, o);
    }

    public void testBooleanComplex() throws Exception {
        Expression e;
        Object o;

        // true && (false || !true)
        e = new FunctionCallImpl(AND, ImmutableList.<Expression> of(
                bTrue,
                new FunctionCallImpl(OR, ImmutableList.<Expression> of(new LiteralImpl(false, l), new FunctionCallImpl(
                        NOT, ImmutableList.<Expression> of(new LiteralImpl(true, l)), l)), l)), l);
        o = e.evaluate(values);
        assertFalse("Expected boolean expression to be false", o);
    }
View Full Code Here

        verifyEvaluateResult("5 +\r\n1\r\n!=\r\n'null'", ExpressionType.FUNCTION, null, true);
    }

    private void verifyEvaluateResult(String expression, ExpressionType type, ValueProvider vp, Object result)
            throws Exception {
        Expression e = buildExpression(expression);
        assertEquals("Unexpected expression type when parsing <" + expression + ">", type, e.getExpressionType());
        assertEquals("Unexpected evaluation of <" + expression + ">", result, e.evaluate(vp));
    }
View Full Code Here

          Object result;
            String raw = getRawValue();
            Set<PropertyReference> propRefs = null;
            if (type == TokenType.EXPRESSION) {
              propRefs = Sets.newHashSetWithExpectedSize(2);
                Expression e = AuraImpl.getExpressionAdapter().buildExpression(unwrap(raw), location);
                e.gatherPropertyReferences(propRefs);
                result = e;
            } else {
                // Let's see if we can find any "naked" $Label.section.name references in the plain text
                Matcher matcher = LABEL_GVP_PATTERN.matcher(raw);
                while (matcher.find()) {
View Full Code Here

    @Override
    public List<String> getAdditionalAppCacheURLs() throws QuickFixException {
        List<String> urls = Collections.emptyList();

        if (additionalAppCacheURLs != null) {
            Expression expression = AuraImpl.getExpressionAdapter().buildExpression(
                    TextTokenizer.unwrap(additionalAppCacheURLs), null);
            if (!(expression instanceof PropertyReference)) {
                throw new AuraRuntimeException(
                        "Value of 'additionalAppCacheURLs' attribute must be a reference to a server Action");
            }
View Full Code Here

        builder.setDescription(getAttributeValue(RootTagHandler.ATTRIBUTE_DESCRIPTION));

        String action = getAttributeValue(ATTRIBUTE_ACTION);
        if (action != null) {
            Expression e = AuraImpl.getExpressionAdapter().buildExpression(
                    TextTokenizer.unwrap(getAttributeValue(ATTRIBUTE_ACTION)), getLocation());
            if (!(e instanceof PropertyReference)) {
                error("value of 'action' attribute must be a reference to an Action");
            }
            builder.setAction((PropertyReference) e);
        }
        String value = getAttributeValue(ATTRIBUTE_VALUE);
        if (value != null) {
            Expression valueExpression = AuraImpl.getExpressionAdapter().buildExpression(TextTokenizer.unwrap(value),
                    getLocation());
            if (!(valueExpression instanceof PropertyReference)) {
                error("value of 'value' attribute must be a reference to a Value");
            }
            builder.setValue((PropertyReference) valueExpression);
View Full Code Here

    /**
     * Expressions are not parsed in parseValue.
     */
    public void testParseValueExpression() throws Exception {
        Expression expr = Mockito.mock(Expression.class);
        assertParsedValue(expr, "long", expr);
        Mockito.verifyNoMoreInteractions(expr);
    }
View Full Code Here

    /**
     * Function precedence respects Java conventions.
     */
    public void testPrecedence() throws Exception {
        double result = 3.5 * 280 + 53145.3145 / -2.61;
        Expression e = buildExpression("3.5 * 280 + 53145.3145 / -2.61");
        assertEquals("Unexpected expression evaluation", result, e.evaluate(null));

        result = (536 + .346) * 1.56 / 634 + 11 % 5;
        e = buildExpression("(536 + .346) * 1.56 / 634 + 11 % 5");
        assertEquals("Unexpected expression evaluation", result, e.evaluate(null));

        e = buildExpression("1 - -5");
        // this is an integer
        assertEquals("Unexpected expression evaluation", 6.0, e.evaluate(null));

        e = buildExpression("true ? true : false ? 16 : 21");
        assertEquals("Unexpected expression evaluation", true, e.evaluate(null));
    }
View Full Code Here

    /**
     * Boolean precedence respects Java conventions.
     */
    public void testBoolPrecedence() throws Exception {
        boolean compare = 324.4326 < 259 / 134.6 + 2356;
        Expression e = buildExpression("324.4326 < 259 / 134.6 + 2356");
        assertEquals("Boolean precedence not evaluated correctly", compare, e.evaluate(null));

        compare = 324.4326 < 259 / (134.6 + 2356);
        e = buildExpression("324.4326 < 259 / (134.6 + 2356)");
        assertEquals("Boolean precedence not evaluated correctly", compare, e.evaluate(null));

        e = buildExpression("324.4326 == 259 / (134.6 + 2356) && (false || true)");
        assertFalse("Boolean precedence not evaluated correctly", e.evaluate(null));

        e = buildExpression("346 > 346 ? 6541 / 21 - 77 : 235.66");
        assertEquals("Boolean precedence not evaluated correctly", 235.66, e.evaluate(null));

        e = buildExpression("false == false ? 16 : 21");
        assertEquals("Boolean precedence not evaluated correctly", 16., e.evaluate(null));

        e = buildExpression("false && false ? 16 : 21");
        assertEquals("Boolean precedence not evaluated correctly", 21., e.evaluate(null));

        e = buildExpression("true ? 16 : 21 < 20");
        assertEquals("Boolean precedence not evaluated correctly", 16., e.evaluate(null));

        e = buildExpression("! true && false");
        assertEquals("Boolean precedence not evaluated correctly", false, e.evaluate(null));
    }
View Full Code Here

    /**
     * Alternate relational operators can be parsed.
     */
    public void testAlternateNames() throws Exception {
        Expression e = buildExpression("55 eq 55");
        assertTrue("Unexpected expression evaluation using alternate relational operators", e.evaluate(null));
        e = buildExpression("55 ne 55");
        assertFalse("Unexpected expression evaluation using alternate relational operators", e.evaluate(null));
        e = buildExpression("55 ge 55");
        assertTrue("Unexpected expression evaluation using alternate relational operators", e.evaluate(null));
        e = buildExpression("55 le 55");
        assertTrue("Unexpected expression evaluation using alternate relational operators", e.evaluate(null));
        e = buildExpression("55 lt 55");
        assertFalse("Unexpected expression evaluation using alternate relational operators", e.evaluate(null));
        e = buildExpression("55 gt 55");
        assertFalse("Unexpected expression evaluation using alternate relational operators", e.evaluate(null));
    }
View Full Code Here

TOP

Related Classes of org.auraframework.expression.Expression

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.