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.

AjASMAttribute.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 org.aspectj.weaver.AjAttribute;
  14. import org.aspectj.weaver.BCException;
  15. import org.aspectj.org.objectweb.asm.Attribute;
  16. import org.aspectj.org.objectweb.asm.ByteVector;
  17. import org.aspectj.org.objectweb.asm.ClassReader;
  18. import org.aspectj.org.objectweb.asm.ClassWriter;
  19. import org.aspectj.org.objectweb.asm.Label;
  20. class AjASMAttribute extends Attribute {
  21. private boolean unpacked = false;
  22. private byte[] data;
  23. protected AjASMAttribute(String type) {
  24. super(type);
  25. }
  26. protected AjASMAttribute(String type,byte[] data) {
  27. super(type);
  28. this.data=data;
  29. }
  30. /**
  31. * Initial read of the attribute is super lightweight - no unpacking
  32. */
  33. protected Attribute read(ClassReader cr, int off, int len, char[] buf,
  34. int codeOff, Label[] labels) {
  35. byte[] data = new byte[len];
  36. System.arraycopy(cr.b, off, data, 0, len);
  37. return new AjASMAttribute(this.type, data);
  38. }
  39. /**
  40. * These attributes are read only, an attempt to write them violates this fundamental assumption.
  41. */
  42. protected ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) {
  43. throw new BCException("Attempt to write out the AjASMAttribute for "+this.type);
  44. // return new ByteVector().putByteArray(data, 0, data.length);
  45. }
  46. public boolean isUnknown() { return false; }
  47. // ---
  48. public AjAttribute unpack(AsmDelegate relatedDelegate) {
  49. if (unpacked) throw new BCException("Don't unpack an attribute twice!");
  50. AjAttribute attr = AjAttribute.read(relatedDelegate.weaverVersion,type,data,relatedDelegate.getSourceContext(),relatedDelegate.getWorld());
  51. unpacked=true;
  52. return attr;
  53. }
  54. }