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 the _ebean_newInstance() method. 011 */ 012public class MethodNewInstance { 013 014 /** 015 * Add the _ebean_newInstance() method. 016 */ 017 public static void addMethod(ClassVisitor cv, ClassMeta classMeta) { 018 019 MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_ebean_newInstance", "()Ljava/lang/Object;", null, null); 020 mv.visitCode(); 021 Label l0 = new Label(); 022 mv.visitLabel(l0); 023 mv.visitLineNumber(10, l0); 024 mv.visitTypeInsn(Opcodes.NEW, classMeta.getClassName()); 025 mv.visitInsn(Opcodes.DUP); 026 mv.visitMethodInsn(Opcodes.INVOKESPECIAL, classMeta.getClassName(), "<init>", "()V", false); 027 mv.visitInsn(Opcodes.ARETURN); 028 029 Label l1 = new Label(); 030 mv.visitLabel(l1); 031 mv.visitLocalVariable("this", "L" + classMeta.getClassName() + ";", null, l0, l1, 0); 032 mv.visitMaxs(2, 1); 033 mv.visitEnd(); 034 } 035}