View Javadoc
1 package net.sf.cglib.transform.impl; 2 3 import net.sf.cglib.transform.*; 4 import net.sf.cglib.core.*; 5 import org.objectweb.asm.ClassVisitor; 6 import org.objectweb.asm.CodeVisitor; 7 import org.objectweb.asm.Attribute; 8 import org.objectweb.asm.Type; 9 10 public class AccessFieldTransformer extends ClassEmitterTransformer { 11 private Callback callback; 12 13 public AccessFieldTransformer(Callback callback) { 14 this.callback = callback; 15 } 16 17 public interface Callback { 18 String getPropertyName(Type owner, String fieldName); 19 } 20 21 public void declare_field(int access, final String name, Type type, Object value, Attribute attrs) { 22 super.declare_field(access, name, type, value, attrs); 23 24 String property = TypeUtils.upperFirst(callback.getPropertyName(getClassType(), name)); 25 if (property != null) { 26 CodeEmitter e; 27 e = begin_method(Constants.ACC_PUBLIC, 28 new Signature("get" + property, 29 type, 30 Constants.TYPES_EMPTY), 31 null, 32 null); 33 e.load_this(); 34 e.getfield(name); 35 e.return_value(); 36 e.end_method(); 37 38 e = begin_method(Constants.ACC_PUBLIC, 39 new Signature("set" + property, 40 Type.VOID_TYPE, 41 new Type[]{ type }), 42 null, 43 null); 44 e.load_this(); 45 e.load_arg(0); 46 e.putfield(name); 47 e.return_value(); 48 e.end_method(); 49 } 50 } 51 }

This page was automatically generated by Maven