| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 
 | void createSetter (String propertyName, String type, Class c) {
  String methodName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
  MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "(" + type + ")V", null, null);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitVarInsn(Type.getType(c).getOpcode(ILOAD, 1));
  mv.visitFieldInsn(PUTFIELD, className, propertyName, type);
  mv.visitInsn(RETURN);
  mv.visitMaxs(0, 0);
}
 
void createGetter (String propertyName, String returnType, Class c) {
  String methodName = "get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
  MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "()" + returnType, null, null);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitFieldInsn(GETFIELD, internalClassName, propertyName, returnType);
  mv.visitInsn(Type.getType(c).getOpcode(IRETURN));
  mv.visitMaxs(0, 0);
} | 
Partager