}
}
private void interceptFieldAccess(MethodNode methodNode, Set<MethodNode> unusedAccessMethods)
{
InsnList insns = methodNode.instructions;
ListIterator it = insns.iterator();
while (it.hasNext())
{
AbstractInsnNode node = (AbstractInsnNode) it.next();
int opcode = node.getOpcode();
if (opcode != GETFIELD && opcode != PUTFIELD)
continue;
// Make sure we're talking about access to a field of this class, not some other
// visible field of another class.
FieldInsnNode fnode = (FieldInsnNode) node;
if (!fnode.owner.equals(classNode.name))
continue;
Map<String, MethodNode> fieldToMethod = opcode == GETFIELD ? fieldToReadMethod : fieldToWriteMethod;
MethodNode mn = fieldToMethod.get(fnode.name);
if (mn == null)
continue;
String methodDescription = opcode == GETFIELD ? "()" + fnode.desc : "(" + fnode.desc + ")V";
// Replace the field access node with the appropriate method invocation.
insns.insertBefore(fnode, new MethodInsnNode(INVOKEVIRTUAL, fnode.owner, mn.name, methodDescription));
it.remove();
unusedAccessMethods.remove(mn);
}