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

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