Package com.strobel.expressions

Examples of com.strobel.expressions.Expression


        delegate.run();
    }

    @Test
    public void testForEachWithArray() throws Exception {
        final Expression out = field(null, Type.of(System.class).getField("out"));
        final ParameterExpression item = variable(Types.String, "item");

        final ConstantExpression items = constant(
            new String[]{"one", "two", "three", "four", "five"}
        );
View Full Code Here


        delegate.run();
    }

    @Test
    public void testForEachWithIterable() throws Exception {
        final Expression out = field(null, Type.of(System.class).getField("out"));
        final ParameterExpression item = variable(Types.String, "item");

        final ConstantExpression items = constant(
            Arrays.asList("one", "two", "three", "four", "five"),
            Types.Iterable.makeGenericType(Types.String)
View Full Code Here

        delegate.run();
    }

    @Test
    public void testForLoop() throws Exception {
        final Expression out = field(null, Type.of(System.class).getField("out"));
        final ParameterExpression base = variable(PrimitiveTypes.Integer, "base");
        final ParameterExpression power = variable(PrimitiveTypes.Integer, "power");
        final ParameterExpression accumulator = variable(PrimitiveTypes.Integer, "accumulator");
        final ParameterExpression variable = variable(PrimitiveTypes.Integer, "i");
View Full Code Here

        assertEquals("something else", delegate.apply("6"));
    }

    @Test
    public void testTryCatchFinally() throws Exception {
        final Expression out = field(null, Type.of(System.class).getField("out"));
        final ParameterExpression tempException = variable(Types.RuntimeException, "$exception");

        final LambdaExpression<Runnable> lambda = lambda(
            Type.of(Runnable.class),
            block(
View Full Code Here

    }

    @Test
    public void testTryFinally() throws Exception {
        final MutableInteger counter = new MutableInteger(0);
        final Expression counterConstant = constant(counter);
        final ParameterExpression shouldThrow = parameter(PrimitiveTypes.Boolean);

        final LambdaExpression<ShouldThrowDelegate> lambda = lambda(
            Type.of(ShouldThrowDelegate.class),
            tryFinally(
View Full Code Here

        assertEquals(1, counter.getValue());
    }

    @Test
    public void testTryNestedCatchFinally() throws Exception {
        final Expression out = field(null, Type.of(System.class).getField("out"));
        final ParameterExpression tempException = variable(Types.RuntimeException, "$exception");

        final LambdaExpression<Runnable> lambda = lambda(
            Type.of(Runnable.class),
            block(
View Full Code Here

        assertTrue(delegate.test());
    }

    @Test
    public void testCompileToMethod() throws Exception {
        final Expression out = field(null, Type.of(System.class).getField("out"));

        final TypeBuilder<Runnable> typeBuilder = new TypeBuilder<>(
            "TestCompileToMethod",
            Modifier.PUBLIC | Modifier.FINAL,
            Types.Object,
            Type.list(Type.of(Runnable.class))
        );

        final MethodBuilder powerMethod = typeBuilder.defineMethod(
            "power",
            Modifier.PUBLIC | Modifier.FINAL,
            PrimitiveTypes.Integer,
            Type.list(PrimitiveTypes.Integer, PrimitiveTypes.Integer)
        );

        final MethodBuilder runMethod = typeBuilder.defineMethod(
            "run",
            Modifier.PUBLIC | Modifier.FINAL,
            PrimitiveTypes.Void
        );

        final Expression self = self(typeBuilder);

        final ParameterExpression base = variable(PrimitiveTypes.Integer, "base");
        final ParameterExpression power = variable(PrimitiveTypes.Integer, "power");
        final ParameterExpression accumulator = variable(PrimitiveTypes.Integer, "accumulator");
        final ParameterExpression variable = variable(PrimitiveTypes.Integer, "i");
View Full Code Here

        instance.run();
    }

    @Test
    public void testCompileToGeneratedMethod() throws Exception {
        final Expression out = field(null, Type.of(System.class).getField("out"));

        final TypeBuilder<Runnable> typeBuilder = new TypeBuilder<>(
            "TestCompileToGeneratedMethod",
            Modifier.PUBLIC | Modifier.FINAL,
            Types.Object,
            Type.list(Type.of(Runnable.class))
        );

        final Expression self = self(typeBuilder);

        final ParameterExpression base = variable(PrimitiveTypes.Integer, "base");
        final ParameterExpression power = variable(PrimitiveTypes.Integer, "power");
        final ParameterExpression accumulator = variable(PrimitiveTypes.Integer, "accumulator");
        final ParameterExpression variable = variable(PrimitiveTypes.Integer, "i");
View Full Code Here

        assertEquals(expectedShRResult, result[6]);
    }

    @Test
    public void testMethodBasedComparisonOperators() throws Throwable {
        Expression zero = constant(new BigInteger("0"));
        Expression one = constant(new BigInteger("1"));

        assertResultTrue(lessThanOrEqual(zero, one));
        assertResultTrue(lessThanOrEqual(one, one));
        assertResultFalse(lessThanOrEqual(one, zero));
View Full Code Here

    }

    @Test
    public void testThreeOrs() throws Throwable {
        final OrCountdown counter = new OrCountdown(3);
        final Expression counterConstant = constant(counter);

        final LambdaExpression<BooleanCallback> callback = lambda(
            Type.of(BooleanCallback.class),
            orElse(
                call(counterConstant, "test"),
View Full Code Here

TOP

Related Classes of com.strobel.expressions.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.