1 package gnu.bytecode; 2 import java.io.*; 3 4 8 9 public class ExceptionsAttr extends Attribute 10 { 11 ClassType[] exceptions; 13 short[] exception_table; 15 16 17 public ExceptionsAttr(Method meth) 18 { 19 super("Exceptions"); 20 addToFrontOf(meth); 21 } 22 23 25 public void setExceptions (short[] indices, ClassType cl) 26 { 27 exception_table = indices; 28 exceptions = new ClassType[indices.length]; 29 ConstantPool cp = cl.getConstants (); 30 for (int i = indices.length - 1; i >= 0; -- i) 31 exceptions[i] = 32 (ClassType)((CpoolClass)cp.getPoolEntry(indices[i])).getClassType (); 33 } 34 35 37 public void setExceptions (ClassType[] excep_types) 38 { 39 exceptions = excep_types; 40 } 41 42 public void assignConstants (ClassType cl) 43 { 44 super.assignConstants(cl); 45 ConstantPool cp = cl.getConstants(); 46 int count = exceptions.length; 47 exception_table = new short[ count ]; 48 for (int i = count - 1; i >= 0; --i) 49 { 50 exception_table[i] = (short)cp.addClass(exceptions[i]).index; 51 } 52 } 53 54 56 public final int getLength() 57 { 58 return 2 + 2 * (exceptions == null ? 0 : exceptions.length); 59 } 60 61 62 public final ClassType[] getExceptions() 63 { 64 return exceptions; 65 } 66 67 public void write (DataOutputStream dstr) throws java.io.IOException 68 { 69 int count = exceptions.length; 70 dstr.writeShort(count); 71 for (int i = 0; i < count; i++) 72 { 73 dstr.writeShort(exception_table[i]); 74 } 75 } 76 77 public void print (ClassTypeWriter dst) 78 { 79 dst.print("Attribute \""); 80 dst.print(getName()); 81 dst.print("\", length:"); 82 dst.print(getLength()); 83 dst.print(", count: "); 84 int count = exceptions.length; 85 dst.println(count); 86 for (int i = 0; i < count; i++) 87 { 88 int catch_type_index = exception_table[i] & 0xffff; 89 dst.print(" "); 90 dst.printOptionalIndex(catch_type_index); 91 dst.printConstantTersely(catch_type_index, ConstantPool.CLASS); 92 dst.println(); 93 } 94 } 95 } 96 | Popular Tags |