cv.visitLabel(switchCaseLabels[0]);
// add invocations to the before advices
for (int i = 0; i < beforeAdvices.length; i++) {
AdviceInfo beforeAdvice = beforeAdvices[i];
AspectContainer container = beforeAdvice.getAspectManager().getAspectContainer(
beforeAdvice.getAspectIndex());
Method adviceMethod = container.getAdvice(beforeAdvice.getMethodIndex());
String aspectClassName = container.getCrossCuttingInfo().getAspectClass().getName().replace('.', '/');
String aspectFieldName = BEFORE_ADVICE_FIELD_PREFIX + i;
String aspectClassSignature = L + aspectClassName + SEMICOLON;
// handles advice with signature for args() support
// JoinPoint as sole arg or:
// this.getRtti().getParametersValues()[<index>], unwrap if primitive type
int[] argIndexes = beforeAdvice.getMethodToArgIndexes();
// if no arg or only JoinPoint, we consider for now that we have to push JoinPoint for old advice with JoinPoint as sole arg
if (isAdviceArgsJoinPointOnly(argIndexes)) {
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitFieldInsn(Constants.GETFIELD, className, aspectFieldName, aspectClassSignature);
cv.visitVarInsn(Constants.ALOAD, 0);
} else {
Type[] adviceArgTypes = Type.getArgumentTypes(adviceMethod);
// this.getRtti().getParameterValues() (array, store in register 2)
prepareParameterUnwrapping(joinPointType, adviceArgTypes, cv, className);
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitFieldInsn(Constants.GETFIELD, className, aspectFieldName, aspectClassSignature);
for (int j = 0; j < argIndexes.length; j++) {
int argIndex = argIndexes[j];
if (argIndex != -1) {
Type argumentType = adviceArgTypes[j];
cv.visitVarInsn(Constants.ALOAD, 2);//the param array
AsmHelper.loadConstant(cv, argIndex);//index
cv.visitInsn(Constants.AALOAD);
unwrapParameter(argumentType, cv);//unwrap
} else {
// assume JoinPoint - TODO support for static part optimization
cv.visitVarInsn(Constants.ALOAD, 0);
}
}
}
cv.visitMethodInsn(
Constants.INVOKEVIRTUAL,
aspectClassName,
adviceMethod.getName(),
Type.getMethodDescriptor(adviceMethod));
}
// add invocation to this.proceed
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitMethodInsn(Constants.INVOKEVIRTUAL, className, PROCEED_METHOD_NAME, PROCEED_METHOD_SIGNATURE);
cv.visitVarInsn(Constants.ASTORE, 1);
// add invocations to the after advices
for (int i = afterAdvices.length - 1; i >= 0; i--) {
AdviceInfo afterAdvice = afterAdvices[i];
AspectContainer container = afterAdvice.getAspectManager().getAspectContainer(
afterAdvice.getAspectIndex());
Method adviceMethod = container.getAdvice(afterAdvice.getMethodIndex());
String aspectClassName = container.getCrossCuttingInfo().getAspectClass().getName().replace('.', '/');
String aspectFieldName = AFTER_ADVICE_FIELD_PREFIX + i;
String aspectClassSignature = L + aspectClassName + SEMICOLON;
// handles advice with signature for args() support
// JoinPoint as sole arg or:
// this.getRtti().getParametersValues()[<index>], unwrap if primitive type