001: /*
002: * Javassist, a Java-bytecode translator toolkit.
003: * Copyright (C) 2004 Bill Burke. All Rights Reserved.
004: *
005: * The contents of this file are subject to the Mozilla Public License Version
006: * 1.1 (the "License"); you may not use this file except in compliance with
007: * the License. Alternatively, the contents of this file may be used under
008: * the terms of the GNU Lesser General Public License Version 2.1 or later.
009: *
010: * Software distributed under the License is distributed on an "AS IS" basis,
011: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
012: * for the specific language governing rights and limitations under the
013: * License.
014: */
015:
016: package javassist.bytecode.annotation;
017:
018: import javassist.ClassPool;
019: import javassist.bytecode.ConstPool;
020: import java.io.IOException;
021: import java.lang.reflect.Method;
022:
023: /**
024: * Floating-point number constant value.
025: *
026: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
027: * @author Shigeru Chiba
028: * @version $Revision: 1.7 $
029: */
030: public class FloatMemberValue extends MemberValue {
031: int valueIndex;
032:
033: /**
034: * Constructs a float constant value. The initial value is specified
035: * by the constant pool entry at the given index.
036: *
037: * @param index the index of a CONSTANT_Float_info structure.
038: */
039: public FloatMemberValue(int index, ConstPool cp) {
040: super ('F', cp);
041: this .valueIndex = index;
042: }
043:
044: /**
045: * Constructs a float constant value.
046: *
047: * @param f the initial value.
048: */
049: public FloatMemberValue(float f, ConstPool cp) {
050: super ('F', cp);
051: setValue(f);
052: }
053:
054: /**
055: * Constructs a float constant value. The initial value is 0.0.
056: */
057: public FloatMemberValue(ConstPool cp) {
058: super ('F', cp);
059: setValue(0.0F);
060: }
061:
062: Object getValue(ClassLoader cl, ClassPool cp, Method m) {
063: return new Float(getValue());
064: }
065:
066: Class getType(ClassLoader cl) {
067: return float.class;
068: }
069:
070: /**
071: * Obtains the value of the member.
072: */
073: public float getValue() {
074: return cp.getFloatInfo(valueIndex);
075: }
076:
077: /**
078: * Sets the value of the member.
079: */
080: public void setValue(float newValue) {
081: valueIndex = cp.addFloatInfo(newValue);
082: }
083:
084: /**
085: * Obtains the string representation of this object.
086: */
087: public String toString() {
088: return Float.toString(getValue());
089: }
090:
091: /**
092: * Writes the value.
093: */
094: public void write(AnnotationsWriter writer) throws IOException {
095: writer.constValueIndex(getValue());
096: }
097:
098: /**
099: * Accepts a visitor.
100: */
101: public void accept(MemberValueVisitor visitor) {
102: visitor.visitFloatMemberValue(this);
103: }
104: }
|