1/* 2 * Javassist, a Java-bytecode translator toolkit. 3 * Copyright (C) 2004 Bill Burke. All Rights Reserved. 4 * 5 * The contents of this file are subject to the Mozilla Public License Version 6 * 1.1 (the "License"); you may not use this file except in compliance with 7 * the License. Alternatively, the contents of this file may be used under 8 * the terms of the GNU Lesser General Public License Version 2.1 or later. 9 * 10 * Software distributed under the License is distributed on an "AS IS" basis, 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12 * for the specific language governing rights and limitations under the 13 * License. 14 */ 15 16package javassist.bytecode.annotation; 17 18import javassist.ClassPool; 19import javassist.bytecode.ConstPool; 20import java.io.IOException; 21import java.lang.reflect.Method; 22 23/** 24 * Double floating-point number constant value. 25 * 26 * @author <a href="mailto:bill@jboss.org">Bill Burke</a> 27 * @author Shigeru Chiba 28 * @version $Revision: 1.7 $ 29 */ 30public class DoubleMemberValue extends MemberValue { 31 int valueIndex; 32 33 /** 34 * Constructs a double constant value. The initial value is specified 35 * by the constant pool entry at the given index. 36 * 37 * @param index the index of a CONSTANT_Double_info structure. 38 */ 39 public DoubleMemberValue(int index, ConstPool cp) { 40 super('D', cp); 41 this.valueIndex = index; 42 } 43 44 /** 45 * Constructs a double constant value. 46 * 47 * @param d the initial value. 48 */ 49 public DoubleMemberValue(double d, ConstPool cp) { 50 super('D', cp); 51 setValue(d); 52 } 53 54 /** 55 * Constructs a double constant value. The initial value is 0.0. 56 */ 57 public DoubleMemberValue(ConstPool cp) { 58 super('D', cp); 59 setValue(0.0); 60 } 61 62 Object getValue(ClassLoader cl, ClassPool cp, Method m) { 63 return new Double(getValue()); 64 } 65 66 Class getType(ClassLoader cl) { 67 return double.class; 68 } 69 70 /** 71 * Obtains the value of the member. 72 */ 73 public double getValue() { 74 return cp.getDoubleInfo(valueIndex); 75 } 76 77 /** 78 * Sets the value of the member. 79 */ 80 public void setValue(double newValue) { 81 valueIndex = cp.addDoubleInfo(newValue); 82 } 83 84 /** 85 * Obtains the string representation of this object. 86 */ 87 public String toString() { 88 return Double.toString(getValue()); 89 } 90 91 /** 92 * Writes the value. 93 */ 94 public void write(AnnotationsWriter writer) throws IOException { 95 writer.constValueIndex(getValue()); 96 } 97 98 /** 99 * Accepts a visitor. 100 */ 101 public void accept(MemberValueVisitor visitor) { 102 visitor.visitDoubleMemberValue(this); 103 } 104} 105