1 11 package org.eclipse.jdt.internal.core.util; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.core.util.ClassFormatException; 15 import org.eclipse.jdt.core.util.IConstantPool; 16 import org.eclipse.jdt.core.util.IConstantPoolConstant; 17 import org.eclipse.jdt.core.util.IConstantPoolEntry; 18 import org.eclipse.jdt.core.util.IExceptionAttribute; 19 20 23 public class ExceptionAttribute extends ClassFileAttribute implements IExceptionAttribute { 24 private int exceptionsNumber; 25 private char[][] exceptionNames; 26 private int[] exceptionIndexes; 27 28 ExceptionAttribute(byte[] classFileBytes, IConstantPool constantPool, int offset) throws ClassFormatException { 29 super(classFileBytes, constantPool, offset); 30 this.exceptionsNumber = u2At(classFileBytes, 6, offset); 31 int exceptionLength = this.exceptionsNumber; 32 this.exceptionNames = CharOperation.NO_CHAR_CHAR; 33 this.exceptionIndexes = org.eclipse.jdt.internal.compiler.util.Util.EMPTY_INT_ARRAY; 34 if (exceptionLength != 0) { 35 this.exceptionNames = new char[exceptionLength][]; 36 this.exceptionIndexes = new int[exceptionLength]; 37 } 38 int readOffset = 8; 39 IConstantPoolEntry constantPoolEntry; 40 for (int i = 0; i < exceptionLength; i++) { 41 exceptionIndexes[i] = u2At(classFileBytes, readOffset, offset); 42 constantPoolEntry = constantPool.decodeEntry(exceptionIndexes[i]); 43 if (constantPoolEntry.getKind() != IConstantPoolConstant.CONSTANT_Class) { 44 throw new ClassFormatException(ClassFormatException.INVALID_CONSTANT_POOL_ENTRY); 45 } 46 exceptionNames[i] = constantPoolEntry.getClassInfoName(); 47 readOffset += 2; 48 } 49 } 50 51 54 public int[] getExceptionIndexes() { 55 return this.exceptionIndexes; 56 } 57 58 61 public char[][] getExceptionNames() { 62 return this.exceptionNames; 63 } 64 65 68 public int getExceptionsNumber() { 69 return this.exceptionsNumber; 70 } 71 } 72 | Popular Tags |