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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * or the Apache License Version 2.0.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. */
  16. package javassist.bytecode.annotation;
  17. import javassist.ClassPool;
  18. import javassist.bytecode.ConstPool;
  19. import java.io.IOException;
  20. import java.lang.reflect.Method;
  21. /**
  22. * Double floating-point number constant value.
  23. *
  24. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  25. * @author Shigeru Chiba
  26. * @version $Revision: 1.7 $
  27. */
  28. public class DoubleMemberValue extends MemberValue {
  29. int valueIndex;
  30. /**
  31. * Constructs a double constant value. The initial value is specified
  32. * by the constant pool entry at the given index.
  33. *
  34. * @param index the index of a CONSTANT_Double_info structure.
  35. */
  36. public DoubleMemberValue(int index, ConstPool cp) {
  37. super('D', cp);
  38. this.valueIndex = index;
  39. }
  40. /**
  41. * Constructs a double constant value.
  42. *
  43. * @param d the initial value.
  44. */
  45. public DoubleMemberValue(double d, ConstPool cp) {
  46. super('D', cp);
  47. setValue(d);
  48. }
  49. /**
  50. * Constructs a double constant value. The initial value is 0.0.
  51. */
  52. public DoubleMemberValue(ConstPool cp) {
  53. super('D', cp);
  54. setValue(0.0);
  55. }
  56. Object getValue(ClassLoader cl, ClassPool cp, Method m) {
  57. return new Double(getValue());
  58. }
  59. Class getType(ClassLoader cl) {
  60. return double.class;
  61. }
  62. /**
  63. * Obtains the value of the member.
  64. */
  65. public double getValue() {
  66. return cp.getDoubleInfo(valueIndex);
  67. }
  68. /**
  69. * Sets the value of the member.
  70. */
  71. public void setValue(double newValue) {
  72. valueIndex = cp.addDoubleInfo(newValue);
  73. }
  74. /**
  75. * Obtains the string representation of this object.
  76. */
  77. public String toString() {
  78. return Double.toString(getValue());
  79. }
  80. /**
  81. * Writes the value.
  82. */
  83. public void write(AnnotationsWriter writer) throws IOException {
  84. writer.constValueIndex(getValue());
  85. }
  86. /**
  87. * Accepts a visitor.
  88. */
  89. public void accept(MemberValueVisitor visitor) {
  90. visitor.visitDoubleMemberValue(this);
  91. }
  92. }