001package io.ebean.enhance.entity; 002 003import io.ebean.enhance.asm.ClassVisitor; 004import io.ebean.enhance.asm.Label; 005import io.ebean.enhance.asm.MethodVisitor; 006import io.ebean.enhance.asm.Opcodes; 007import io.ebean.enhance.common.ClassMeta; 008 009/** 010 * Adds a default constructor for the cases when there is not one already defined. 011 */ 012public class DefaultConstructor { 013 014 /** 015 * Adds a default constructor. 016 */ 017 public static void add(ClassVisitor cw, ClassMeta classMeta) { 018 019 if (classMeta.isLog(3)) { 020 classMeta.log("... adding default constructor, super class: "+classMeta.getSuperClassName()); 021 } 022 023 MethodVisitor underlyingMV = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); 024 025 ConstructorAdapter mv = new ConstructorAdapter(underlyingMV, classMeta, "()V"); 026 027 mv.visitCode(); 028 Label l0 = new Label(); 029 mv.visitLabel(l0); 030 mv.visitLineNumber(1, l0); 031 mv.visitVarInsn(Opcodes.ALOAD, 0); 032 mv.visitMethodInsn(Opcodes.INVOKESPECIAL, classMeta.getSuperClassName(), "<init>", "()V", false); 033 Label l1 = new Label(); 034 mv.visitLabel(l1); 035 mv.visitLineNumber(2, l1); 036 mv.visitInsn(Opcodes.RETURN); 037 038 Label l2 = new Label(); 039 mv.visitLabel(l2); 040 mv.visitLocalVariable("this", "L"+classMeta.getClassName()+";", null, l0, l2, 0); 041 mv.visitMaxs(1, 1); 042 mv.visitEnd(); 043 } 044}