1 package com.sun.org.apache.bcel.internal.classfile; 2 3 56 57 import com.sun.org.apache.bcel.internal.Constants; 58 import java.io.*; 59 60 70 public final class StackMapType implements Cloneable { 71 private byte type; 72 private int index = -1; private ConstantPool constant_pool; 74 75 80 StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException 81 { 82 this(file.readByte(), -1, constant_pool); 83 84 if(hasIndex()) 85 setIndex(file.readShort()); 86 87 setConstantPool(constant_pool); 88 } 89 90 94 public StackMapType(byte type, int index, ConstantPool constant_pool) { 95 setType(type); 96 setIndex(index); 97 setConstantPool(constant_pool); 98 } 99 100 public void setType(byte t) { 101 if((t < Constants.ITEM_Bogus) || (t > Constants.ITEM_NewObject)) 102 throw new RuntimeException ("Illegal type for StackMapType: " + t); 103 type = t; 104 } 105 106 public byte getType() { return type; } 107 public void setIndex(int t) { index = t; } 108 109 112 public int getIndex() { return index; } 113 114 120 public final void dump(DataOutputStream file) throws IOException 121 { 122 file.writeByte(type); 123 if(hasIndex()) 124 file.writeShort(getIndex()); 125 } 126 127 129 public final boolean hasIndex() { 130 return ((type == Constants.ITEM_Object) || 131 (type == Constants.ITEM_NewObject)); 132 } 133 134 private String printIndex() { 135 if(type == Constants.ITEM_Object) 136 return ", class=" + constant_pool.constantToString(index, Constants.CONSTANT_Class); 137 else if(type == Constants.ITEM_NewObject) 138 return ", offset=" + index; 139 else 140 return ""; 141 } 142 143 146 public final String toString() { 147 return "(type=" + Constants.ITEM_NAMES[type] + printIndex() + ")"; 148 } 149 150 153 public StackMapType copy() { 154 try { 155 return (StackMapType)clone(); 156 } catch(CloneNotSupportedException e) {} 157 158 return null; 159 } 160 161 164 public final ConstantPool getConstantPool() { return constant_pool; } 165 166 169 public final void setConstantPool(ConstantPool constant_pool) { 170 this.constant_pool = constant_pool; 171 } 172 } 173 | Popular Tags |