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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.ClassPool;
  17. import javassist.bytecode.ConstPool;
  18. import java.io.IOException;
  19. import java.lang.reflect.Method;
  20. /**
  21. * Byte constant value.
  22. *
  23. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  24. * @author Shigeru Chiba
  25. */
  26. public class ByteMemberValue extends MemberValue {
  27. int valueIndex;
  28. /**
  29. * Constructs a byte constant value. The initial value is specified
  30. * by the constant pool entry at the given index.
  31. *
  32. * @param index the index of a CONSTANT_Integer_info structure.
  33. */
  34. public ByteMemberValue(int index, ConstPool cp) {
  35. super('B', cp);
  36. this.valueIndex = index;
  37. }
  38. /**
  39. * Constructs a byte constant value.
  40. *
  41. * @param b the initial value.
  42. */
  43. public ByteMemberValue(byte b, ConstPool cp) {
  44. super('B', cp);
  45. setValue(b);
  46. }
  47. /**
  48. * Constructs a byte constant value. The initial value is 0.
  49. */
  50. public ByteMemberValue(ConstPool cp) {
  51. super('B', cp);
  52. setValue((byte)0);
  53. }
  54. Object getValue(ClassLoader cl, ClassPool cp, Method m) {
  55. return new Byte(getValue());
  56. }
  57. Class getType(ClassLoader cl) {
  58. return byte.class;
  59. }
  60. /**
  61. * Obtains the value of the member.
  62. */
  63. public byte getValue() {
  64. return (byte)cp.getIntegerInfo(valueIndex);
  65. }
  66. /**
  67. * Sets the value of the member.
  68. */
  69. public void setValue(byte newValue) {
  70. valueIndex = cp.addIntegerInfo(newValue);
  71. }
  72. /**
  73. * Obtains the string representation of this object.
  74. */
  75. public String toString() {
  76. return Byte.toString(getValue());
  77. }
  78. /**
  79. * Writes the value.
  80. */
  81. public void write(AnnotationsWriter writer) throws IOException {
  82. writer.constValueIndex(getValue());
  83. }
  84. /**
  85. * Accepts a visitor.
  86. */
  87. public void accept(MemberValueVisitor visitor) {
  88. visitor.visitByteMemberValue(this);
  89. }
  90. }