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.

AnnotationElementValue.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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 java.util.List;
  16. import org.aspectj.apache.bcel.Constants;
  17. import org.aspectj.apache.bcel.classfile.ConstantPool;
  18. import org.aspectj.apache.bcel.classfile.ConstantUtf8;
  19. public class AnnotationElementValue extends ElementValue {
  20. private AnnotationGen a;
  21. public AnnotationElementValue(AnnotationGen a, ConstantPool cpool) {
  22. super(ANNOTATION, cpool);
  23. this.a = a;
  24. }
  25. public AnnotationElementValue(int type, AnnotationGen annotation, ConstantPool cpool) {
  26. super(type, cpool);
  27. assert type == ANNOTATION;
  28. this.a = annotation;
  29. }
  30. public AnnotationElementValue(AnnotationElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
  31. super(ANNOTATION, cpool);
  32. a = new AnnotationGen(value.getAnnotation(), cpool, copyPoolEntries);
  33. }
  34. @Override
  35. public void dump(DataOutputStream dos) throws IOException {
  36. dos.writeByte(type); // u1 type of value (ANNOTATION == '@')
  37. a.dump(dos);
  38. }
  39. @Override
  40. public String stringifyValue() {
  41. StringBuilder sb = new StringBuilder();
  42. ConstantUtf8 cu8 = (ConstantUtf8) cpool.getConstant(a.getTypeIndex(), Constants.CONSTANT_Utf8);
  43. sb.append(cu8.getValue());
  44. // haven't really tested this values section:
  45. List<NameValuePair> pairs = a.getValues();
  46. if (pairs != null && pairs.size() > 0) {
  47. sb.append("(");
  48. for (int p = 0; p < pairs.size(); p++) {
  49. if (p > 0) {
  50. sb.append(",");
  51. }
  52. sb.append(pairs.get(p).getNameString()).append("=").append(pairs.get(p).getValue().stringifyValue());
  53. }
  54. sb.append(")");
  55. }
  56. return sb.toString();
  57. }
  58. public AnnotationGen getAnnotation() {
  59. return a;
  60. }
  61. }