001    package railo.transformer.bytecode.literal;
002    
003    import org.objectweb.asm.Type;
004    import org.objectweb.asm.commons.GeneratorAdapter;
005    
006    import railo.runtime.op.Caster;
007    import railo.transformer.bytecode.BytecodeContext;
008    import railo.transformer.bytecode.Literal;
009    import railo.transformer.bytecode.expression.Expression;
010    import railo.transformer.bytecode.expression.ExpressionBase;
011    import railo.transformer.bytecode.util.Methods;
012    import railo.transformer.bytecode.util.Types;
013    
014    /**
015     * Literal Double Value
016     */
017    public final class LitLong extends ExpressionBase implements Literal {
018        
019        private long l;
020    
021            public static Expression toExpr(long l, int line) {
022                    return new LitLong(l,line);
023            }
024        
025        /**
026         * constructor of the class
027         * @param d
028         * @param line 
029         */
030            public LitLong(long l, int line) {
031            super(line);        
032            this.l=l;
033        }
034    
035            /**
036         * @return return value as int
037         */ 
038        public long getLongValue() {
039            return l;
040        }
041        
042        /**
043         * @return return value as Double Object
044         */
045        public Long getLong() {
046            return new Long(l);
047        }
048        
049        /**
050         * @see railo.transformer.bytecode.Literal#getString()
051         */
052        public String getString() {
053            return Caster.toString(l);
054        }
055        
056        /**
057         * @return return value as a Boolean Object
058         */
059        public Boolean getBoolean() {
060            return Caster.toBoolean(l);
061        }
062        
063        /**
064         * @return return value as a boolean value
065         */
066        public boolean getBooleanValue() {
067            return Caster.toBooleanValue(l);
068        }
069    
070        /**
071         * @see railo.transformer.bytecode.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int)
072         */
073        public Type _writeOut(BytecodeContext bc, int mode) {
074            GeneratorAdapter adapter = bc.getAdapter();
075            adapter.push(l);
076            if(mode==MODE_REF) {
077                adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_LONG_FROM_LONG_VALUE);
078                return Types.LONG;
079            }
080            return Types.LONG_VALUE;
081        }
082    
083        /**
084         * @see railo.transformer.bytecode.Literal#getDouble(java.lang.Double)
085         */
086        public Double getDouble(Double defaultValue) {
087            return getDouble();
088        }
089    
090        private Double getDouble() {
091                    return new Double(l);
092            }
093    
094            /**
095         * @see railo.transformer.bytecode.Literal#getBoolean(java.lang.Boolean)
096         */
097        public Boolean getBoolean(Boolean defaultValue) {
098            return getBoolean();
099        }
100    }