001package io.ebean.enhance.querybean; 002 003import io.ebean.enhance.asm.ClassVisitor; 004import io.ebean.enhance.asm.Label; 005import io.ebean.enhance.asm.Opcodes; 006 007import static io.ebean.enhance.common.EnhanceConstants.INIT; 008import static io.ebean.enhance.common.EnhanceConstants.L_OBJECT; 009import static io.ebean.enhance.common.EnhanceConstants.L_STRING; 010 011/** 012 * Changes the existing constructor to remove all the field initialisation as these are going to be 013 * initialised lazily by calls to our generated methods. 014 */ 015public class TypeQueryAssocBasicConstructor extends BaseConstructorAdapter implements Opcodes, Constants { 016 017 private final ClassInfo classInfo; 018 private final ClassVisitor cv; 019 private final String superName; 020 private final String desc; 021 private final String signature; 022 023 /** 024 * Construct for a query bean class given its associated entity bean domain class and a class visitor. 025 */ 026 public TypeQueryAssocBasicConstructor(String superName, ClassInfo classInfo, ClassVisitor cv, String desc, String signature) { 027 super(); 028 this.superName = superName; 029 this.cv = cv; 030 this.classInfo = classInfo; 031 this.desc = desc; 032 this.signature = signature; 033 } 034 035 @Override 036 public void visitCode() { 037 mv = cv.visitMethod(ACC_PUBLIC, INIT, desc, signature, null); 038 mv.visitCode(); 039 Label l0 = new Label(); 040 mv.visitLabel(l0); 041 mv.visitLineNumber(1, l0); 042 mv.visitVarInsn(ALOAD, 0); 043 mv.visitVarInsn(ALOAD, 1); 044 mv.visitVarInsn(ALOAD, 2); 045 mv.visitInsn(ACONST_NULL); 046 mv.visitMethodInsn(INVOKESPECIAL, superName, INIT, "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V", false); 047 Label l1 = new Label(); 048 mv.visitLabel(l1); 049 mv.visitLineNumber(2, l1); 050 mv.visitInsn(RETURN); 051 Label l2 = new Label(); 052 mv.visitLabel(l2); 053 mv.visitLocalVariable("this", "L" + classInfo.getClassName() + ";", "L" + classInfo.getClassName() + "<TR;>;", l0, l2, 0); 054 mv.visitLocalVariable("name", L_STRING, null, l0, l2, 1); 055 mv.visitLocalVariable("root", L_OBJECT, "TR;", l0, l2, 2); 056 mv.visitLocalVariable("depth", "I", null, l0, l2, 3); 057 mv.visitMaxs(4, 4); 058 mv.visitEnd(); 059 } 060 061}