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: * Double 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 DoubleMemberValue extends MemberValue {
031: int valueIndex;
032:
033: /**
034: * Constructs a double 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_Double_info structure.
038: */
039: public DoubleMemberValue(int index, ConstPool cp) {
040: super ('D', cp);
041: this .valueIndex = index;
042: }
043:
044: /**
045: * Constructs a double constant value.
046: *
047: * @param d the initial value.
048: */
049: public DoubleMemberValue(double d, ConstPool cp) {
050: super ('D', cp);
051: setValue(d);
052: }
053:
054: /**
055: * Constructs a double constant value. The initial value is 0.0.
056: */
057: public DoubleMemberValue(ConstPool cp) {
058: super ('D', cp);
059: setValue(0.0);
060: }
061:
062: Object getValue(ClassLoader cl, ClassPool cp, Method m) {
063: return new Double(getValue());
064: }
065:
066: Class getType(ClassLoader cl) {
067: return double.class;
068: }
069:
070: /**
071: * Obtains the value of the member.
072: */
073: public double getValue() {
074: return cp.getDoubleInfo(valueIndex);
075: }
076:
077: /**
078: * Sets the value of the member.
079: */
080: public void setValue(double newValue) {
081: valueIndex = cp.addDoubleInfo(newValue);
082: }
083:
084: /**
085: * Obtains the string representation of this object.
086: */
087: public String toString() {
088: return Double.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.visitDoubleMemberValue(this);
103: }
104: }
|