Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ArrayAnnotationVisitor.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* *******************************************************************
  2. * Copyright (c) 2006 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement IBM initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.asm;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. import org.aspectj.weaver.AnnotationAJ;
  16. import org.aspectj.weaver.AnnotationAnnotationValue;
  17. import org.aspectj.weaver.AnnotationValue;
  18. import org.aspectj.weaver.ArrayAnnotationValue;
  19. import org.aspectj.weaver.BCException;
  20. import org.aspectj.weaver.ClassAnnotationValue;
  21. import org.aspectj.weaver.EnumAnnotationValue;
  22. import org.aspectj.weaver.SimpleAnnotationValue;
  23. import org.aspectj.org.objectweb.asm.AnnotationVisitor;
  24. import org.aspectj.org.objectweb.asm.Type;
  25. class ArrayAnnotationVisitor implements AnnotationVisitor {
  26. List arrayValues = new ArrayList();
  27. boolean vis;
  28. ArrayAnnotationValue val;
  29. public ArrayAnnotationVisitor(ArrayAnnotationValue val,boolean visibility) {this.val = val;this.vis = visibility;}
  30. public void visit(String name, Object value) {
  31. AnnotationValue val = null;
  32. if (value instanceof Integer) val = new SimpleAnnotationValue(AnnotationValue.PRIMITIVE_INT,value);
  33. if (value instanceof Boolean) val = new SimpleAnnotationValue(AnnotationValue.PRIMITIVE_BOOLEAN,value);
  34. if (value instanceof String) val = new SimpleAnnotationValue(AnnotationValue.STRING,value);
  35. if (value instanceof Long) val = new SimpleAnnotationValue(AnnotationValue.PRIMITIVE_LONG,value);
  36. if (value instanceof Short) val = new SimpleAnnotationValue(AnnotationValue.PRIMITIVE_SHORT,value);
  37. if (value instanceof Double) val = new SimpleAnnotationValue(AnnotationValue.PRIMITIVE_DOUBLE,value);
  38. if (value instanceof Float) val = new SimpleAnnotationValue(AnnotationValue.PRIMITIVE_FLOAT,value);
  39. if (value instanceof Character) val = new SimpleAnnotationValue(AnnotationValue.PRIMITIVE_CHAR,value);
  40. if (value instanceof Byte) val = new SimpleAnnotationValue(AnnotationValue.PRIMITIVE_BYTE,value);
  41. if (val==null && value instanceof Type) {
  42. String classSignature = ((Type)value).getDescriptor();
  43. val = new ClassAnnotationValue(classSignature);
  44. }
  45. if (val!=null) {
  46. arrayValues.add(val);
  47. } else {
  48. throw new BCException("ArrayAnnotationVisitor choking on "+name+" = "+value);
  49. }
  50. }
  51. public void visitEnum(String name, String type, String value) {
  52. AnnotationValue val = new EnumAnnotationValue(type,value);
  53. arrayValues.add(val);//new AnnotationNameValuePair(name,val));
  54. }
  55. public AnnotationVisitor visitAnnotation(String name, String desc) {
  56. AnnotationAJ annotation = new AnnotationAJ(desc,vis);
  57. AnnotationValue val = new AnnotationAnnotationValue(annotation);
  58. arrayValues.add(val);
  59. return new AnnVisitor(annotation);
  60. }
  61. public AnnotationVisitor visitArray(String arg0) {
  62. ArrayAnnotationValue val = new ArrayAnnotationValue();
  63. arrayValues.add(val);
  64. return new ArrayAnnotationVisitor(val,vis);
  65. }
  66. public void visitEnd() {
  67. val.setValues((AnnotationValue[])arrayValues.toArray(new AnnotationValue[]{}));
  68. }
  69. }