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 75 public final class StackMap extends Attribute implements Node { 76 private int map_length; 77 private StackMapEntry[] map; 79 85 public StackMap(int name_index, int length, StackMapEntry[] map, 86 ConstantPool constant_pool) 87 { 88 super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool); 89 90 setStackMap(map); 91 } 92 93 101 StackMap(int name_index, int length, DataInputStream file, 102 ConstantPool constant_pool) throws IOException 103 { 104 this(name_index, length, (StackMapEntry[])null, constant_pool); 105 106 map_length = file.readUnsignedShort(); 107 map = new StackMapEntry[map_length]; 108 109 for(int i=0; i < map_length; i++) 110 map[i] = new StackMapEntry(file, constant_pool); 111 } 112 113 119 public final void dump(DataOutputStream file) throws IOException 120 { 121 super.dump(file); 122 file.writeShort(map_length); 123 for(int i=0; i < map_length; i++) 124 map[i].dump(file); 125 } 126 127 130 public final StackMapEntry[] getStackMap() { return map; } 131 132 135 public final void setStackMap(StackMapEntry[] map) { 136 this.map = map; 137 138 map_length = (map == null)? 0 : map.length; 139 } 140 141 144 public final String toString() { 145 StringBuffer buf = new StringBuffer ("StackMap("); 146 147 for(int i=0; i < map_length; i++) { 148 buf.append(map[i].toString()); 149 150 if(i < map_length - 1) 151 buf.append(", "); 152 } 153 154 buf.append(')'); 155 156 return buf.toString(); 157 } 158 159 162 public Attribute copy(ConstantPool constant_pool) { 163 StackMap c = (StackMap)clone(); 164 165 c.map = new StackMapEntry[map_length]; 166 for(int i=0; i < map_length; i++) 167 c.map[i] = map[i].copy(); 168 169 c.constant_pool = constant_pool; 170 return c; 171 } 172 173 180 public void accept(Visitor v) { 181 v.visitStackMap(this); 182 } 183 184 public final int getMapLength() { return map_length; } 185 } 186 | Popular Tags |