Type fieldType = Type.getType(fieldDesc);
int joinPointHash = AsmHelper.calculateFieldHash(fieldName, fieldDesc);
ClassInfo classInfo = AsmClassInfo.getClassInfo(className.replace('/', '.'), m_loader);
FieldInfo fieldInfo = getFieldInfo(classInfo, className, fieldName, fieldDesc, joinPointHash);
if (opcode == PUTFIELD || opcode == PUTSTATIC) {
ExpressionContext ctx = new ExpressionContext(PointcutType.SET, fieldInfo, m_callerMethodInfo);
if (fieldFilter(m_ctx.getDefinitions(), ctx, fieldInfo)) {
super.visitFieldInsn(opcode, className, fieldName, fieldDesc);
} else {
m_ctx.markAsAdvised();
m_sequence++; // single place of incrementation, is used in multiple places
createPutFieldWrapperMethod((opcode==PUTSTATIC), fieldName, fieldDesc);
String joinPointClassName = JoinPointCompiler.getJoinPointClassName(
m_callerClassName,
JoinPointType.FIELD_SET,
joinPointHash
);
// load the caller instance (this), or null if in a static context
// note that callee instance [optional] and args are already on the stack
if (Modifier.isStatic(m_callerMethodInfo.getModifiers())) {
visitInsn(ACONST_NULL);
} else {
visitVarInsn(ALOAD, 0);
}
// add the call to the join point
super.visitMethodInsn(
INVOKESTATIC,
joinPointClassName,
INVOKE_METHOD_NAME,
TransformationUtil.getInvokeSignatureForFieldJoinPoints(
fieldInfo.getModifiers(), fieldDesc, m_callerClassName, className
)
);
super.visitInsn(POP);// field is set by the JP
// emit the joinpoint
m_ctx.addEmittedInlinedJoinPoint(
new ContextImpl.EmittedInlinedJoinPoint(
JoinPointType.FIELD_SET,
m_callerClassName,
m_callerMethodName,
m_callerMethodDesc,
m_callerMethodInfo.getModifiers(),
className,
fieldName,
fieldDesc,
fieldInfo.getModifiers(),
m_sequence,
joinPointHash,
joinPointClassName
)
);
}
} else if (opcode == GETFIELD || opcode == GETSTATIC) {
ExpressionContext ctx = new ExpressionContext(PointcutType.GET, fieldInfo, m_callerMethodInfo);
if (fieldFilter(m_ctx.getDefinitions(), ctx, fieldInfo)) {
super.visitFieldInsn(opcode, className, fieldName, fieldDesc);
} else {
m_ctx.markAsAdvised();
m_sequence++; // single place of incrementation, is used in multiple places
createGetFieldWrapperMethod((opcode==GETSTATIC), fieldName, fieldDesc);
String joinPointClassName = JoinPointCompiler.getJoinPointClassName(
m_callerClassName,
JoinPointType.FIELD_GET,
joinPointHash
);
// if static context pop the 'this' instance and load NULL
if (Modifier.isStatic(m_callerMethodInfo.getModifiers())) {
visitInsn(ACONST_NULL);
}
// no param to field, so pass a default value to the invoke method
AsmHelper.addDefaultValue(this, fieldType);
// if static context load NULL else 'this'
if (Modifier.isStatic(m_callerMethodInfo.getModifiers())) {
visitInsn(ACONST_NULL);
} else {
visitVarInsn(ALOAD, 0);
}
// add the call to the join point
super.visitMethodInsn(
INVOKESTATIC,
joinPointClassName,
INVOKE_METHOD_NAME,
TransformationUtil.getInvokeSignatureForFieldJoinPoints(
fieldInfo.getModifiers(), fieldDesc, m_callerClassName, className
)
);
//super.visitInsn(POP);//pop the field value returned from jp.invoke for now
// emit the joinpoint
m_ctx.addEmittedInlinedJoinPoint(
new ContextImpl.EmittedInlinedJoinPoint(
JoinPointType.FIELD_GET,
m_callerClassName,
m_callerMethodName,
m_callerMethodDesc,
m_callerMethodInfo.getModifiers(),
className,
fieldName,
fieldDesc,
fieldInfo.getModifiers(),
m_sequence,
joinPointHash,
joinPointClassName
)
);