final ReflectionInfo reflectInfo,
final ReflectionInfo withinInfo) {
List adviceIndexInfoList = new ArrayList();
List cflowExpressionList = new ArrayList();
Pointcut cflowPointcut = null;
ExpressionContext ctx = new ExpressionContext(type, reflectInfo, withinInfo);//AVAJ null?
AspectManager[] aspectManagers = system.getAspectManagers();
for (int i = 0; i < aspectManagers.length; i++) {
AspectManager aspectManager = aspectManagers[i];
/// grab the first one found, one single cflow pointcut is enough per join point
if (cflowPointcut == null) {
List cflowPointcuts = aspectManager.getCflowPointcuts(ctx);
if (!cflowPointcuts.isEmpty()) {
cflowPointcut = (Pointcut) cflowPointcuts.get(0);
}
}
// get all matching pointcuts from all managers
for (Iterator it = aspectManager.getPointcuts(ctx).iterator(); it.hasNext();) {
Pointcut pointcut = (Pointcut) it.next();
AdviceInfo[] aroundAdviceIndexes = pointcut.getAroundAdviceIndexes();
AdviceInfo[] beforeAdviceIndexes = pointcut.getBeforeAdviceIndexes();
AdviceInfo[] afterFinallyAdviceIndexes = pointcut.getAfterFinallyAdviceIndexes();
AdviceInfo[] afterReturningAdviceIndexes = pointcut.getAfterReturningAdviceIndexes();
AdviceInfo[] afterThrowingAdviceIndexes = pointcut.getAfterThrowingAdviceIndexes();
AdviceIndexInfo adviceIndexInfo = new AdviceIndexInfo(
aroundAdviceIndexes,
beforeAdviceIndexes,
afterFinallyAdviceIndexes,
afterReturningAdviceIndexes,
afterThrowingAdviceIndexes
);
// compute target args to advice args mapping, it is a property of each *advice*
// refresh the arg index map
pointcut.getExpressionInfo().getArgsIndexMapper().match(ctx);
//TODO can we do cache, can we do in another visitor
//TODO skip map when no args()
for (int j = 0; j < aroundAdviceIndexes.length; j++) {
setMethodArgumentIndexes(pointcut.getAroundAdviceName(j), pointcut, ctx, aroundAdviceIndexes[j]);
}
for (int j = 0; j < beforeAdviceIndexes.length; j++) {
setMethodArgumentIndexes(pointcut.getBeforeAdviceName(j), pointcut, ctx, beforeAdviceIndexes[j]);
}
for (int j = 0; j < afterFinallyAdviceIndexes.length; j++) {
setMethodArgumentIndexes(
pointcut.getAfterFinallyAdviceName(j), pointcut, ctx, afterFinallyAdviceIndexes[j]
);
}
for (int j = 0; j < afterReturningAdviceIndexes.length; j++) {
setMethodArgumentIndexes(
pointcut.getAfterReturningAdviceName(j), pointcut, ctx, afterReturningAdviceIndexes[j]
);
}
for (int j = 0; j < afterThrowingAdviceIndexes.length; j++) {
setMethodArgumentIndexes(
pointcut.getAfterThrowingAdviceName(j), pointcut, ctx, afterThrowingAdviceIndexes[j]
);
}
adviceIndexInfoList.add(adviceIndexInfo);
// collect the cflow expressions for the matching pointcuts (if they have one)
if (pointcut.getExpressionInfo().hasCflowPointcut()) {
cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
}
}
}
// turn the lists into arrays for performance reasons