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.

IntegerMemberValue.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * Integer constant value.
  20. *
  21. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  22. * @author Shigeru Chiba
  23. */
  24. public class IntegerMemberValue extends MemberValue {
  25. int valueIndex;
  26. /**
  27. * Constructs an int constant value. The initial value is specified
  28. * by the constant pool entry at the given index.
  29. *
  30. * @param index the index of a CONSTANT_Integer_info structure.
  31. */
  32. public IntegerMemberValue(int index, ConstPool cp) {
  33. super('I', cp);
  34. this.valueIndex = index;
  35. }
  36. /**
  37. * Constructs an int constant value.
  38. * Note that this constructor receives <b>the initial value
  39. * as the second parameter</b>
  40. * unlike the corresponding constructors in the sibling classes.
  41. * This is for making a difference from the constructor that receives
  42. * an index into the constant pool table as the first parameter.
  43. * Note that the index is also int type.
  44. *
  45. * @param value the initial value.
  46. */
  47. public IntegerMemberValue(ConstPool cp, int value) {
  48. super('I', cp);
  49. setValue(value);
  50. }
  51. /**
  52. * Constructs an int constant value. The initial value is 0.
  53. */
  54. public IntegerMemberValue(ConstPool cp) {
  55. super('I', cp);
  56. setValue(0);
  57. }
  58. /**
  59. * Obtains the value of the member.
  60. */
  61. public int getValue() {
  62. return cp.getIntegerInfo(valueIndex);
  63. }
  64. /**
  65. * Sets the value of the member.
  66. */
  67. public void setValue(int newValue) {
  68. valueIndex = cp.addIntegerInfo(newValue);
  69. }
  70. /**
  71. * Obtains the string representation of this object.
  72. */
  73. public String toString() {
  74. return Integer.toString(getValue());
  75. }
  76. void write(AnnotationsWriter writer) throws IOException {
  77. writer.constValueIndex(getValue());
  78. }
  79. /**
  80. * Accepts a visitor.
  81. */
  82. public void accept(MemberValueVisitor visitor) {
  83. visitor.visitIntegerMemberValue(this);
  84. }
  85. }