OSDN Git Service

initial version (daily commit), not work yet
[stigmata/stigmata-plugins.git] / wsp / src / main / java / jp / sourceforge / stigmata / birthmarks / wsp / Opcode.java
1 package jp.sourceforge.stigmata.birthmarks.wsp;
2
3 /*
4  * $Id$
5  */
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collections;
10 import java.util.Iterator;
11 import java.util.List;
12
13 import org.objectweb.asm.Label;
14
15 /**
16  * 
17  * @author Haruaki Tamada
18  * @version $Revision$
19  */
20 public class Opcode implements Serializable{
21     private static final long serialVersionUID = -2349834745416345564L;
22
23     public static enum Category{
24         NORMAL, BRANCH, OBJECT, INVOKE, TARGETER,
25     };
26     private int opcode;
27     private String name;
28     private int argumentCount;
29     private int act;
30     private Category category;
31     private List<Label> labels = new ArrayList<Label>();
32
33     public Opcode(Opcode opcode){
34         this(opcode.getOpcode(), opcode.getName(), opcode.getArgumentCount(), opcode.getAct(), opcode.getCategory());
35     }
36
37     public Opcode(int opcode, String name, int argumentCount, int act, String category){
38         this(opcode, name, argumentCount, act, Category.valueOf(category));
39     }
40
41     public Opcode(int opcode, String name, int argumentCount, int act, Category category){
42         this.opcode = opcode;
43         this.name = name;
44         this.argumentCount = argumentCount;
45         this.act = act;
46         this.category = category;
47     }
48
49     public int getOpcode(){
50         return opcode;
51     }
52
53     public String getName(){
54         return name;
55     }
56
57     public int getArgumentCount(){
58         return argumentCount;
59     }
60
61     public void addLabel(Label label){
62         if(category != Category.BRANCH){
63             throw new IllegalStateException("this method allows only branch category");
64         }
65         labels.add(label);
66     }
67
68     public void setLabels(Label[] labelArray){
69         if(category != Category.BRANCH){
70             throw new IllegalStateException("this method allows only branch category");
71         }
72         for(Label label: labelArray){
73             labels.add(label);
74         }
75     }
76
77     public Iterator<Label> labels(){
78         return Collections.unmodifiableList(labels).iterator();
79     }
80
81     public void setAct(int act){
82         if(category != Category.OBJECT && category != Category.INVOKE){
83             throw new IllegalStateException("setAct can be called only object and invoke category.");
84         }
85         this.act = act;
86     }
87
88     public int getAct(){
89         return act;
90     }
91
92     public Category getCategory(){
93         return category;
94     }
95 }