KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > util > ExceptionAttribute


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
21  * Default implementation of IExceptionAttribute.
22  */

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     /**
52      * @see IExceptionAttribute#getExceptionIndexes()
53      */

54     public int[] getExceptionIndexes() {
55         return this.exceptionIndexes;
56     }
57
58     /**
59      * @see IExceptionAttribute#getExceptionNames()
60      */

61     public char[][] getExceptionNames() {
62         return this.exceptionNames;
63     }
64
65     /**
66      * @see IExceptionAttribute#getExceptionsNumber()
67      */

68     public int getExceptionsNumber() {
69         return this.exceptionsNumber;
70     }
71 }
72
Popular Tags