/*
* Report a message about the advice weave that has occurred. Some messing about to make it pretty ! This code is just asking
* for an NPE to occur ...
*/
private void reportWeavingMessage(ShadowMunger munger, Shadow shadow) {
Advice advice = (Advice) munger;
AdviceKind aKind = advice.getKind();
// Only report on interesting advice kinds ...
if (aKind == null || advice.getConcreteAspect() == null) {
// We suspect someone is programmatically driving the weaver
// (e.g. IdWeaveTestCase in the weaver testcases)
return;
}
if (!(aKind.equals(AdviceKind.Before) || aKind.equals(AdviceKind.After) || aKind.equals(AdviceKind.AfterReturning)
|| aKind.equals(AdviceKind.AfterThrowing) || aKind.equals(AdviceKind.Around) || aKind.equals(AdviceKind.Softener))) {
return;
}
// synchronized blocks are implemented with multiple monitor_exit instructions in the bytecode
// (one for normal exit from the method, one for abnormal exit), we only want to tell the user
// once we have advised the end of the sync block, even though under the covers we will have
// woven both exit points
if (shadow.getKind() == Shadow.SynchronizationUnlock) {
if (advice.lastReportedMonitorExitJoinpointLocation == null) {
// this is the first time through, let's continue...
advice.lastReportedMonitorExitJoinpointLocation = shadow.getSourceLocation();
} else {
if (areTheSame(shadow.getSourceLocation(), advice.lastReportedMonitorExitJoinpointLocation)) {
// Don't report it again!
advice.lastReportedMonitorExitJoinpointLocation = null;
return;
}
// hmmm, this means some kind of nesting is going on, urgh
advice.lastReportedMonitorExitJoinpointLocation = shadow.getSourceLocation();
}
}
String description = advice.getKind().toString();
String advisedType = shadow.getEnclosingType().getName();
String advisingType = advice.getConcreteAspect().getName();
Message msg = null;
if (advice.getKind().equals(AdviceKind.Softener)) {
msg = WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_SOFTENS, new String[] { advisedType,
beautifyLocation(shadow.getSourceLocation()), advisingType, beautifyLocation(munger.getSourceLocation()) },
advisedType, advisingType);
} else {
boolean runtimeTest = advice.hasDynamicTests();
String joinPointDescription = shadow.toString();
msg = WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ADVISES, new String[] { joinPointDescription,
advisedType, beautifyLocation(shadow.getSourceLocation()), description, advisingType,
beautifyLocation(munger.getSourceLocation()), (runtimeTest ? " [with runtime test]" : "") }, advisedType,
advisingType);