// thread safe reentrant
for (Iterator it = definitions.iterator(); it.hasNext();) {
final SystemDefinition definition = (SystemDefinition) it.next();
final CtClass ctClass = klass.getCtClass();
ClassInfo classInfo = JavassistClassInfo.getClassInfo(ctClass, context.getLoader());
if (classFilter(definition, new ExpressionContext(PointcutType.HANDLER, classInfo, classInfo), ctClass)) {
continue;
}
ctClass.instrument(new ExprEditor() {
public void edit(Handler handlerExpr) throws CannotCompileException {
try {
CtClass exceptionClass = null;
try {
exceptionClass = handlerExpr.getType();
} catch (NullPointerException e) {
return;
}
CtBehavior where = null;
try {
where = handlerExpr.where();
} catch (RuntimeException e) {
// <clinit> access leads to a bug in Javassist
where = ctClass.getClassInitializer();
}
MemberInfo withinMethodInfo = null;
if (where instanceof CtMethod) {
withinMethodInfo = JavassistMethodInfo.getMethodInfo((CtMethod) where, context.getLoader());
} else if (where instanceof CtConstructor) {
withinMethodInfo = JavassistConstructorInfo.getConstructorInfo(
(CtConstructor) where,
context.getLoader());
}
ClassInfo exceptionClassInfo = JavassistClassInfo.getClassInfo(exceptionClass, context
.getLoader());
ExpressionContext ctx = new ExpressionContext(
PointcutType.HANDLER,
exceptionClassInfo,
withinMethodInfo);
if (definition.hasPointcut(ctx)) {
// call the wrapper method instead of the callee