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.Attribute; 23 import org.objectweb.util.monolog.api.Logger; 24 import org.objectweb.util.monolog.api.BasicLevel; 25 import org.objectweb.speedo.metadata.SpeedoField; 26 import org.objectweb.speedo.metadata.SpeedoClass; 27 import org.objectweb.speedo.generation.lib.NamingRules; 28 29 import java.util.Set ; 30 import java.util.HashSet ; 31 import java.util.Iterator ; 32 33 41 public class DummyAccessorModifier extends LoggedClassAdapter { 42 43 46 private Set methods; 47 48 public DummyAccessorModifier(ClassVisitor classVisitor, 49 Logger logger, 50 SpeedoClass sc, 51 boolean beforeCompilation) { 52 super(classVisitor, logger); 53 if (!beforeCompilation) { 54 methods = new HashSet (); 55 } 56 Iterator it = sc.jdoField.values().iterator(); 57 while (it.hasNext()) { 58 SpeedoField sf = (SpeedoField) it.next(); 59 String getter = NamingRules.getterName(sc, sf.name); 61 String setter = NamingRules.setterName(sc, sf.name); 62 String coherencesetter = NamingRules.coherentSetterName(sc, sf.name); 63 if (debug) { 64 logger.log(BasicLevel.DEBUG, 65 "DummyAccessor modifier of the class " 66 + sc.getFQName() + ": getter=" + getter); 67 } 68 if (beforeCompilation) { 69 CodeVisitor _cv = this.cv.visitMethod(ACC_PUBLIC, getter, 71 "()" + sf.desc, null, null); 72 _cv.visitInsn(ACONST_NULL); 73 _cv.visitInsn(ARETURN); 74 _cv.visitMaxs(1, 1); 75 _cv = this.cv.visitMethod(ACC_PUBLIC, setter, 77 "(" + sf.desc + ")V", null, null); 78 _cv.visitInsn(RETURN); 79 _cv.visitMaxs(2, 2); 80 _cv = this.cv.visitMethod(ACC_PUBLIC, coherencesetter, 82 "(" + sf.desc + ")V", null, null); 83 _cv.visitInsn(RETURN); 84 _cv.visitMaxs(2, 2); 85 } else { 86 methods.add(getter); 87 methods.add(setter); 88 methods.add(coherencesetter); 89 } 90 } 92 if (methods != null && methods.isEmpty()) { 93 methods = null; 94 } 95 } 96 97 public CodeVisitor visitMethod(int modifier, 98 String methodName, 99 String returnType, 100 String [] paramTypes, 101 Attribute attrs) { 102 if (methods != null && methods.contains(methodName)) { 103 if (debug) { 104 logger.log(BasicLevel.DEBUG, "DummyAccessor.visitMethod(" 105 + methodName + ") return null"); 106 } 107 return null; 109 } else { 110 CodeVisitor _cv = super.visitMethod( 111 modifier, methodName, returnType, paramTypes, attrs); 112 if (debug) { 113 logger.log(BasicLevel.DEBUG, "DummyAccessor.visitMethod(" 114 + methodName + ") return cv=" + _cv); 115 } 116 return _cv; 117 } 118 } 119 } 120 | Popular Tags |