OSDN Git Service

26cf87fefcd2604b669de8e8fc8ec5bb09398fef
[stigmata/stigmata-plugins.git] / opcodes / src / main / java / jp / sourceforge / stigmata / birthmarks / OpcodeExtractVisitor.java
1 package jp.sourceforge.stigmata.birthmarks;
2
3 /*
4  * $Id$
5  */
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import jp.sourceforge.stigmata.Birthmark;
11 import jp.sourceforge.stigmata.BirthmarkContext;
12 import jp.sourceforge.stigmata.BirthmarkElement;
13 import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor;
14
15 import org.objectweb.asm.ClassVisitor;
16 import org.objectweb.asm.MethodVisitor;
17
18 /**
19  *
20  *
21  * @author tamada
22  * @version $Revision$
23  */
24 public class OpcodeExtractVisitor extends BirthmarkExtractVisitor{
25     private List<Opcode> opcodeList = new ArrayList<Opcode>();
26     private BirthmarkElementBuilder builder;
27
28     public OpcodeExtractVisitor(ClassVisitor visitor, Birthmark birthmark, BirthmarkContext context, BirthmarkElementBuilder builder){
29         super(visitor, birthmark, context);
30         this.builder = builder;
31     }
32
33     public void visitEnd(){
34         BirthmarkElement[] elements = builder.buildBirthmarkElements(opcodeList, getContext());
35         for(BirthmarkElement element: elements){
36             addElement(element);
37         }
38     }
39
40     @Override
41     public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4){
42         MethodVisitor visitor = super.visitMethod(arg0, arg1, arg2, arg3, arg4);
43         OpcodeExtractMethodVisitor opcodeVisitor = new OpcodeExtractMethodVisitor(visitor, opcodeList);
44
45         return opcodeVisitor;
46     }
47 }