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.

ArrayElementValue.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement - initial implementation {date}
  11. * ******************************************************************/
  12. package org.aspectj.apache.bcel.classfile.annotation;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. import org.aspectj.apache.bcel.classfile.ConstantPool;
  16. public class ArrayElementValue extends ElementValue {
  17. // For array types, this is the array
  18. private ElementValue[] evalues;
  19. public String toString() {
  20. StringBuffer sb = new StringBuffer();
  21. sb.append("{");
  22. for (int i = 0; i < evalues.length; i++) {
  23. sb.append(evalues[i].toString());
  24. if ((i+1)<evalues.length) sb.append(",");
  25. }
  26. sb.append("}");
  27. return sb.toString();
  28. }
  29. public ArrayElementValue(int type, ElementValue[] datums, ConstantPool cpool) {
  30. super(type,cpool);
  31. if (type != ARRAY)
  32. throw new RuntimeException("Only element values of type array can be built with this ctor");
  33. this.evalues = datums;
  34. }
  35. public void dump(DataOutputStream dos) throws IOException {
  36. dos.writeByte(type); // u1 type of value (ARRAY == '[')
  37. dos.writeShort(evalues.length);
  38. for (int i=0; i<evalues.length; i++) {
  39. evalues[i].dump(dos);
  40. }
  41. }
  42. public String stringifyValue() {
  43. StringBuffer sb = new StringBuffer();
  44. sb.append("[");
  45. for(int i=0; i<evalues.length; i++) {
  46. sb.append(evalues[i].stringifyValue());
  47. if ((i+1)<evalues.length) sb.append(",");
  48. }
  49. sb.append("]");
  50. return sb.toString();
  51. }
  52. public ElementValue[] getElementValuesArray() { return evalues;}
  53. public int getElementValuesArraySize() { return evalues.length;}
  54. }