~ubuntu-branches/ubuntu/breezy/proguard/breezy

« back to all changes in this revision

Viewing changes to src/proguard/classfile/RefCpInfo.java

  • Committer: Bazaar Package Importer
  • Author(s): Sam Clegg
  • Date: 2005-06-17 14:25:24 UTC
  • Revision ID: james.westby@ubuntu.com-20050617142524-thz2yfa3vemy3j9d
Tags: upstream-3.2
ImportĀ upstreamĀ versionĀ 3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: RefCpInfo.java,v 1.21 2004/10/31 18:13:37 eric Exp $
 
2
 *
 
3
 * ProGuard -- shrinking, optimization, and obfuscation of Java class files.
 
4
 *
 
5
 * Copyright (c) 1999      Mark Welsh (markw@retrologic.com)
 
6
 * Copyright (c) 2002-2004 Eric Lafortune (eric@graphics.cornell.edu)
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or modify it
 
9
 * under the terms of the GNU General Public License as published by the Free
 
10
 * Software Foundation; either version 2 of the License, or (at your option)
 
11
 * any later version.
 
12
 *
 
13
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
15
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 
16
 * for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public License
 
19
 * along with this library; if not, write to the Free Software Foundation,
 
20
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
21
 */
 
22
package proguard.classfile;
 
23
 
 
24
import proguard.classfile.visitor.*;
 
25
 
 
26
import java.io.*;
 
27
 
 
28
/**
 
29
 * Representation of a 'ref'-type entry in the ConstantPool.
 
30
 *
 
31
 * @author Mark Welsh
 
32
 * @author Eric Lafortune
 
33
 */
 
34
public abstract class RefCpInfo extends CpInfo
 
35
{
 
36
    public int u2classIndex;
 
37
    public int u2nameAndTypeIndex;
 
38
 
 
39
    /**
 
40
     * An extra field pointing to the referenced ClassFile object.
 
41
     * This field is typically filled out by the <code>{@link
 
42
     * ClassFileReferenceInitializer}</code>.
 
43
     */
 
44
    public ClassFile referencedClassFile;
 
45
 
 
46
    /**
 
47
     * An extra field optionally pointing to the referenced MemberInfo object.
 
48
     * This field is typically filled out by the <code>{@link
 
49
     * ClassFileReferenceInitializer}</code>.
 
50
     */
 
51
    public MemberInfo referencedMemberInfo;
 
52
 
 
53
 
 
54
    protected RefCpInfo()
 
55
    {
 
56
    }
 
57
 
 
58
 
 
59
    /**
 
60
     * Returns the class index.
 
61
     */
 
62
    public int getClassIndex()
 
63
    {
 
64
        return u2classIndex;
 
65
    }
 
66
 
 
67
    /**
 
68
     * Returns the name-and-type index.
 
69
     */
 
70
    public int getNameAndTypeIndex()
 
71
    {
 
72
        return u2nameAndTypeIndex;
 
73
    }
 
74
 
 
75
    /**
 
76
     * Sets the name-and-type index.
 
77
     */
 
78
    public void setNameAndTypeIndex(int index)
 
79
    {
 
80
        u2nameAndTypeIndex = index;
 
81
    }
 
82
 
 
83
    /**
 
84
     * Returns the class name.
 
85
     */
 
86
    public String getClassName(ClassFile classFile)
 
87
    {
 
88
        return classFile.getCpClassNameString(u2classIndex);
 
89
    }
 
90
 
 
91
    /**
 
92
     * Returns the method/field name.
 
93
     */
 
94
    public String getName(ClassFile classFile)
 
95
    {
 
96
        return classFile.getCpNameString(u2nameAndTypeIndex);
 
97
    }
 
98
 
 
99
    /**
 
100
     * Returns the type.
 
101
     */
 
102
    public String getType(ClassFile classFile)
 
103
    {
 
104
        return classFile.getCpTypeString(u2nameAndTypeIndex);
 
105
    }
 
106
 
 
107
 
 
108
    /**
 
109
     * Lets the referenced class file accept the given visitor.
 
110
     */
 
111
    public void referencedClassAccept(ClassFileVisitor classFileVisitor)
 
112
    {
 
113
        if (referencedClassFile != null)
 
114
        {
 
115
            referencedClassFile.accept(classFileVisitor);
 
116
        }
 
117
    }
 
118
 
 
119
 
 
120
    /**
 
121
     * Lets the referenced class member accept the given visitor.
 
122
     */
 
123
    public void referencedMemberInfoAccept(MemberInfoVisitor memberInfoVisitor)
 
124
    {
 
125
        if (referencedMemberInfo != null)
 
126
        {
 
127
            referencedMemberInfo.accept(referencedClassFile,
 
128
                                        memberInfoVisitor);
 
129
        }
 
130
    }
 
131
 
 
132
 
 
133
    // Implementations for CpInfo.
 
134
 
 
135
    protected void readInfo(DataInput din) throws IOException
 
136
    {
 
137
        u2classIndex = din.readUnsignedShort();
 
138
        u2nameAndTypeIndex = din.readUnsignedShort();
 
139
    }
 
140
 
 
141
    protected void writeInfo(DataOutput dout) throws IOException
 
142
    {
 
143
        dout.writeShort(u2classIndex);
 
144
        dout.writeShort(u2nameAndTypeIndex);
 
145
    }
 
146
}