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.

WeavingAdaptor.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM Corporation
  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. * Matthew Webster, Adrian Colyer,
  11. * Martin Lippert initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.weaver.tools;
  14. import java.io.File;
  15. import java.io.FileOutputStream;
  16. import java.io.IOException;
  17. import java.io.PrintWriter;
  18. import java.net.URL;
  19. import java.net.URLClassLoader;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.HashSet;
  23. import java.util.Iterator;
  24. import java.util.LinkedList;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.Set;
  28. import java.util.StringTokenizer;
  29. import org.aspectj.bridge.AbortException;
  30. import org.aspectj.bridge.IMessage;
  31. import org.aspectj.bridge.IMessageContext;
  32. import org.aspectj.bridge.IMessageHandler;
  33. import org.aspectj.bridge.Message;
  34. import org.aspectj.bridge.MessageUtil;
  35. import org.aspectj.bridge.MessageWriter;
  36. import org.aspectj.bridge.Version;
  37. import org.aspectj.bridge.WeaveMessage;
  38. import org.aspectj.bridge.IMessage.Kind;
  39. import org.aspectj.org.objectweb.asm.ClassReader;
  40. import org.aspectj.util.FileUtil;
  41. import org.aspectj.util.LangUtil;
  42. import org.aspectj.weaver.IClassFileProvider;
  43. import org.aspectj.weaver.IWeaveRequestor;
  44. import org.aspectj.weaver.ResolvedType;
  45. import org.aspectj.weaver.bcel.BcelObjectType;
  46. import org.aspectj.weaver.bcel.BcelWeaver;
  47. import org.aspectj.weaver.bcel.BcelWorld;
  48. import org.aspectj.weaver.bcel.UnwovenClassFile;
  49. import org.aspectj.weaver.bcel.Utility;
  50. /**
  51. * This adaptor allows the AspectJ compiler to be embedded in an existing
  52. * system to facilitate load-time weaving. It provides an interface for a
  53. * weaving class loader to provide a classpath to be woven by a set of
  54. * aspects. A callback is supplied to allow a class loader to define classes
  55. * generated by the compiler during the weaving process.
  56. * <p>
  57. * A weaving class loader should create a <code>WeavingAdaptor</code> before
  58. * any classes are defined, typically during construction. The set of aspects
  59. * passed to the adaptor is fixed for the lifetime of the adaptor although the
  60. * classpath can be augmented. A system property can be set to allow verbose
  61. * weaving messages to be written to the console.
  62. *
  63. */
  64. public class WeavingAdaptor implements IMessageContext {
  65. /**
  66. * System property used to turn on verbose weaving messages
  67. */
  68. public static final String WEAVING_ADAPTOR_VERBOSE = "aj.weaving.verbose";
  69. public static final String SHOW_WEAVE_INFO_PROPERTY = "org.aspectj.weaver.showWeaveInfo";
  70. public static final String TRACE_MESSAGES_PROPERTY = "org.aspectj.tracing.messages";
  71. private boolean enabled = true;
  72. protected boolean verbose = getVerbose();
  73. protected BcelWorld bcelWorld;
  74. protected BcelWeaver weaver;
  75. private IMessageHandler messageHandler;
  76. private WeavingAdaptorMessageHandler messageHolder;
  77. private boolean abortOnError = false;
  78. protected GeneratedClassHandler generatedClassHandler;
  79. protected Map generatedClasses = new HashMap(); /* String -> UnwovenClassFile */
  80. protected BcelObjectType delegateForCurrentClass; // lazily initialized, should be used to prevent parsing bytecode multiple times
  81. private static Trace trace = TraceFactory.getTraceFactory().getTrace(WeavingAdaptor.class);
  82. protected WeavingAdaptor () {
  83. }
  84. /**
  85. * Construct a WeavingAdaptor with a reference to a weaving class loader. The
  86. * adaptor will automatically search the class loader hierarchy to resolve
  87. * classes. The adaptor will also search the hierarchy for WeavingClassLoader
  88. * instances to determine the set of aspects to be used ofr weaving.
  89. * @param loader instance of <code>ClassLoader</code>
  90. */
  91. public WeavingAdaptor (WeavingClassLoader loader) {
  92. // System.err.println("? WeavingAdaptor.<init>(" + loader +"," + aspectURLs.length + ")");
  93. generatedClassHandler = loader;
  94. init(getFullClassPath((ClassLoader)loader),getFullAspectPath((ClassLoader)loader/*,aspectURLs*/));
  95. }
  96. /**
  97. * Construct a WeavingAdator with a reference to a
  98. * <code>GeneratedClassHandler</code>, a full search path for resolving
  99. * classes and a complete set of aspects. The search path must include
  100. * classes loaded by the class loader constructing the WeavingAdaptor and
  101. * all its parents in the hierarchy.
  102. * @param handler <code>GeneratedClassHandler</code>
  103. * @param classURLs the URLs from which to resolve classes
  104. * @param aspectURLs the aspects used to weave classes defined by this class loader
  105. */
  106. public WeavingAdaptor (GeneratedClassHandler handler, URL[] classURLs, URL[] aspectURLs) {
  107. // System.err.println("? WeavingAdaptor.<init>()");
  108. generatedClassHandler = handler;
  109. init(FileUtil.makeClasspath(classURLs),FileUtil.makeClasspath(aspectURLs));
  110. }
  111. private List getFullClassPath (ClassLoader loader) {
  112. List list = new LinkedList();
  113. for (; loader != null; loader = loader.getParent()) {
  114. if (loader instanceof URLClassLoader) {
  115. URL[] urls = ((URLClassLoader)loader).getURLs();
  116. list.addAll(0,FileUtil.makeClasspath(urls));
  117. }
  118. else {
  119. warn("cannot determine classpath");
  120. }
  121. }
  122. list.addAll(0,makeClasspath(System.getProperty("sun.boot.class.path")));
  123. return list;
  124. }
  125. private List getFullAspectPath (ClassLoader loader) {
  126. List list = new LinkedList();
  127. for (; loader != null; loader = loader.getParent()) {
  128. if (loader instanceof WeavingClassLoader) {
  129. URL[] urls = ((WeavingClassLoader)loader).getAspectURLs();
  130. list.addAll(0,FileUtil.makeClasspath(urls));
  131. }
  132. }
  133. return list;
  134. }
  135. private static boolean getVerbose () {
  136. return Boolean.getBoolean(WEAVING_ADAPTOR_VERBOSE);
  137. }
  138. private void init(List classPath, List aspectPath) {
  139. abortOnError = true;
  140. createMessageHandler();
  141. info("using classpath: " + classPath);
  142. info("using aspectpath: " + aspectPath);
  143. bcelWorld = new BcelWorld(classPath,messageHandler,null);
  144. bcelWorld.setXnoInline(false);
  145. bcelWorld.getLint().loadDefaultProperties();
  146. if (LangUtil.is15VMOrGreater()) {
  147. bcelWorld.setBehaveInJava5Way(true);
  148. }
  149. weaver = new BcelWeaver(bcelWorld);
  150. registerAspectLibraries(aspectPath);
  151. }
  152. protected void createMessageHandler() {
  153. messageHolder = new WeavingAdaptorMessageHandler(new PrintWriter(System.err));
  154. messageHandler = messageHolder;
  155. if (verbose) messageHandler.dontIgnore(IMessage.INFO);
  156. if (Boolean.getBoolean(SHOW_WEAVE_INFO_PROPERTY)) messageHandler.dontIgnore(IMessage.WEAVEINFO);
  157. info("AspectJ Weaver Version " + Version.text + " built on " + Version.time_text); //$NON-NLS-1$
  158. }
  159. protected IMessageHandler getMessageHandler () {
  160. return messageHandler;
  161. }
  162. protected void setMessageHandler (IMessageHandler mh) {
  163. if (mh instanceof ISupportsMessageContext) {
  164. ISupportsMessageContext smc = (ISupportsMessageContext)mh;
  165. smc.setMessageContext(this);
  166. }
  167. if (mh != messageHolder) messageHolder.setDelegate(mh);
  168. messageHolder.flushMessages();
  169. }
  170. protected void disable () {
  171. if (trace.isTraceEnabled()) trace.enter("disable",this);
  172. enabled = false;
  173. messageHolder.flushMessages();
  174. if (trace.isTraceEnabled()) trace.exit("disable");
  175. }
  176. protected boolean isEnabled () {
  177. return enabled;
  178. }
  179. /**
  180. * Appends URL to path used by the WeavingAdptor to resolve classes
  181. * @param url to be appended to search path
  182. */
  183. public void addURL(URL url) {
  184. File libFile = new File(url.getPath());
  185. try {
  186. weaver.addLibraryJarFile(libFile);
  187. }
  188. catch (IOException ex) {
  189. warn("bad library: '" + libFile + "'");
  190. }
  191. }
  192. /**
  193. * Weave a class using aspects previously supplied to the adaptor.
  194. * @param name the name of the class
  195. * @param bytes the class bytes
  196. * @return the woven bytes
  197. * @exception IOException weave failed
  198. */
  199. public byte[] weaveClass (String name, byte[] bytes) throws IOException {
  200. if (enabled) {
  201. try {
  202. delegateForCurrentClass=null;
  203. if (trace.isTraceEnabled()) trace.enter("weaveClass",this,new Object[] {name,bytes});
  204. name = name.replace('/','.');
  205. if (couldWeave(name, bytes)) {
  206. if (accept(name, bytes)) {
  207. // TODO @AspectJ problem
  208. // Annotation style aspects need to be included regardless in order to get
  209. // a valid aspectOf()/hasAspect() generated in them. However - if they are excluded
  210. // (via include/exclude in aop.xml) they really should only get aspectOf()/hasAspect()
  211. // and not be included in the full set of aspects being applied by 'this' weaver
  212. debug("weaving '" + name + "'");
  213. bytes = getWovenBytes(name, bytes);
  214. } else if (shouldWeaveAnnotationStyleAspect(name, bytes)) {
  215. // an @AspectJ aspect needs to be at least munged by the aspectOf munger
  216. debug("weaving '" + name + "'");
  217. bytes = getAtAspectJAspectBytes(name, bytes);
  218. } else {
  219. debug("not weaving '" + name + "'");
  220. }
  221. } else {
  222. debug("cannot weave '" + name + "'");
  223. }
  224. if (trace.isTraceEnabled()) trace.exit("weaveClass",bytes);
  225. } finally {
  226. delegateForCurrentClass=null;
  227. }
  228. }
  229. return bytes;
  230. }
  231. /**
  232. * @param name
  233. * @return true if even valid to weave: either with an accept check or to munge it for @AspectJ aspectof support
  234. */
  235. private boolean couldWeave (String name, byte[] bytes) {
  236. return !generatedClasses.containsKey(name) && shouldWeaveName(name);
  237. }
  238. //ATAJ
  239. protected boolean accept(String name, byte[] bytes) {
  240. return true;
  241. }
  242. protected boolean shouldDump(String name, boolean before) {
  243. return false;
  244. }
  245. private boolean shouldWeaveName (String name) {
  246. boolean should =
  247. !((name.startsWith("org.aspectj.")
  248. || name.startsWith("java.")
  249. || name.startsWith("javax."))
  250. //|| name.startsWith("$Proxy")//JDK proxies//FIXME AV is that 1.3 proxy ? fe. ataspect.$Proxy0 is a java5 proxy...
  251. || name.startsWith("sun.reflect."));//JDK reflect
  252. return should;
  253. }
  254. /**
  255. * We allow @AJ aspect weaving so that we can add aspectOf() as part of the weaving
  256. * (and not part of the source compilation)
  257. *
  258. * @param name
  259. * @param bytes bytecode (from classloader), allow to NOT lookup stuff on disk again during resolve
  260. * @return true if @Aspect
  261. */
  262. private boolean shouldWeaveAnnotationStyleAspect(String name, byte[] bytes) {
  263. if (delegateForCurrentClass==null) {
  264. if (weaver.getWorld().isASMAround()) return asmCheckAnnotationStyleAspect(bytes);
  265. else ensureDelegateInitialized(name, bytes);
  266. }
  267. return (delegateForCurrentClass.isAnnotationStyleAspect());
  268. }
  269. private boolean asmCheckAnnotationStyleAspect(byte[] bytes) {
  270. IsAtAspectAnnotationVisitor detector = new IsAtAspectAnnotationVisitor();
  271. ClassReader cr = new ClassReader(bytes);
  272. try {
  273. cr.accept(detector, true);//, ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
  274. } catch (Exception spe) {
  275. // if anything goes wrong, e.g., an NPE, then assume it's NOT an @AspectJ aspect...
  276. System.err.println("Unexpected problem parsing bytes to discover @Aspect annotation");
  277. spe.printStackTrace();
  278. return false;
  279. }
  280. return detector.isAspect();
  281. }
  282. protected void ensureDelegateInitialized(String name,byte[] bytes) {
  283. if (delegateForCurrentClass==null)
  284. delegateForCurrentClass = ((BcelWorld)weaver.getWorld()).addSourceObjectType(Utility.makeJavaClass(name, bytes));
  285. }
  286. /**
  287. * Weave a set of bytes defining a class.
  288. * @param name the name of the class being woven
  289. * @param bytes the bytes that define the class
  290. * @return byte[] the woven bytes for the class
  291. * @throws IOException
  292. */
  293. private byte[] getWovenBytes(String name, byte[] bytes) throws IOException {
  294. WeavingClassFileProvider wcp = new WeavingClassFileProvider(name,bytes);
  295. weaver.weave(wcp);
  296. return wcp.getBytes();
  297. }
  298. /**
  299. * Weave a set of bytes defining a class for only what is needed to turn @AspectJ aspect
  300. * in a usefull form ie with aspectOf method - see #113587
  301. * @param name the name of the class being woven
  302. * @param bytes the bytes that define the class
  303. * @return byte[] the woven bytes for the class
  304. * @throws IOException
  305. */
  306. private byte[] getAtAspectJAspectBytes(String name, byte[] bytes) throws IOException {
  307. WeavingClassFileProvider wcp = new WeavingClassFileProvider(name,bytes);
  308. wcp.setApplyAtAspectJMungersOnly();
  309. weaver.weave(wcp);
  310. return wcp.getBytes();
  311. }
  312. private void registerAspectLibraries(List aspectPath) {
  313. // System.err.println("? WeavingAdaptor.registerAspectLibraries(" + aspectPath + ")");
  314. for (Iterator i = aspectPath.iterator(); i.hasNext();) {
  315. String libName = (String)i.next();
  316. addAspectLibrary(libName);
  317. }
  318. weaver.prepareForWeave();
  319. }
  320. /*
  321. * Register an aspect library with this classloader for use during
  322. * weaving. This class loader will also return (unmodified) any of the
  323. * classes in the library in response to a <code>findClass()</code> request.
  324. * The library is not required to be on the weavingClasspath given when this
  325. * classloader was constructed.
  326. * @param aspectLibraryJarFile a jar file representing an aspect library
  327. * @throws IOException
  328. */
  329. private void addAspectLibrary(String aspectLibraryName) {
  330. File aspectLibrary = new File(aspectLibraryName);
  331. if (aspectLibrary.isDirectory()
  332. || (FileUtil.isZipFile(aspectLibrary))) {
  333. try {
  334. info("adding aspect library: '" + aspectLibrary + "'");
  335. weaver.addLibraryJarFile(aspectLibrary);
  336. } catch (IOException ex) {
  337. error("exception adding aspect library: '" + ex + "'");
  338. }
  339. } else {
  340. error("bad aspect library: '" + aspectLibrary + "'");
  341. }
  342. }
  343. private static List makeClasspath(String cp) {
  344. List ret = new ArrayList();
  345. if (cp != null) {
  346. StringTokenizer tok = new StringTokenizer(cp,File.pathSeparator);
  347. while (tok.hasMoreTokens()) {
  348. ret.add(tok.nextToken());
  349. }
  350. }
  351. return ret;
  352. }
  353. protected boolean debug (String message) {
  354. return MessageUtil.debug(messageHandler,message);
  355. }
  356. protected boolean info (String message) {
  357. return MessageUtil.info(messageHandler,message);
  358. }
  359. protected boolean warn (String message) {
  360. return MessageUtil.warn(messageHandler,message);
  361. }
  362. protected boolean warn (String message, Throwable th) {
  363. return messageHandler.handleMessage(new Message(message, IMessage.WARNING, th, null));
  364. }
  365. protected boolean error (String message) {
  366. return MessageUtil.error(messageHandler,message);
  367. }
  368. protected boolean error (String message, Throwable th) {
  369. return messageHandler.handleMessage(new Message(message, IMessage.ERROR, th, null));
  370. }
  371. public String getContextId () {
  372. return "WeavingAdaptor";
  373. }
  374. /**
  375. * Dump the given bytcode in _dump/... (dev mode)
  376. *
  377. * @param name
  378. * @param b
  379. * @param before whether we are dumping before weaving
  380. * @throws Throwable
  381. */
  382. protected void dump(String name, byte[] b, boolean before) {
  383. String dirName = "_ajdump";
  384. if (before) dirName = dirName + File.separator + "_before";
  385. String className = name.replace('.', '/');
  386. final File dir;
  387. if (className.indexOf('/') > 0) {
  388. dir = new File(dirName + File.separator + className.substring(0, className.lastIndexOf('/')));
  389. } else {
  390. dir = new File(dirName);
  391. }
  392. dir.mkdirs();
  393. String fileName = dirName + File.separator + className + ".class";
  394. try {
  395. // System.out.println("WeavingAdaptor.dump() fileName=" + new File(fileName).getAbsolutePath());
  396. FileOutputStream os = new FileOutputStream(fileName);
  397. os.write(b);
  398. os.close();
  399. }
  400. catch (IOException ex) {
  401. warn("unable to dump class " + name + " in directory " + dirName,ex);
  402. }
  403. }
  404. /**
  405. * Processes messages arising from weaver operations.
  406. * Tell weaver to abort on any message more severe than warning.
  407. */
  408. protected class WeavingAdaptorMessageHandler implements IMessageHandler {
  409. private IMessageHandler delegate;
  410. private boolean accumulating = true;
  411. private List messages = new ArrayList();
  412. protected boolean traceMessages = Boolean.getBoolean(TRACE_MESSAGES_PROPERTY);
  413. public WeavingAdaptorMessageHandler (PrintWriter writer) {
  414. this.delegate = new WeavingAdaptorMessageWriter(writer);
  415. }
  416. public boolean handleMessage(IMessage message) throws AbortException {
  417. if (traceMessages) traceMessage(message);
  418. if (accumulating) {
  419. boolean result = addMessage(message);
  420. if (abortOnError && 0 <= message.getKind().compareTo(IMessage.ERROR)) {
  421. throw new AbortException(message);
  422. }
  423. return result;
  424. }
  425. else return delegate.handleMessage(message);
  426. }
  427. private void traceMessage (IMessage message) {
  428. if (message instanceof WeaveMessage) {
  429. trace.debug(render(message));
  430. }
  431. else if (message.isDebug()) {
  432. trace.debug(render(message));
  433. }
  434. else if (message.isInfo()) {
  435. trace.info(render(message));
  436. }
  437. else if (message.isWarning()) {
  438. trace.warn(render(message),message.getThrown());
  439. }
  440. else if (message.isError()) {
  441. trace.error(render(message),message.getThrown());
  442. }
  443. else if (message.isFailed()) {
  444. trace.fatal(render(message),message.getThrown());
  445. }
  446. else if (message.isAbort()) {
  447. trace.fatal(render(message),message.getThrown());
  448. }
  449. else {
  450. trace.error(render(message),message.getThrown());
  451. }
  452. }
  453. protected String render(IMessage message) {
  454. return "[" + getContextId() + "] " + message.toString();
  455. }
  456. public boolean isIgnoring (Kind kind) {
  457. return delegate.isIgnoring(kind);
  458. }
  459. public void dontIgnore (IMessage.Kind kind) {
  460. if (null != kind) {
  461. delegate.dontIgnore(kind);
  462. }
  463. }
  464. public void ignore(Kind kind) {
  465. if (null != kind) {
  466. delegate.ignore(kind);
  467. }
  468. }
  469. private boolean addMessage (IMessage message) {
  470. messages.add(message);
  471. return true;
  472. }
  473. public void flushMessages () {
  474. for (Iterator iter = messages.iterator(); iter.hasNext();) {
  475. IMessage message = (IMessage)iter.next();
  476. delegate.handleMessage(message);
  477. }
  478. accumulating = false;
  479. messages.clear();
  480. }
  481. public void setDelegate (IMessageHandler messageHandler) {
  482. delegate = messageHandler;
  483. }
  484. }
  485. protected class WeavingAdaptorMessageWriter extends MessageWriter {
  486. private Set ignoring = new HashSet();
  487. private IMessage.Kind failKind;
  488. public WeavingAdaptorMessageWriter (PrintWriter writer) {
  489. super(writer,true);
  490. ignore(IMessage.WEAVEINFO);
  491. ignore(IMessage.DEBUG);
  492. ignore(IMessage.INFO);
  493. this.failKind = IMessage.ERROR;
  494. }
  495. public boolean handleMessage(IMessage message) throws AbortException {
  496. boolean result = super.handleMessage(message);
  497. if (abortOnError && 0 <= message.getKind().compareTo(failKind)) {
  498. throw new AbortException(message);
  499. }
  500. return true;
  501. }
  502. public boolean isIgnoring (Kind kind) {
  503. return ((null != kind) && (ignoring.contains(kind)));
  504. }
  505. /**
  506. * Set a message kind to be ignored from now on
  507. */
  508. public void ignore (IMessage.Kind kind) {
  509. if ((null != kind) && (!ignoring.contains(kind))) {
  510. ignoring.add(kind);
  511. }
  512. }
  513. /**
  514. * Remove a message kind from the list of those ignored from now on.
  515. */
  516. public void dontIgnore (IMessage.Kind kind) {
  517. if (null != kind) {
  518. ignoring.remove(kind);
  519. }
  520. }
  521. protected String render(IMessage message) {
  522. return "[" + getContextId() + "] " + super.render(message);
  523. }
  524. }
  525. private class WeavingClassFileProvider implements IClassFileProvider {
  526. private UnwovenClassFile unwovenClass;
  527. private List unwovenClasses = new ArrayList(); /* List<UnovenClassFile> */
  528. private UnwovenClassFile wovenClass;
  529. private boolean isApplyAtAspectJMungersOnly = false;
  530. public WeavingClassFileProvider (String name, byte[] bytes) {
  531. ensureDelegateInitialized(name, bytes);
  532. this.unwovenClass = new UnwovenClassFile(name,delegateForCurrentClass.getResolvedTypeX().getName(),bytes);
  533. this.unwovenClasses.add(unwovenClass);
  534. if (shouldDump(name.replace('/', '.'),true)) {
  535. dump(name, bytes, true);
  536. }
  537. }
  538. public void setApplyAtAspectJMungersOnly() {
  539. isApplyAtAspectJMungersOnly = true;
  540. }
  541. public boolean isApplyAtAspectJMungersOnly() {
  542. return isApplyAtAspectJMungersOnly;
  543. }
  544. public byte[] getBytes () {
  545. if (wovenClass != null) return wovenClass.getBytes();
  546. else return unwovenClass.getBytes();
  547. }
  548. public Iterator getClassFileIterator() {
  549. return unwovenClasses.iterator();
  550. }
  551. public IWeaveRequestor getRequestor() {
  552. return new IWeaveRequestor() {
  553. public void acceptResult(UnwovenClassFile result) {
  554. if (wovenClass == null) {
  555. wovenClass = result;
  556. String name = result.getClassName();
  557. if (shouldDump(name.replace('/', '.'), false)) {
  558. dump(name, result.getBytes(), false);
  559. }
  560. }
  561. /* Classes generated by weaver e.g. around closure advice */
  562. else {
  563. String className = result.getClassName();
  564. generatedClasses.put(className,result);
  565. generatedClasses.put(wovenClass.getClassName(),result);
  566. generatedClassHandler.acceptClass(className,result.getBytes());
  567. }
  568. }
  569. public void processingReweavableState() { }
  570. public void addingTypeMungers() {}
  571. public void weavingAspects() {}
  572. public void weavingClasses() {}
  573. public void weaveCompleted() {
  574. ResolvedType.resetPrimitives();
  575. if (delegateForCurrentClass!=null) delegateForCurrentClass.weavingCompleted();
  576. ResolvedType.resetPrimitives();
  577. //bcelWorld.discardType(typeBeingProcessed.getResolvedTypeX()); // work in progress
  578. }
  579. };
  580. }
  581. }
  582. }