diff options
author | mwebster <mwebster> | 2006-11-06 13:51:39 +0000 |
---|---|---|
committer | mwebster <mwebster> | 2006-11-06 13:51:39 +0000 |
commit | 3cb2fd8d69a01c405f36b486831e5573d693ee2b (patch) | |
tree | 4d435dc630d47954f17b0c16d5cff0c9cbe93c37 | |
parent | c54bc0b1b5db182c431d7c1ac28cbc73edb229c2 (diff) | |
download | aspectj-3cb2fd8d69a01c405f36b486831e5573d693ee2b.tar.gz aspectj-3cb2fd8d69a01c405f36b486831e5573d693ee2b.zip |
Bug 155033 "Use ajcore for LTW problems" (change MessageHandler to MessageHolder)
-rw-r--r-- | weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java | 161 |
1 files changed, 97 insertions, 64 deletions
diff --git a/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java b/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java index 4916a10ab..d532b8d94 100644 --- a/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java +++ b/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java @@ -33,7 +33,9 @@ import org.aspectj.bridge.AbortException; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessageContext; import org.aspectj.bridge.IMessageHandler; +import org.aspectj.bridge.IMessageHolder; import org.aspectj.bridge.Message; +import org.aspectj.bridge.MessageHandler; import org.aspectj.bridge.MessageUtil; import org.aspectj.bridge.MessageWriter; import org.aspectj.bridge.Version; @@ -78,7 +80,7 @@ public class WeavingAdaptor implements IMessageContext { protected BcelWorld bcelWorld; protected BcelWeaver weaver; private IMessageHandler messageHandler; - private WeavingAdaptorMessageHandler messageHolder; + private WeavingAdaptorMessageHolder messageHolder; private boolean abortOnError = false; protected GeneratedClassHandler generatedClassHandler; protected Map generatedClasses = new HashMap(); /* String -> UnwovenClassFile */ @@ -173,7 +175,7 @@ public class WeavingAdaptor implements IMessageContext { } protected void createMessageHandler() { - messageHolder = new WeavingAdaptorMessageHandler(new PrintWriter(System.err)); + messageHolder = new WeavingAdaptorMessageHolder(new PrintWriter(System.err)); messageHandler = messageHolder; if (verbose) messageHandler.dontIgnore(IMessage.INFO); if (Boolean.getBoolean(SHOW_WEAVE_INFO_PROPERTY)) messageHandler.dontIgnore(IMessage.WEAVEINFO); @@ -184,6 +186,10 @@ public class WeavingAdaptor implements IMessageContext { return messageHandler; } + public IMessageHolder getMessageHolder () { + return messageHolder; + } + protected void setMessageHandler (IMessageHandler mh) { if (mh instanceof ISupportsMessageContext) { ISupportsMessageContext smc = (ISupportsMessageContext)mh; @@ -235,35 +241,35 @@ public class WeavingAdaptor implements IMessageContext { public byte[] weaveClass (String name, byte[] bytes) throws IOException { if (trace.isTraceEnabled()) trace.enter("weaveClass",this,new Object[] {name, bytes}); - if (enabled) { - try { - delegateForCurrentClass=null; - if (trace.isTraceEnabled()) trace.enter("weaveClass",this,new Object[] {name,bytes}); - name = name.replace('/','.'); - if (couldWeave(name, bytes)) { - if (accept(name, bytes)) { - // TODO @AspectJ problem - // Annotation style aspects need to be included regardless in order to get - // a valid aspectOf()/hasAspect() generated in them. However - if they are excluded - // (via include/exclude in aop.xml) they really should only get aspectOf()/hasAspect() - // and not be included in the full set of aspects being applied by 'this' weaver - debug("weaving '" + name + "'"); - bytes = getWovenBytes(name, bytes); - } else if (shouldWeaveAnnotationStyleAspect(name, bytes)) { - // an @AspectJ aspect needs to be at least munged by the aspectOf munger - debug("weaving '" + name + "'"); - bytes = getAtAspectJAspectBytes(name, bytes); - } else { - debug("not weaving '" + name + "'"); - } - } else { - debug("cannot weave '" + name + "'"); + if (!enabled) { + if (trace.isTraceEnabled()) trace.exit("weaveClass",false); + return bytes; + } + + try { + delegateForCurrentClass=null; + name = name.replace('/','.'); + if (couldWeave(name, bytes)) { + if (accept(name, bytes)) { + // TODO @AspectJ problem + // Annotation style aspects need to be included regardless in order to get + // a valid aspectOf()/hasAspect() generated in them. However - if they are excluded + // (via include/exclude in aop.xml) they really should only get aspectOf()/hasAspect() + // and not be included in the full set of aspects being applied by 'this' weaver + debug("weaving '" + name + "'"); + bytes = getWovenBytes(name, bytes); + } else if (shouldWeaveAnnotationStyleAspect(name, bytes)) { + // an @AspectJ aspect needs to be at least munged by the aspectOf munger + debug("weaving '" + name + "'"); + bytes = getAtAspectJAspectBytes(name, bytes); + } else { + debug("not weaving '" + name + "'"); } - - if (trace.isTraceEnabled()) trace.exit("weaveClass",bytes); - } finally { - delegateForCurrentClass=null; + } else { + debug("cannot weave '" + name + "'"); } + } finally { + delegateForCurrentClass=null; } if (trace.isTraceEnabled()) trace.exit("weaveClass",bytes); @@ -472,29 +478,18 @@ public class WeavingAdaptor implements IMessageContext { * Processes messages arising from weaver operations. * Tell weaver to abort on any message more severe than warning. */ - protected class WeavingAdaptorMessageHandler implements IMessageHandler { + protected class WeavingAdaptorMessageHolder extends MessageHandler { + private IMessageHandler delegate; - private boolean accumulating = true; - private List messages = new ArrayList(); + private List savedMessages; protected boolean traceMessages = Boolean.getBoolean(TRACE_MESSAGES_PROPERTY); - public WeavingAdaptorMessageHandler (PrintWriter writer) { + public WeavingAdaptorMessageHolder (PrintWriter writer) { this.delegate = new WeavingAdaptorMessageWriter(writer); - } - - public boolean handleMessage(IMessage message) throws AbortException { - if (traceMessages) traceMessage(message); - if (accumulating) { - boolean result = addMessage(message); - if (abortOnError && 0 <= message.getKind().compareTo(IMessage.ERROR)) { - throw new AbortException(message); - } - return result; - } - else return delegate.handleMessage(message); + super.dontIgnore(IMessage.WEAVEINFO); } private void traceMessage (IMessage message) { @@ -527,41 +522,79 @@ public class WeavingAdaptor implements IMessageContext { protected String render(IMessage message) { return "[" + getContextId() + "] " + message.toString(); } + + public void flushMessages () { + if (savedMessages == null) { + savedMessages = new ArrayList(); + savedMessages.addAll(super.getUnmodifiableListView()); + clearMessages(); + for (Iterator iter = savedMessages.iterator(); iter.hasNext();) { + IMessage message = (IMessage)iter.next(); + delegate.handleMessage(message); + } + } +// accumulating = false; +// messages.clear(); + } + + public void setDelegate (IMessageHandler messageHandler) { + delegate = messageHandler; + } + + + /* + * IMessageHandler + */ + + public boolean handleMessage(IMessage message) throws AbortException { + if (traceMessages) traceMessage(message); + + super.handleMessage(message); + + if (abortOnError && 0 <= message.getKind().compareTo(IMessage.ERROR)) { + throw new AbortException(message); + } +// if (accumulating) { +// boolean result = addMessage(message); +// if (abortOnError && 0 <= message.getKind().compareTo(IMessage.ERROR)) { +// throw new AbortException(message); +// } +// return result; +// } +// else return delegate.handleMessage(message); + + if (savedMessages != null) delegate.handleMessage(message); + return true; + } public boolean isIgnoring (Kind kind) { return delegate.isIgnoring(kind); } public void dontIgnore (IMessage.Kind kind) { - if (null != kind) { + if (null != kind && delegate != null) { delegate.dontIgnore(kind); } } public void ignore(Kind kind) { - if (null != kind) { + if (null != kind && delegate != null) { delegate.ignore(kind); } } + - private boolean addMessage (IMessage message) { - messages.add(message); - return true; - } - - public void flushMessages () { - for (Iterator iter = messages.iterator(); iter.hasNext();) { - IMessage message = (IMessage)iter.next(); - delegate.handleMessage(message); - } - accumulating = false; - messages.clear(); - } - - public void setDelegate (IMessageHandler messageHandler) { - delegate = messageHandler; - } + /* + * IMessageHolder + */ + public List getUnmodifiableListView() { +// System.err.println("? WeavingAdaptorMessageHolder.getUnmodifiableListView() savedMessages=" + savedMessages); + List allMessages = new ArrayList(); + allMessages.addAll(savedMessages); + allMessages.addAll(super.getUnmodifiableListView()); + return allMessages; + } } protected class WeavingAdaptorMessageWriter extends MessageWriter { |