1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import org.apache.bcel.Constants; 23 24 34 public final class StackMapType implements Cloneable { 35 36 private byte type; 37 private int index = -1; private ConstantPool constant_pool; 39 40 41 46 StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException { 47 this(file.readByte(), -1, constant_pool); 48 if (hasIndex()) { 49 setIndex(file.readShort()); 50 } 51 setConstantPool(constant_pool); 52 } 53 54 55 59 public StackMapType(byte type, int index, ConstantPool constant_pool) { 60 setType(type); 61 setIndex(index); 62 setConstantPool(constant_pool); 63 } 64 65 66 public void setType( byte t ) { 67 if ((t < Constants.ITEM_Bogus) || (t > Constants.ITEM_NewObject)) { 68 throw new RuntimeException ("Illegal type for StackMapType: " + t); 69 } 70 type = t; 71 } 72 73 74 public byte getType() { 75 return type; 76 } 77 78 79 public void setIndex( int t ) { 80 index = t; 81 } 82 83 84 87 public int getIndex() { 88 return index; 89 } 90 91 92 98 public final void dump( DataOutputStream file ) throws IOException { 99 file.writeByte(type); 100 if (hasIndex()) { 101 file.writeShort(getIndex()); 102 } 103 } 104 105 106 108 public final boolean hasIndex() { 109 return ((type == Constants.ITEM_Object) || (type == Constants.ITEM_NewObject)); 110 } 111 112 113 private String printIndex() { 114 if (type == Constants.ITEM_Object) { 115 if (index < 0) { 116 return ", class=<unknown>"; 117 } 118 return ", class=" + constant_pool.constantToString(index, Constants.CONSTANT_Class); 119 } else if (type == Constants.ITEM_NewObject) { 120 return ", offset=" + index; 121 } else { 122 return ""; 123 } 124 } 125 126 127 130 public final String toString() { 131 return "(type=" + Constants.ITEM_NAMES[type] + printIndex() + ")"; 132 } 133 134 135 138 public StackMapType copy() { 139 try { 140 return (StackMapType) clone(); 141 } catch (CloneNotSupportedException e) { 142 } 143 return null; 144 } 145 146 147 150 public final ConstantPool getConstantPool() { 151 return constant_pool; 152 } 153 154 155 158 public final void setConstantPool( ConstantPool constant_pool ) { 159 this.constant_pool = constant_pool; 160 } 161 } 162 | Popular Tags |