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 39 public final class StackMap extends Attribute implements Node { 40 41 private int map_length; 42 private StackMapEntry[] map; 44 45 51 public StackMap(int name_index, int length, StackMapEntry[] map, ConstantPool constant_pool) { 52 super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool); 53 setStackMap(map); 54 } 55 56 57 65 StackMap(int name_index, int length, DataInputStream file, ConstantPool constant_pool) 66 throws IOException { 67 this(name_index, length, (StackMapEntry[]) null, constant_pool); 68 map_length = file.readUnsignedShort(); 69 map = new StackMapEntry[map_length]; 70 for (int i = 0; i < map_length; i++) { 71 map[i] = new StackMapEntry(file, constant_pool); 72 } 73 } 74 75 76 82 public final void dump( DataOutputStream file ) throws IOException { 83 super.dump(file); 84 file.writeShort(map_length); 85 for (int i = 0; i < map_length; i++) { 86 map[i].dump(file); 87 } 88 } 89 90 91 94 public final StackMapEntry[] getStackMap() { 95 return map; 96 } 97 98 99 102 public final void setStackMap( StackMapEntry[] map ) { 103 this.map = map; 104 map_length = (map == null) ? 0 : map.length; 105 } 106 107 108 111 public final String toString() { 112 StringBuffer buf = new StringBuffer ("StackMap("); 113 for (int i = 0; i < map_length; i++) { 114 buf.append(map[i].toString()); 115 if (i < map_length - 1) { 116 buf.append(", "); 117 } 118 } 119 buf.append(')'); 120 return buf.toString(); 121 } 122 123 124 127 public Attribute copy( ConstantPool _constant_pool ) { 128 StackMap c = (StackMap) clone(); 129 c.map = new StackMapEntry[map_length]; 130 for (int i = 0; i < map_length; i++) { 131 c.map[i] = map[i].copy(); 132 } 133 c.constant_pool = _constant_pool; 134 return c; 135 } 136 137 138 145 public void accept( Visitor v ) { 146 v.visitStackMap(this); 147 } 148 149 150 public final int getMapLength() { 151 return map_length; 152 } 153 } 154 | Popular Tags |