Java tutorial
/** * * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * **/ package lucee.transformer.bytecode.literal; import lucee.runtime.op.Caster; import lucee.transformer.bytecode.BytecodeContext; import lucee.transformer.bytecode.Literal; import lucee.transformer.bytecode.Position; import lucee.transformer.bytecode.expression.ExprBoolean; import lucee.transformer.bytecode.expression.ExpressionBase; import lucee.transformer.bytecode.util.Types; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.commons.GeneratorAdapter; /** * Literal Boolean */ public final class LitBoolean extends ExpressionBase implements Literal, ExprBoolean { /** * @see java.lang.Object#toString() */ @Override public String toString() { return b + ""; } private boolean b; public static final LitBoolean TRUE = new LitBoolean(true, null, null); public static final LitBoolean FALSE = new LitBoolean(false, null, null); public static ExprBoolean toExprBoolean(boolean b, Position start, Position end) { return new LitBoolean(b, start, end); } public static ExprBoolean toExprBoolean(boolean b) { return new LitBoolean(b, null, null); } /** * constructor of the class * @param b * @param line */ public LitBoolean(boolean b, Position start, Position end) { super(start, end); this.b = b; } /** * @return return value as double value */ public double getDoubleValue() { return Caster.toDoubleValue(b); } /** * @return return value as Double Object */ public Double getDouble() { return Caster.toDouble(b); } /** * @see lucee.transformer.bytecode.Literal#getString() */ public String getString() { return Caster.toString(b); } /** * @return return value as a Boolean Object */ public Boolean getBoolean() { return Caster.toBoolean(b); } /** * @return return value as a boolean value */ public boolean getBooleanValue() { return b; } /** * * @see lucee.transformer.bytecode.expression.ExpressionBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) */ public Type _writeOut(BytecodeContext bc, int mode) { GeneratorAdapter adapter = bc.getAdapter(); if (mode == MODE_REF) { adapter.getStatic(Types.BOOLEAN, b ? "TRUE" : "FALSE", Types.BOOLEAN); return Types.BOOLEAN; } adapter.visitInsn(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0); return Types.BOOLEAN_VALUE; } /** * @see lucee.transformer.bytecode.Literal#getDouble(java.lang.Double) */ public Double getDouble(Double defaultValue) { return getDouble(); } /** * @see lucee.transformer.bytecode.Literal#getBoolean(java.lang.Boolean) */ public Boolean getBoolean(Boolean defaultValue) { return getBoolean(); } /* * * @see lucee.transformer.bytecode.expression.Expression#getType() * / public int getType() { return Types._BOOLEAN; }*/ }