LocalVariableInfo.java revision 8a6199f0c36a778f22394364347a301b0b28e94b
1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2013 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     * Lets the referenced class accept the given visitor.
80     */
81    public void referencedClassAccept(ClassVisitor classVisitor)
82    {
83        if (referencedClass != null)
84        {
85            referencedClass.accept(classVisitor);
86        }
87    }
88
89
90    // Implementations for VisitorAccepter.
91
92    public Object getVisitorInfo()
93    {
94        return visitorInfo;
95    }
96
97    public void setVisitorInfo(Object visitorInfo)
98    {
99        this.visitorInfo = visitorInfo;
100    }
101
102
103    // Implementations for Comparable.
104
105    public int compareTo(Object object)
106    {
107        LocalVariableInfo other = (LocalVariableInfo)object;
108
109        return
110            this.u2startPC          < other.u2startPC          ? -1 : this.u2startPC          > other.u2startPC          ? 1 :
111            this.u2index            < other.u2index            ? -1 : this.u2index            > other.u2index            ? 1 :
112            this.u2length           < other.u2length           ? -1 : this.u2length           > other.u2length           ? 1 :
113            this.u2descriptorIndex  < other.u2descriptorIndex  ? -1 : this.u2descriptorIndex  > other.u2descriptorIndex  ? 1 :
114            this.u2nameIndex        < other.u2nameIndex        ? -1 : this.u2nameIndex        > other.u2nameIndex        ? 1 :
115                                                                                                                           0;
116    }
117}
118