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.

EnumMemberValue.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 javassist.bytecode.Descriptor;
  18. import java.io.DataOutputStream;
  19. import java.io.IOException;
  20. /**
  21. * Comment
  22. *
  23. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  24. * @version $Revision: 1.4 $
  25. *
  26. **/
  27. public class EnumMemberValue extends MemberValue
  28. {
  29. short type_name_index;
  30. short const_name_index;
  31. public EnumMemberValue(short type, short cni, ConstPool cp)
  32. {
  33. super('e', cp);
  34. this.type_name_index = type;
  35. this.const_name_index = cni;
  36. }
  37. public EnumMemberValue(String type, ConstPool cp)
  38. {
  39. super('e', cp);
  40. setEnumType(type);
  41. }
  42. public EnumMemberValue(ConstPool cp)
  43. {
  44. super('e', cp);
  45. }
  46. /**
  47. * @return tring representing the classname
  48. */
  49. public String getEnumType()
  50. {
  51. return Descriptor.fromDescriptor(cp.getUtf8Info(type_name_index));
  52. }
  53. /**
  54. *
  55. * @param classname FQN classname
  56. */
  57. public void setEnumType(String classname)
  58. {
  59. type_name_index = (short)cp.addUtf8Info(Descriptor.toDescriptor(classname));
  60. }
  61. public String getEnumVal()
  62. {
  63. return cp.getUtf8Info(const_name_index);
  64. }
  65. public void setEnumVal(String name)
  66. {
  67. const_name_index = (short)cp.addUtf8Info(name);
  68. }
  69. public String toString()
  70. {
  71. return getEnumType() + "." + getEnumVal();
  72. }
  73. public void write(DataOutputStream dos) throws IOException
  74. {
  75. super.write(dos);
  76. dos.writeShort(type_name_index);
  77. dos.writeShort(const_name_index);
  78. }
  79. public void accept(MemberValueVisitor visitor)
  80. {
  81. visitor.visitEnumMemberValue(this);
  82. }
  83. }