1 18 package org.objectweb.speedo.generation.enhancer; 19 20 import org.objectweb.asm.ClassVisitor; 21 import org.objectweb.asm.CodeVisitor; 22 import org.objectweb.asm.Constants; 23 import org.objectweb.asm.Attribute; 24 import org.objectweb.util.monolog.api.Logger; 25 import org.objectweb.speedo.metadata.SpeedoClass; 26 27 33 public class EmptyConstructorAdder extends LoggedClassAdapter { 34 35 42 byte status = 0; 43 44 public EmptyConstructorAdder(ClassVisitor classVisitor, byte status) { 45 super(classVisitor); 46 this.status = status; 47 } 48 49 public EmptyConstructorAdder(ClassVisitor classVisitor, Logger logger, byte status) { 50 super(classVisitor, logger); 51 this.status = status; 52 } 53 54 public void visit(final int version, final int access, 55 final String name, 56 final String superName, 57 final String [] interfaces, 58 final String sourceFile) { 59 cv.visit(version, access, name, superName, interfaces, sourceFile); 60 if (status == SpeedoClass.NO_NO_ARG_CONSTRUCTOR) { 62 CodeVisitor _cv = this.cv.visitMethod( 63 Constants.ACC_PUBLIC, "<init>", "()V", null, null); 64 _cv.visitVarInsn(Constants.ALOAD, 0); 65 _cv.visitMethodInsn(Constants.INVOKESPECIAL, superName, "<init>", "()V"); 66 _cv.visitInsn(Constants.RETURN); 67 _cv.visitMaxs(1, 1); 68 } 69 } 70 71 public CodeVisitor visitMethod(final int access, 72 final String name, 73 final String desc, 74 final String [] exceptions, 75 final Attribute attrs) { 76 int newaccess = access; 77 if (status == SpeedoClass.NON_PUBLIC_NO_ARG_CONSTRUCTOR 79 && name.equals("<init>") 80 && desc.equals("()V")) { 81 newaccess = Constants.ACC_PUBLIC; 82 } 83 return super.visitMethod(newaccess, name, desc, exceptions, attrs); 84 } 85 } 86 | Popular Tags |