final String signature,
final Object value)
{
FieldVisitor fv = super.visitField(access, name, desc, signature, value);
if ((access & ACC_STATIC) == 0) {
Type t = Type.getType(desc);
int size = t.getSize();
// generates getter method
String gDesc = "()" + desc;
MethodVisitor gv = cv.visitMethod(ACC_PRIVATE,
"_get" + name,
gDesc,
null,
null);
gv.visitFieldInsn(GETSTATIC,
"java/lang/System",
"err",
"Ljava/io/PrintStream;");
gv.visitLdcInsn("_get" + name + " called");
gv.visitMethodInsn(INVOKEVIRTUAL,
"java/io/PrintStream",
"println",
"(Ljava/lang/String;)V");
gv.visitVarInsn(ALOAD, 0);
gv.visitFieldInsn(GETFIELD, owner, name, desc);
gv.visitInsn(t.getOpcode(IRETURN));
gv.visitMaxs(1 + size, 1);
gv.visitEnd();
// generates setter method
String sDesc = "(" + desc + ")V";
MethodVisitor sv = cv.visitMethod(ACC_PRIVATE,
"_set" + name,
sDesc,
null,
null);
sv.visitFieldInsn(GETSTATIC,
"java/lang/System",
"err",
"Ljava/io/PrintStream;");
sv.visitLdcInsn("_set" + name + " called");
sv.visitMethodInsn(INVOKEVIRTUAL,
"java/io/PrintStream",
"println",
"(Ljava/lang/String;)V");
sv.visitVarInsn(ALOAD, 0);
sv.visitVarInsn(t.getOpcode(ILOAD), 1);
sv.visitFieldInsn(PUTFIELD, owner, name, desc);
sv.visitInsn(RETURN);
sv.visitMaxs(1 + size, 1 + size);
sv.visitEnd();
}