Community
Participate
Working Groups
Currently it's not possible to post-process the byte code after it has been woven. It would be a great feature to support this so that we can apply custom transformations after the aspects have been applied, e.g. using ASM. A simple extension could look like this: // class org.aspectj.weaver.loadtime.WeavingURLClassLoader /** * Override to apply transformations after aspects have been applied. */ protected byte[] postProcess(String name, byte[] byteCode) { return byteCode; } @Override protected Class defineClass(String name, byte[] b, CodeSource cs) throws IOException { if (trace.isTraceEnabled()) { trace.enter("defineClass", this, new Object[] { name, b, cs }); } // System.err.println("? WeavingURLClassLoader.defineClass(" + name + ", [" + b.length + "])"); byte orig[] = b; /* Avoid recursion during adaptor initialization */ if (!initializingAdaptor) { /* Need to defer creation because of possible recursion during constructor execution */ if (adaptor == null && !initializingAdaptor) { createAdaptor(); } try { b = adaptor.weaveClass(name, b, false); } catch (AbortException ex) { trace.error("defineClass", ex); throw ex; } catch (Throwable th) { trace.error("defineClass", th); } } // perform custom post-processing b = postProcess(name, b); Class clazz; // On error, define the original form of the class and log the issue try { clazz = super.defineClass(name, b, cs); } catch (Throwable th) { trace.error("Weaving class problem. Original class has been returned. The error was caused because of: " + th, th); clazz = super.defineClass(name, orig, cs); } if (trace.isTraceEnabled()) { trace.exit("defineClass", clazz); } return clazz; }