package net.sf.cglib.transform;

import net.sf.cglib.core.*;
import net.sf.cglib.core.Signature;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Type;

public class AccessFieldTransformer extends EmittingTransformer {
    private Callback callback;

    public AccessFieldTransformer(Callback callback) {
        this.callback = callback;
    }

    public interface Callback {
        String getPropertyName(Type owner, String fieldName);
    }

    protected Emitter getEmitter(ClassVisitor cv) {
        return new Emitter(cv) {
            public void declare_field(int access, String name, Type type, Object value) {
                super.declare_field(access, name, type, value);

                String property = callback.getPropertyName(getClassType(), name);
                begin_method(Constants.ACC_PUBLIC,
                             new Signature("get" + property,
                                           type,
                                           Constants.TYPES_EMPTY),
                             null);
                load_this();
                getfield(name);
                return_value();

                begin_method(Constants.ACC_PUBLIC,
                             new Signature("set" + property,
                                           Type.VOID_TYPE,
                                           new Type[]{ type }),
                             null);
                load_this();
                load_arg(0);
                putfield(name);
                return_value();
            }
        };
    }
}

@@ -774,24 +774,68 @@
 e(), name);%0A
+                if (property != null) %7B%0A    
             
@@ -865,32 +865,36 @@
 nts.ACC_PUBLIC,%0A
+    
                 
@@ -985,14 +985,22 @@
     
+    
 type,%0A
+    
     
@@ -1083,32 +1083,36 @@
                 
+    
 null);%0A         
@@ -1110,32 +1110,36 @@
                 
+   
+ 
 load_this();%0A   
@@ -1127,32 +1127,36 @@
    load_this();%0A
+    
                 
@@ -1179,32 +1179,36 @@
                 
+   
+ 
 return_value();%0A
@@ -1204,24 +1204,28 @@
 n_value();%0A%0A
+    
             
@@ -1284,32 +1284,36 @@
                 
+   
+ 
 new Signature(%22s
@@ -1371,16 +1371,20 @@
         
+    
 Type.VOI
@@ -1430,24 +1430,28 @@
             
+   
+ 
 new Type%5B%5D%7B 
@@ -1480,32 +1480,36 @@
                 
+    
 null);%0A         
@@ -1507,32 +1507,36 @@
                 
+   
+ 
 load_this();%0A   
@@ -1524,32 +1524,36 @@
    load_this();%0A
+    
                 
@@ -1581,16 +1581,20 @@
         
+   
+ 
 putfield
@@ -1609,32 +1609,36 @@
                 
+    
 return_value();%0A
@@ -1633,24 +1633,42 @@
 rn_value();%0A
+                %7D%0A
             

make callback work as filter too