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.

MemberValue.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.DataInput;
  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.3 $
  25. *
  26. **/
  27. public abstract class MemberValue
  28. {
  29. ConstPool cp;
  30. char tag;
  31. protected MemberValue(char tag, ConstPool cp)
  32. {
  33. this.cp = cp;
  34. this.tag = tag;
  35. }
  36. public abstract void accept(MemberValueVisitor visitor);
  37. public void write(DataOutputStream dos) throws IOException
  38. {
  39. byte btag = (byte)tag;
  40. dos.writeByte(btag);
  41. }
  42. public static MemberValue readMemberValue(ConstPool cp, DataInput di) throws java.io.IOException
  43. {
  44. byte btag = di.readByte();
  45. char tag = (char) btag;
  46. MemberValue rtn = null;
  47. switch (tag)
  48. {
  49. case 'B':
  50. rtn = new ByteMemberValue(di.readShort(), cp);
  51. break;
  52. case 'C':
  53. rtn = new CharMemberValue(di.readShort(), cp);
  54. break;
  55. case 'D':
  56. rtn = new DoubleMemberValue(di.readShort(), cp);
  57. break;
  58. case 'F':
  59. rtn = new FloatMemberValue(di.readShort(), cp);
  60. break;
  61. case 'I':
  62. rtn = new IntegerMemberValue(di.readShort(), cp);
  63. break;
  64. case 'J':
  65. rtn = new LongMemberValue(di.readShort(), cp);
  66. break;
  67. case 'S':
  68. rtn = new ShortMemberValue(di.readShort(), cp);
  69. break;
  70. case 'Z':
  71. rtn = new BooleanMemberValue(di.readShort(), cp);
  72. break;
  73. case 's':
  74. rtn = new StringMemberValue(di.readShort(), cp);
  75. break;
  76. case 'e':
  77. rtn = new EnumMemberValue(di.readShort(), di.readShort(), cp);
  78. break;
  79. case 'c':
  80. rtn = new ClassMemberValue(di.readShort(), cp);
  81. break;
  82. case '@':
  83. rtn = new AnnotationMemberValue(AnnotationInfo.readAnnotationInfo(cp, di), cp);
  84. break;
  85. case '[':
  86. rtn = ArrayMemberValue.readArray(cp, di);
  87. break;
  88. }
  89. rtn.cp = cp;
  90. rtn.tag = tag;
  91. return rtn;
  92. }
  93. }