Coverage Report - org.boretti.drools.integration.drools4.DroolsAddConstructorMethodVisitor
 
Classes in this File Line Coverage Branch Coverage Complexity
DroolsAddConstructorMethodVisitor
0 %
0/20
N/A
1
 
 1  
 /*
 2  
     Drools4 Integration Helper
 3  
     Copyright (C) 2009  Mathieu Boretti mathieu.boretti@gmail.com
 4  
 
 5  
     This program is free software: you can redistribute it and/or modify
 6  
     it under the terms of the GNU General Public License as published by
 7  
     the Free Software Foundation, either version 3 of the License, or
 8  
     (at your option) any later version.
 9  
 
 10  
     This program is distributed in the hope that it will be useful,
 11  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
     GNU General Public License for more details.
 14  
 
 15  
     You should have received a copy of the GNU General Public License
 16  
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 17  
 
 18  
  */
 19  
 package org.boretti.drools.integration.drools4;
 20  
 
 21  
 import org.drools.RuleBase;
 22  
 import org.objectweb.asm.MethodVisitor;
 23  
 import org.objectweb.asm.commons.AdviceAdapter;
 24  
 import org.objectweb.asm.Opcodes;
 25  
 import org.objectweb.asm.Type;
 26  
 
 27  
 /**
 28  
  * @author mbo
 29  
  * @since 1.1.0
 30  
  */
 31  
 class DroolsAddConstructorMethodVisitor extends AdviceAdapter {
 32  
         
 33  
         private String parent;
 34  
                         
 35  
         private String droolsName;
 36  
         
 37  
         private String droolsRule;
 38  
 
 39  
         public DroolsAddConstructorMethodVisitor(
 40  
                         MethodVisitor mv, 
 41  
                         int access,
 42  
                         String name, 
 43  
                         String desc,
 44  
                         String parent,
 45  
                         String droolsName,
 46  
                         String droolsRule) {
 47  0
                 super(mv, access, name, desc);
 48  0
                 this.parent=parent;
 49  0
                 this.droolsName=droolsName;
 50  0
                 this.droolsRule=droolsRule;
 51  0
         }
 52  
 
 53  
         /* (non-Javadoc)
 54  
          * @see org.objectweb.asm.commons.AdviceAdapter#onMethodEnter()
 55  
          */
 56  
         @Override
 57  
         protected void onMethodEnter() {
 58  0
                 this.visitVarInsn(Opcodes.ALOAD,0);
 59  0
                 this.visitInsn(Opcodes.DUP);
 60  0
                 this.visitInsn(Opcodes.DUP);
 61  0
                 this.visitInsn(Opcodes.ICONST_0);
 62  0
                 this.visitFieldInsn(Opcodes.PUTFIELD,Type.getObjectType(parent).getInternalName(), droolsName, Type.BOOLEAN_TYPE.getDescriptor());
 63  0
                 this.visitTypeInsn(Opcodes.NEW,Type.getType(DroolsProvider.class).getInternalName());
 64  0
                 this.visitInsn(Opcodes.DUP);                
 65  0
                 this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getType(DroolsProvider.class).getInternalName(), "<init>","()V");
 66  0
                 this.visitInsn(Opcodes.SWAP);
 67  0
                 this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getObjectType(parent).getInternalName(), "getClass", "()Ljava/lang/Class;");
 68  0
                 this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getType(DroolsProvider.class).getInternalName(), "getRuleBase","(Ljava/lang/Class;)Lorg/drools/RuleBase;");
 69  0
                 this.visitFieldInsn(Opcodes.PUTFIELD,Type.getObjectType(parent).getInternalName(), droolsRule, Type.getType(RuleBase.class).getDescriptor());
 70  0
         }
 71  
 
 72  
 
 73  
         @Override
 74  
         public void visitMaxs(int maxStack, int maxLocals) {
 75  0
                 super.visitMaxs(maxStack+4, maxLocals);
 76  0
         }
 77  
 
 78  
 }