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.

ArrayMemberValue.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. import java.util.ArrayList;
  21. /**
  22. * Comment
  23. *
  24. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  25. * @version $Revision: 1.3 $
  26. *
  27. **/
  28. public class ArrayMemberValue extends MemberValue
  29. {
  30. MemberValue[] values;
  31. MemberValue type;
  32. private ArrayMemberValue(ConstPool cp)
  33. {
  34. super('[', cp);
  35. }
  36. public ArrayMemberValue(MemberValue type, ConstPool cp)
  37. {
  38. this(cp);
  39. this.type = type;
  40. }
  41. public MemberValue[] getValue()
  42. {
  43. return values;
  44. }
  45. public void setValue(MemberValue[] values)
  46. {
  47. if (values != null && values.length > 0) type = values[0];
  48. this.values = values;
  49. }
  50. public MemberValue getType()
  51. {
  52. return type;
  53. }
  54. public static ArrayMemberValue readArray(ConstPool cp, DataInput di) throws java.io.IOException
  55. {
  56. ArrayMemberValue rtn = new ArrayMemberValue(cp);
  57. int length = di.readShort();
  58. ArrayList values = new ArrayList(length);
  59. for (int i = 0; i < length; i++)
  60. {
  61. MemberValue type = MemberValue.readMemberValue(cp, di);
  62. rtn.type = type;
  63. values.add(type);
  64. }
  65. rtn.values = (MemberValue[]) values.toArray(new MemberValue[length]);
  66. return rtn;
  67. }
  68. public void write(DataOutputStream dos) throws IOException
  69. {
  70. super.write(dos);
  71. if (values == null)
  72. {
  73. dos.writeShort(0);
  74. return;
  75. }
  76. dos.writeShort(values.length);
  77. for (int i = 0; i < values.length; i++)
  78. {
  79. values[i].write(dos);
  80. }
  81. }
  82. public String toString()
  83. {
  84. StringBuffer buf = new StringBuffer("{");
  85. if (values != null)
  86. {
  87. for (int i = 0; i < values.length; i++)
  88. {
  89. buf.append(values[i].toString());
  90. if (i + 1 < values.length) buf.append(", ");
  91. }
  92. }
  93. buf.append("}");
  94. return buf.toString();
  95. }
  96. public void accept(MemberValueVisitor visitor)
  97. {
  98. visitor.visitArrayMemberValue(this);
  99. }
  100. }