You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DoubleMemberValue.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. package javassist.bytecode.annotation;
  16. import javassist.bytecode.ConstPool;
  17. import java.io.IOException;
  18. /**
  19. * Double floating-point number constant value.
  20. *
  21. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  22. * @author Shigeru Chiba
  23. * @version $Revision: 1.4 $
  24. */
  25. public class DoubleMemberValue extends MemberValue {
  26. int valueIndex;
  27. /**
  28. * Constructs a double constant value. The initial value is specified
  29. * by the constant pool entry at the given index.
  30. *
  31. * @param index the index of a CONSTANT_Double_info structure.
  32. */
  33. public DoubleMemberValue(int index, ConstPool cp) {
  34. super('D', cp);
  35. this.valueIndex = index;
  36. }
  37. /**
  38. * Constructs a double constant value.
  39. *
  40. * @param d the initial value.
  41. */
  42. public DoubleMemberValue(double d, ConstPool cp) {
  43. super('D', cp);
  44. setValue(d);
  45. }
  46. /**
  47. * Constructs a double constant value. The initial value is 0.0.
  48. */
  49. public DoubleMemberValue(ConstPool cp) {
  50. super('D', cp);
  51. setValue(0.0);
  52. }
  53. /**
  54. * Obtains the value of the member.
  55. */
  56. public double getValue() {
  57. return cp.getDoubleInfo(valueIndex);
  58. }
  59. /**
  60. * Sets the value of the member.
  61. */
  62. public void setValue(double newValue) {
  63. valueIndex = cp.addDoubleInfo(newValue);
  64. }
  65. /**
  66. * Obtains the string representation of this object.
  67. */
  68. public String toString() {
  69. return Double.toString(getValue());
  70. }
  71. void write(AnnotationsWriter writer) throws IOException {
  72. writer.constValueIndex(getValue());
  73. }
  74. /**
  75. * Accepts a visitor.
  76. */
  77. public void accept(MemberValueVisitor visitor) {
  78. visitor.visitDoubleMemberValue(this);
  79. }
  80. }