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.

ByteMemberValue.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * Byte constant value.
  20. *
  21. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  22. * @author Shigeru Chiba
  23. */
  24. public class ByteMemberValue extends MemberValue {
  25. int valueIndex;
  26. /**
  27. * Constructs a byte 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 ByteMemberValue(int index, ConstPool cp) {
  33. super('B', cp);
  34. this.valueIndex = index;
  35. }
  36. /**
  37. * Constructs a byte constant value.
  38. *
  39. * @param b the initial value.
  40. */
  41. public ByteMemberValue(byte b, ConstPool cp) {
  42. super('B', cp);
  43. setValue(b);
  44. }
  45. /**
  46. * Constructs a byte constant value. The initial value is 0.
  47. */
  48. public ByteMemberValue(ConstPool cp) {
  49. super('B', cp);
  50. setValue((byte)0);
  51. }
  52. /**
  53. * Obtains the value of the member.
  54. */
  55. public byte getValue() {
  56. return (byte)cp.getIntegerInfo(valueIndex);
  57. }
  58. /**
  59. * Sets the value of the member.
  60. */
  61. public void setValue(byte newValue) {
  62. valueIndex = cp.addIntegerInfo(newValue);
  63. }
  64. /**
  65. * Obtains the string representation of this object.
  66. */
  67. public String toString() {
  68. return Byte.toString(getValue());
  69. }
  70. void write(AnnotationsWriter writer) throws IOException {
  71. writer.constValueIndex(getValue());
  72. }
  73. /**
  74. * Accepts a visitor.
  75. */
  76. public void accept(MemberValueVisitor visitor) {
  77. visitor.visitByteMemberValue(this);
  78. }
  79. }