1 19 package org.apache.cayenne.enhancer; 20 21 import org.apache.cayenne.ObjectContext; 22 import org.objectweb.asm.Label; 23 import org.objectweb.asm.MethodAdapter; 24 import org.objectweb.asm.MethodVisitor; 25 import org.objectweb.asm.Opcodes; 26 import org.objectweb.asm.Type; 27 28 32 public class GetterVisitor extends MethodAdapter { 33 34 private EnhancementHelper helper; 35 private String propertyName; 36 private boolean lazyFaulting; 37 38 public GetterVisitor(MethodVisitor mv, EnhancementHelper helper, String propertyName, 39 boolean lazyFaulting) { 40 super(mv); 41 this.helper = helper; 42 this.propertyName = propertyName; 43 this.lazyFaulting = lazyFaulting; 44 } 45 46 @Override 47 public void visitCode() { 48 super.visitCode(); 49 50 String field = helper.getPropertyField("objectContext"); 51 Type objectContextType = Type.getType(ObjectContext.class); 52 53 mv.visitVarInsn(Opcodes.ALOAD, 0); 54 mv.visitFieldInsn( 55 Opcodes.GETFIELD, 56 helper.getCurrentClass().getInternalName(), 57 field, 58 objectContextType.getDescriptor()); 59 Label l1 = new Label(); 60 mv.visitJumpInsn(Opcodes.IFNULL, l1); 61 mv.visitVarInsn(Opcodes.ALOAD, 0); 62 mv.visitFieldInsn( 63 Opcodes.GETFIELD, 64 helper.getCurrentClass().getInternalName(), 65 field, 66 objectContextType.getDescriptor()); 67 mv.visitVarInsn(Opcodes.ALOAD, 0); 68 mv.visitLdcInsn(propertyName); 69 mv.visitInsn(lazyFaulting ? Opcodes.ICONST_1 : Opcodes.ICONST_0); 70 mv.visitMethodInsn( 71 Opcodes.INVOKEINTERFACE, 72 objectContextType.getInternalName(), 73 "prepareForAccess", 74 "(Lorg/apache/cayenne/Persistent;Ljava/lang/String;Z)V"); 75 mv.visitLabel(l1); 76 } 77 } 78 | Popular Tags |