KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > attribute > LineNumberTableAttribute


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.classfile.attribute;
22
23 import proguard.classfile.attribute.visitor.*;
24 import proguard.classfile.*;
25
26 import java.io.*;
27
28 /**
29  * This Attribute represents a line number table attribute.
30  *
31  * @author Eric Lafortune
32  */

33 public class LineNumberTableAttribute extends Attribute
34 {
35     public int u2lineNumberTableLength;
36     public LineNumberInfo[] lineNumberTable;
37
38
39     /**
40      * Creates an uninitialized LineNumberTableAttribute.
41      */

42     public LineNumberTableAttribute()
43     {
44     }
45
46
47     /**
48      * Returns the line number corresponding to the given byte code program
49      * counter.
50      */

51     public int getLineNumber(int pc)
52     {
53         for (int index = u2lineNumberTableLength-1 ; index >= 0 ; index--)
54         {
55             LineNumberInfo info = lineNumberTable[index];
56             if (pc >= info.u2startPC)
57             {
58                 return info.u2lineNumber;
59             }
60         }
61
62         return u2lineNumberTableLength > 0 ?
63             lineNumberTable[0].u2lineNumber :
64             0;
65     }
66
67
68     // Implementations for Attribute.
69

70     public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor)
71     {
72         attributeVisitor.visitLineNumberTableAttribute(clazz, method, codeAttribute, this);
73     }
74
75
76     /**
77      * Applies the given visitor to all line numbers.
78      */

79     public void lineNumbersAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfoVisitor lineNumberInfoVisitor)
80     {
81         for (int index = 0; index < u2lineNumberTableLength; index++)
82         {
83             // We don't need double dispatching here, since there is only one
84
// type of LineNumberInfo.
85
lineNumberInfoVisitor.visitLineNumberInfo(clazz, method, codeAttribute, lineNumberTable[index]);
86         }
87     }
88 }
89
Popular Tags