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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 java.io.IOException;
  18. import java.lang.reflect.Method;
  19. import javassist.ClassPool;
  20. import javassist.bytecode.ConstPool;
  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. @Override
  57. Object getValue(ClassLoader cl, ClassPool cp, Method m) {
  58. return Double.valueOf(getValue());
  59. }
  60. @Override
  61. Class<?> getType(ClassLoader cl) {
  62. return double.class;
  63. }
  64. /**
  65. * Obtains the value of the member.
  66. */
  67. public double getValue() {
  68. return cp.getDoubleInfo(valueIndex);
  69. }
  70. /**
  71. * Sets the value of the member.
  72. */
  73. public void setValue(double newValue) {
  74. valueIndex = cp.addDoubleInfo(newValue);
  75. }
  76. /**
  77. * Obtains the string representation of this object.
  78. */
  79. @Override
  80. public String toString() {
  81. return Double.toString(getValue());
  82. }
  83. /**
  84. * Writes the value.
  85. */
  86. @Override
  87. public void write(AnnotationsWriter writer) throws IOException {
  88. writer.constValueIndex(getValue());
  89. }
  90. /**
  91. * Accepts a visitor.
  92. */
  93. @Override
  94. public void accept(MemberValueVisitor visitor) {
  95. visitor.visitDoubleMemberValue(this);
  96. }
  97. }