1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
6 *
7 * This program 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 program 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 General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21package proguard.classfile.attribute;
22
23import proguard.classfile.*;
24import proguard.classfile.visitor.ClassVisitor;
25
26/**
27 * Representation of an Local Variable table entry.
28 *
29 * @author Eric Lafortune
30 */
31public class LocalVariableInfo implements VisitorAccepter, Comparable
32{
33    public int u2startPC;
34    public int u2length;
35    public int u2nameIndex;
36    public int u2descriptorIndex;
37    public int u2index;
38
39    /**
40     * An extra field pointing to the referenced Clazz object.
41     * This field is typically filled out by the <code>{@link
42     * proguard.classfile.util.ClassReferenceInitializer
43     * ClassReferenceInitializer}</code>.
44     */
45    public Clazz referencedClass;
46
47    /**
48     * An extra field in which visitors can store information.
49     */
50    public Object visitorInfo;
51
52
53    /**
54     * Creates an uninitialized LocalVariableInfo.
55     */
56    public LocalVariableInfo()
57    {
58    }
59
60
61    /**
62     * Creates an initialized LocalVariableInfo.
63     */
64    public LocalVariableInfo(int   u2startPC,
65                             int   u2length,
66                             int   u2nameIndex,
67                             int   u2descriptorIndex,
68                             int   u2index)
69    {
70        this.u2startPC         = u2startPC;
71        this.u2length          = u2length;
72        this.u2nameIndex       = u2nameIndex;
73        this.u2descriptorIndex = u2descriptorIndex;
74        this.u2index           = u2index;
75    }
76
77
78    /**
79     * Returns the name.
80     */
81    public String getName(Clazz clazz)
82    {
83        return clazz.getString(u2nameIndex);
84    }
85
86
87    /**
88     * Returns the descriptor.
89     */
90    public String getDescriptor(Clazz clazz)
91    {
92        return clazz.getString(u2descriptorIndex);
93    }
94
95
96    /**
97     * Lets the referenced class accept the given visitor.
98     */
99    public void referencedClassAccept(ClassVisitor classVisitor)
100    {
101        if (referencedClass != null)
102        {
103            referencedClass.accept(classVisitor);
104        }
105    }
106
107
108    // Implementations for VisitorAccepter.
109
110    public Object getVisitorInfo()
111    {
112        return visitorInfo;
113    }
114
115    public void setVisitorInfo(Object visitorInfo)
116    {
117        this.visitorInfo = visitorInfo;
118    }
119
120
121    // Implementations for Comparable.
122
123    public int compareTo(Object object)
124    {
125        LocalVariableInfo other = (LocalVariableInfo)object;
126
127        return
128            this.u2startPC          < other.u2startPC          ? -1 : this.u2startPC          > other.u2startPC          ? 1 :
129            this.u2index            < other.u2index            ? -1 : this.u2index            > other.u2index            ? 1 :
130            this.u2length           < other.u2length           ? -1 : this.u2length           > other.u2length           ? 1 :
131            this.u2descriptorIndex  < other.u2descriptorIndex  ? -1 : this.u2descriptorIndex  > other.u2descriptorIndex  ? 1 :
132            this.u2nameIndex        < other.u2nameIndex        ? -1 : this.u2nameIndex        > other.u2nameIndex        ? 1 :
133                                                                                                                           0;
134    }
135}
136