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.

BcelAttributes.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  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. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. import org.aspectj.apache.bcel.classfile.Attribute;
  16. import org.aspectj.apache.bcel.classfile.Unknown;
  17. import org.aspectj.weaver.AjAttribute;
  18. import org.aspectj.weaver.BCException;
  19. import org.aspectj.weaver.ISourceContext;
  20. import org.aspectj.weaver.World;
  21. import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
  22. // this is a class o' static methods for reading attributes. It's pretty much a bridge from
  23. // bcel to AjAttribute.
  24. // OPTIMIZE move the contents of this class to bcel Utility
  25. class BcelAttributes {
  26. /**
  27. * Process an array of Bcel attributes - looking for those with the name prefix org.aspectj.weaver. The returned
  28. * list contains the AspectJ attributes identified and unpacked to 'AjAttribute' objects.
  29. */
  30. // public static List readAjAttributes(String classname,List as, ISourceContext context,
  31. // World w, AjAttribute.WeaverVersionInfo version) {
  32. // List l = new ArrayList();
  33. //
  34. // // first pass, look for version
  35. // List forSecondPass = new ArrayList();
  36. // for (int i = as.size() - 1; i >= 0; i--) {
  37. // Attribute a = (Attribute)as.get(i);
  38. // if (a instanceof Unknown) {
  39. // Unknown u = (Unknown) a;
  40. // String name = u.getName();
  41. // if (name.charAt(0)=='o') { // 'o'rg.aspectj
  42. // if (name.startsWith(AjAttribute.AttributePrefix)) {
  43. // if (name.endsWith(WeaverVersionInfo.AttributeName)) {
  44. // version = (AjAttribute.WeaverVersionInfo)AjAttribute.read(version,name,u.getBytes(),context,w);
  45. // if (version.getMajorVersion() > WeaverVersionInfo.getCurrentWeaverMajorVersion()) {
  46. // throw new BCException("Unable to continue, this version of AspectJ supports classes built with weaver version "+
  47. // WeaverVersionInfo.toCurrentVersionString()+" but the class "+classname+" is version "+version.toString());
  48. // }
  49. // }
  50. // forSecondPass.add(a);
  51. // }
  52. // }
  53. // }
  54. // }
  55. // for (int i = forSecondPass.size()-1; i >= 0; i--) {
  56. // Unknown a = (Unknown)forSecondPass.get(i);
  57. // String name = a.getName();
  58. // AjAttribute attr = AjAttribute.read(version,name,a.getBytes(),context,w);
  59. // if (attr!=null) l.add(attr);
  60. // }
  61. // return l;
  62. // }
  63. public static List readAjAttributes(String classname, Attribute[] as, ISourceContext context, World w, AjAttribute.WeaverVersionInfo version) {
  64. List l = new ArrayList();
  65. // first pass, look for version
  66. List forSecondPass = new ArrayList();
  67. for (int i = as.length - 1; i >= 0; i--) {
  68. Attribute a = as[i];
  69. if (a instanceof Unknown) {
  70. Unknown u = (Unknown) a;
  71. String name = u.getName();
  72. if (name.charAt(0) == 'o') { // 'o'rg.aspectj
  73. if (name.startsWith(AjAttribute.AttributePrefix)) {
  74. if (name.endsWith(WeaverVersionInfo.AttributeName)) {
  75. version = (AjAttribute.WeaverVersionInfo) AjAttribute.read(version, name, u.getBytes(), context, w);
  76. if (version.getMajorVersion() > WeaverVersionInfo
  77. .getCurrentWeaverMajorVersion()) {
  78. throw new BCException(
  79. "Unable to continue, this version of AspectJ supports classes built with weaver version "
  80. + WeaverVersionInfo
  81. .toCurrentVersionString()
  82. + " but the class "
  83. + classname
  84. + " is version "
  85. + version.toString());
  86. }
  87. }
  88. forSecondPass.add(a);
  89. }
  90. }
  91. }
  92. }
  93. for (int i = forSecondPass.size() - 1; i >= 0; i--) {
  94. Unknown a = (Unknown) forSecondPass.get(i);
  95. String name = a.getName();
  96. AjAttribute attr = AjAttribute.read(version, name, a.getBytes(), context, w);
  97. if (attr != null) l.add(attr);
  98. }
  99. return l;
  100. }
  101. }