KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ClassFormatException;
14 import org.eclipse.jdt.core.util.IConstantPool;
15 import org.eclipse.jdt.core.util.ILineNumberAttribute;
16
17 /**
18  * Default implementation of ILineNumberAttribute.
19  */

20 public class LineNumberAttribute
21     extends ClassFileAttribute
22     implements ILineNumberAttribute {
23
24     private static final int[][] NO_ENTRIES = new int[0][0];
25     private int lineNumberTableLength;
26     private int[][] lineNumberTable;
27     
28     /**
29      * Constructor for LineNumberAttribute.
30      * @param classFileBytes
31      * @param constantPool
32      * @param offset
33      * @throws ClassFormatException
34      */

35     public LineNumberAttribute(
36         byte[] classFileBytes,
37         IConstantPool constantPool,
38         int offset)
39         throws ClassFormatException {
40         super(classFileBytes, constantPool, offset);
41         
42         final int length = u2At(classFileBytes, 6, offset);
43         this.lineNumberTableLength = length;
44         if (length != 0) {
45             this.lineNumberTable = new int[length][2];
46             int readOffset = 8;
47             for (int i = 0; i < length; i++) {
48                 this.lineNumberTable[i][0] = u2At(classFileBytes, readOffset, offset);
49                 this.lineNumberTable[i][1] = u2At(classFileBytes, readOffset + 2, offset);
50                 readOffset += 4;
51             }
52         } else {
53             this.lineNumberTable = NO_ENTRIES;
54         }
55     }
56     /**
57      * @see ILineNumberAttribute#getLineNumberTable()
58      */

59     public int[][] getLineNumberTable() {
60         return this.lineNumberTable;
61     }
62
63     /**
64      * @see ILineNumberAttribute#getLineNumberTableLength()
65      */

66     public int getLineNumberTableLength() {
67         return this.lineNumberTableLength;
68     }
69
70 }
71
Popular Tags