1
/* $Id: RefCpInfo.java,v 1.21 2004/10/31 18:13:37 eric Exp $
3
* ProGuard -- shrinking, optimization, and obfuscation of Java class files.
5
* Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
6
* Copyright (c) 2002-2004 Eric Lafortune (eric@graphics.cornell.edu)
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)
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
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
22
package proguard.classfile;
24
import proguard.classfile.visitor.*;
29
* Representation of a 'ref'-type entry in the ConstantPool.
32
* @author Eric Lafortune
34
public abstract class RefCpInfo extends CpInfo
36
public int u2classIndex;
37
public int u2nameAndTypeIndex;
40
* An extra field pointing to the referenced ClassFile object.
41
* This field is typically filled out by the <code>{@link
42
* ClassFileReferenceInitializer}</code>.
44
public ClassFile referencedClassFile;
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>.
51
public MemberInfo referencedMemberInfo;
60
* Returns the class index.
62
public int getClassIndex()
68
* Returns the name-and-type index.
70
public int getNameAndTypeIndex()
72
return u2nameAndTypeIndex;
76
* Sets the name-and-type index.
78
public void setNameAndTypeIndex(int index)
80
u2nameAndTypeIndex = index;
84
* Returns the class name.
86
public String getClassName(ClassFile classFile)
88
return classFile.getCpClassNameString(u2classIndex);
92
* Returns the method/field name.
94
public String getName(ClassFile classFile)
96
return classFile.getCpNameString(u2nameAndTypeIndex);
102
public String getType(ClassFile classFile)
104
return classFile.getCpTypeString(u2nameAndTypeIndex);
109
* Lets the referenced class file accept the given visitor.
111
public void referencedClassAccept(ClassFileVisitor classFileVisitor)
113
if (referencedClassFile != null)
115
referencedClassFile.accept(classFileVisitor);
121
* Lets the referenced class member accept the given visitor.
123
public void referencedMemberInfoAccept(MemberInfoVisitor memberInfoVisitor)
125
if (referencedMemberInfo != null)
127
referencedMemberInfo.accept(referencedClassFile,
133
// Implementations for CpInfo.
135
protected void readInfo(DataInput din) throws IOException
137
u2classIndex = din.readUnsignedShort();
138
u2nameAndTypeIndex = din.readUnsignedShort();
141
protected void writeInfo(DataOutput dout) throws IOException
143
dout.writeShort(u2classIndex);
144
dout.writeShort(u2nameAndTypeIndex);