1 package jp.sourceforge.stigmata.birthmarks;
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;
13 import org.objectweb.asm.Label;
17 * @author Haruaki Tamada
20 public class Opcode implements Serializable{
21 private static final long serialVersionUID = -2349834745416345564L;
23 public static enum Category{
24 NORMAL, BRANCH, OBJECT, INVOKE, TARGETER,
28 private int argumentCount;
30 private Category category;
31 private List<Label> labels = new ArrayList<Label>();
33 public Opcode(Opcode opcode){
34 this(opcode.getOpcode(), opcode.getName(), opcode.getArgumentCount(), opcode.getAct(), opcode.getCategory());
37 public Opcode(int opcode, String name, int argumentCount, int act, String category){
38 this(opcode, name, argumentCount, act, Category.valueOf(category));
41 public Opcode(int opcode, String name, int argumentCount, int act, Category category){
44 this.argumentCount = argumentCount;
46 this.category = category;
49 public int getOpcode(){
53 public String getName(){
57 public int getArgumentCount(){
61 public void addLabel(Label label){
63 throw new NullPointerException();
65 if(category != Category.BRANCH){
66 throw new IllegalStateException("this method allows only branch category");
71 public void setLabels(Label[] labelArray){
72 if(labelArray == null){
73 throw new NullPointerException();
75 if(category != Category.BRANCH){
76 throw new IllegalStateException("this method allows only branch category");
79 for(Label label: labelArray){
81 throw new NullPointerException();
87 public Label getLabel(int index){
88 return labels.get(index);
91 public Iterator<Label> labels(){
92 return Collections.unmodifiableList(labels).iterator();
95 public void setAct(int act){
96 if(category != Category.OBJECT && category != Category.INVOKE){
97 throw new IllegalStateException("setAct can be called only object and invoke category.");
106 public Category getCategory(){
110 public String toString(){
111 return String.format("%d:%s:%f(%s)", getOpcode(), getName(), getAct(), getCategory());