Package com.googlecode.aviator.lexer.token

Examples of com.googlecode.aviator.lexer.token.NumberToken


        }
        // load token to stack
        switch (lookhead.getType()) {
        case Number:
            // load numbers
            NumberToken numberToken = (NumberToken) lookhead;
            if (numberToken.getNumber() instanceof Double) {
                mv.visitTypeInsn(NEW, "com/googlecode/aviator/runtime/type/AviatorDouble");
                mv.visitInsn(DUP);
                mv.visitLdcInsn(numberToken.getNumber());
                mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;");
                mv.visitMethodInsn(INVOKESPECIAL, "com/googlecode/aviator/runtime/type/AviatorDouble", "<init>",
                    "(Ljava/lang/Number;)V");
            }
            else {
                mv.visitTypeInsn(NEW, "com/googlecode/aviator/runtime/type/AviatorLong");
                mv.visitInsn(DUP);
                mv.visitLdcInsn(numberToken.getNumber());
                mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
                mv.visitMethodInsn(INVOKESPECIAL, "com/googlecode/aviator/runtime/type/AviatorLong", "<init>",
                    "(Ljava/lang/Number;)V");
            }
            pushOperand(2);
View Full Code Here


    }


    @Test
    public void testOnConstant_Long() throws Exception {
        this.codeGenerator.onConstant(new NumberToken(3L, "3"));
        Expression exp = this.codeGenerator.getResult();
        Object result = exp.execute();
        assertEquals(3L, result);
    }
View Full Code Here

    }


    @Test
    public void testOnConstant_Double() throws Exception {
        this.codeGenerator.onConstant(new NumberToken(3.3D, "3.3"));
        Expression exp = this.codeGenerator.getResult();
        Object result = exp.execute();
        assertEquals(3.3D, result);
    }
View Full Code Here

        doArithOpTest(OperatorType.MOD);
    }


    public void doArithOpTest(OperatorType operatorType) throws Exception {
        NumberToken a = new NumberToken(3L, "3");
        NumberToken b = new NumberToken(3.5d, "3.5");
        Map<String, Object> env = new HashMap<String, Object>();
        env.put("c", 9L);
        codeGenerator.onConstant(new Variable("c", 0));
        codeGenerator.onConstant(a);
        codeGenerator.onConstant(b);
View Full Code Here

    }


    @Test
    public void testOnNeg_Long() throws Exception {
        codeGenerator.onConstant(new NumberToken(3L, "3"));
        codeGenerator.onNeg(null);
        Object result = eval(new HashMap<String, Object>());
        assertEquals(-3L, result);
    }
View Full Code Here

    }


    @Test
    public void testOnNeg_Double() throws Exception {
        codeGenerator.onConstant(new NumberToken(-3.3d, "-3.3"));
        codeGenerator.onNeg(null);
        Object result = eval(new HashMap<String, Object>());
        assertEquals(3.3, result);
    }
View Full Code Here

        doLogicOpTest(OperatorType.LE);
    }


    public void doLogicOpTest(OperatorType operatorType) throws Exception {
        NumberToken a = new NumberToken(3L, "3");
        NumberToken b = new NumberToken(3L, "3");
        Map<String, Object> env = new HashMap<String, Object>();
        env.put("c", 9L);
        switch (operatorType) {
        case EQ:
            codeGenerator.onConstant(a);
View Full Code Here

    @Test
    public void testOnMethod_withTwoArguments() throws Exception {
        codeGenerator.onMethodName(new Variable("string.substring", -1));
        codeGenerator.onConstant(new StringToken("hello", -1));
        codeGenerator.onMethodParameter(null);
        codeGenerator.onConstant(new NumberToken(2L, "2"));
        codeGenerator.onMethodParameter(null);
        codeGenerator.onConstant(new NumberToken(5L, "5"));
        codeGenerator.onMethodParameter(null);
        codeGenerator.onMethodInvoke(null);
        Object result = eval(new HashMap<String, Object>());
        assertEquals("llo", result);
    }
View Full Code Here

                        d = d * 10;
                        nextChar();
                    }
                }
            } while (Character.isDigit(peek) || peek == '.');
            return new NumberToken(value, sb.toString(), startIndex);
        }

        // It is a variable
        if (Character.isJavaIdentifierStart(peek)) {
            int startIndex = iterator.getIndex();
View Full Code Here

        case Nil:
            token = Variable.NIL;
            break;
        case Number:
            final Number value = (Number) operand.getValue(null);
            token = new NumberToken(value, value.toString());
            break;
        case String:
            final String str = (String) operand.getValue(null);
            token = new StringToken(str, -1);
            break;
View Full Code Here

TOP

Related Classes of com.googlecode.aviator.lexer.token.NumberToken

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.