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