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 LitInteger extends ExpressionBase implements Literal { 018 019 private int i; 020 021 public static Expression toExpr(int i, int line) { 022 return new LitInteger(i,line); 023 } 024 025 /** 026 * constructor of the class 027 * @param d 028 * @param line 029 */ 030 public LitInteger(int i, int line) { 031 super(line); 032 this.i=i; 033 } 034 035 /** 036 * @return return value as int 037 */ 038 public int geIntValue() { 039 return i; 040 } 041 042 /** 043 * @return return value as Double Object 044 */ 045 public Integer getInteger() { 046 return new Integer(i); 047 } 048 049 /** 050 * @see railo.transformer.bytecode.Literal#getString() 051 */ 052 public String getString() { 053 return Caster.toString(i); 054 } 055 056 /** 057 * @return return value as a Boolean Object 058 */ 059 public Boolean getBoolean() { 060 return Caster.toBoolean(i); 061 } 062 063 /** 064 * @return return value as a boolean value 065 */ 066 public boolean getBooleanValue() { 067 return Caster.toBooleanValue(i); 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(i); 076 if(mode==MODE_REF) { 077 adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_INTEGER_FROM_INT); 078 return Types.INTEGER; 079 } 080 return Types.INT_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(i); 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 }