1 27 package org.objectweb.speedo.generation.enhancer; 28 29 import org.objectweb.asm.Attribute; 30 import org.objectweb.asm.ClassVisitor; 31 import org.objectweb.asm.CodeVisitor; 32 import org.objectweb.asm.Constants; 33 import org.objectweb.asm.Type; 34 import org.objectweb.util.monolog.api.Logger; 35 36 import java.util.List ; 37 38 public class MergedClassModifier extends LoggedClassAdapter { 39 40 private List itfs; 41 42 private String persistenceCapableSuperClass; 43 44 private boolean fixProxyMethodOverriding; 45 46 public MergedClassModifier(ClassVisitor classVisitor, 47 List itfs, 48 Logger logger) { 49 super(classVisitor, logger); 50 this.itfs = itfs; 51 this.fixProxyMethodOverriding = false; 52 } 53 54 public MergedClassModifier(ClassVisitor classVisitor, 55 List itfs, 56 String persistenceCapableSuperClass, 57 Logger logger) { 58 super(classVisitor, logger); 59 this.itfs = itfs; 60 this.fixProxyMethodOverriding = false; 61 this.persistenceCapableSuperClass = persistenceCapableSuperClass; 62 } 63 64 67 public void visit(final int version, final int access, 68 final String name, 69 final String superName, 70 final String [] interfaces, 71 final String sourceFile) { 72 if (interfaces != null) { 74 for (int i = 0; i < interfaces.length; ++i) { 75 if (!itfs.contains(interfaces[i])) { 76 itfs.add(interfaces[i]); 77 } 78 } 79 } 80 } 81 82 public CodeVisitor visitMethod(final int access, 83 final String name, 84 final String desc, 85 final String [] exceptions, 86 final Attribute attrs) { 87 if ((access & Constants.ACC_ABSTRACT) != 0 88 || name.equals("<init>") 89 || name.equals("this")) { 90 return null; 92 } else { 93 CodeVisitor c = cv.visitMethod(access, name, desc, exceptions, attrs); 94 if (fixProxyMethodOverriding 95 && (name.equals("jdoLoadFieldsInAccessor") 96 || name.equals("jdoLoadFieldsFromAccessor") 97 || name.equals("jdoMakePersistent") 98 || name.equals("jdoLoadFields") 99 )) { 100 int off = 1; 101 c.visitVarInsn(Constants.ALOAD, 0); 102 Type[] args = Type.getArgumentTypes(desc); 103 for (int i = 0; i < args.length; ++i) { 104 c.visitVarInsn(args[i].getOpcode(Constants.ILOAD), off); 105 off += args[i].getSize(); 106 } 107 c.visitMethodInsn(Constants.INVOKESPECIAL, 108 persistenceCapableSuperClass, name, desc); 109 } 110 return c; 111 } 112 } 113 114 public void visitEnd() { 115 } 117 } 118 | Popular Tags |