final ReflectionInfo reflectInfo,
final ReflectionInfo withinInfo,
final Map joinPointMetaDataMap) {
List adviceIndexInfoList = new ArrayList();
List cflowExpressionList = new ArrayList();
Pointcut cflowPointcut = null;
ExpressionContext ctx = new ExpressionContext(type, reflectInfo, withinInfo);
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[] afterAdviceIndexes = pointcut.getAfterFinallyAdviceIndexes();
AdviceIndexInfo adviceIndexInfo = new AdviceIndexInfo(
aroundAdviceIndexes,
pointcut.getBeforeAdviceIndexes(),
pointcut.getAfterFinallyAdviceIndexes(),
pointcut.getAfterReturningAdviceIndexes(),
pointcut.getAfterThrowingAdviceIndexes()
);
// args() support
// TODO refactor from JPMetaData used in inlining weaving
// 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 < beforeAdviceIndexes.length; j++) {
AdviceInfo indexTuple = beforeAdviceIndexes[j];
String adviceName = pointcut.getBeforeAdviceName(j);
//grab the parameters names
String[] adviceArgNames = JoinPointMetaData.getParameterNames(adviceName);
// map them from the ctx info
int[] adviceToTargetArgs = new int[adviceArgNames.length];
for (int k = 0; k < adviceArgNames.length; k++) {
String adviceArgName = adviceArgNames[k];
int exprArgIndex = pointcut.getExpressionInfo().getArgumentIndex(adviceArgName);
if (exprArgIndex >= 0 && ctx.m_exprIndexToTargetIndex.containsKey(exprArgIndex)) {
adviceToTargetArgs[k] = ctx.m_exprIndexToTargetIndex.get(exprArgIndex);
} else {
adviceToTargetArgs[k] = -1;
}
}
// //debug:
// for (int k = 0; k < adviceToTargetArgs.length; k++) {
// int adviceToTargetArg = adviceToTargetArgs[k];
// System.out.println(" " + k + " -> " + adviceToTargetArg);
// }
indexTuple.setMethodToArgIndexes(adviceToTargetArgs);
}
for (int j = 0; j < afterAdviceIndexes.length; j++) {
AdviceInfo indexTuple = afterAdviceIndexes[j];
String adviceName = pointcut.getAfterFinallyAdviceName(j);
//grab the parameters names
String[] adviceArgNames = JoinPointMetaData.getParameterNames(adviceName);
// map them from the ctx info
int[] adviceToTargetArgs = new int[adviceArgNames.length];
for (int k = 0; k < adviceArgNames.length; k++) {
String adviceArgName = adviceArgNames[k];
int exprArgIndex = pointcut.getExpressionInfo().getArgumentIndex(adviceArgName);
if (exprArgIndex >= 0 && ctx.m_exprIndexToTargetIndex.containsKey(exprArgIndex)) {
adviceToTargetArgs[k] = ctx.m_exprIndexToTargetIndex.get(exprArgIndex);
} else {
adviceToTargetArgs[k] = -1;
}
}
// //debug:
// for (int k = 0; k < adviceToTargetArgs.length; k++) {
// int adviceToTargetArg = adviceToTargetArgs[k];
// System.out.println(" " + k + " -> " + adviceToTargetArg);
// }
indexTuple.setMethodToArgIndexes(adviceToTargetArgs);
}
for (int j = 0; j < aroundAdviceIndexes.length; j++) {
AdviceInfo indexTuple = aroundAdviceIndexes[j];
String adviceName = pointcut.getAroundAdviceName(j);
//grab the parameters names
String[] adviceArgNames = JoinPointMetaData.getParameterNames(adviceName);
// map them from the ctx info
int[] adviceToTargetArgs = new int[adviceArgNames.length];
for (int k = 0; k < adviceArgNames.length; k++) {
String adviceArgName = adviceArgNames[k];
int exprArgIndex = pointcut.getExpressionInfo().getArgumentIndex(adviceArgName);
if (exprArgIndex >= 0 && ctx.m_exprIndexToTargetIndex.containsKey(exprArgIndex)) {
adviceToTargetArgs[k] = ctx.m_exprIndexToTargetIndex.get(exprArgIndex);
} else {
adviceToTargetArgs[k] = -1;
}
}
// //debug:
// for (int k = 0; k < adviceToTargetArgs.length; k++) {
// int adviceToTargetArg = adviceToTargetArgs[k];
// System.out.println(" " + k + " -> " + adviceToTargetArg);
// }
indexTuple.setMethodToArgIndexes(adviceToTargetArgs);
}
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