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.

LongMemberValue.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * Long integer constant value.
  20. *
  21. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  22. * @author Shigeru Chiba
  23. */
  24. public class LongMemberValue extends MemberValue {
  25. int valueIndex;
  26. /**
  27. * Constructs a long 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_Long_info structure.
  31. */
  32. public LongMemberValue(int index, ConstPool cp) {
  33. super('J', cp);
  34. this.valueIndex = index;
  35. }
  36. /**
  37. * Constructs a long constant value.
  38. *
  39. * @param j the initial value.
  40. */
  41. public LongMemberValue(long j, ConstPool cp) {
  42. super('J', cp);
  43. setValue(j);
  44. }
  45. /**
  46. * Constructs a long constant value. The initial value is 0.
  47. */
  48. public LongMemberValue(ConstPool cp) {
  49. super('J', cp);
  50. setValue(0L);
  51. }
  52. /**
  53. * Obtains the value of the member.
  54. */
  55. public long getValue() {
  56. return cp.getLongInfo(valueIndex);
  57. }
  58. /**
  59. * Sets the value of the member.
  60. */
  61. public void setValue(long newValue) {
  62. valueIndex = cp.addLongInfo(newValue);
  63. }
  64. /**
  65. * Obtains the string representation of this object.
  66. */
  67. public String toString() {
  68. return Long.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.visitLongMemberValue(this);
  78. }
  79. }