1
/* $Id: EnclosingMethodAttrInfo.java,v 1.2 2004/10/31 18:13:38 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 Lesser General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or (at your
11
* option) any later version.
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.attribute;
24
import proguard.classfile.*;
25
import proguard.classfile.visitor.*;
30
* Representation of an enclosing method attribute.
32
* @author Eric Lafortune
34
public class EnclosingMethodAttrInfo extends AttrInfo
36
private static final int CONSTANT_FIELD_SIZE = 4;
39
public int u2classIndex;
40
public int u2nameAndTypeIndex;
43
* An extra field pointing to the referenced ClassFile object.
44
* This field is typically filled out by the <code>{@link
45
* ClassFileReferenceInitializer}</code>.
47
public ClassFile referencedClassFile;
50
* An extra field optionally pointing to the referenced MethodInfo object.
51
* This field is typically filled out by the <code>{@link
52
* ClassFileReferenceInitializer}</code>.
54
public MethodInfo referencedMethodInfo;
57
protected EnclosingMethodAttrInfo()
63
* Returns the class name.
65
public String getClassName(ClassFile classFile)
67
return classFile.getCpClassNameString(u2classIndex);
71
* Returns the method/field name.
73
public String getName(ClassFile classFile)
75
return classFile.getCpNameString(u2nameAndTypeIndex);
81
public String getType(ClassFile classFile)
83
return classFile.getCpTypeString(u2nameAndTypeIndex);
88
* Lets the referenced class file accept the given visitor.
90
public void referencedClassAccept(ClassFileVisitor classFileVisitor)
92
if (referencedClassFile != null)
94
referencedClassFile.accept(classFileVisitor);
100
* Lets the referenced class member accept the given visitor.
102
public void referencedMethodInfoAccept(MemberInfoVisitor memberInfoVisitor)
104
if (referencedMethodInfo != null)
106
referencedMethodInfo.accept(referencedClassFile,
112
// Implementations for AttrInfo.
114
protected int getLength()
116
return CONSTANT_FIELD_SIZE;
119
protected void readInfo(DataInput din, ClassFile classFile) throws IOException
121
u2classIndex = din.readUnsignedShort();
122
u2nameAndTypeIndex = din.readUnsignedShort();
125
protected void writeInfo(DataOutput dout) throws IOException
127
dout.writeShort(u2classIndex);
128
dout.writeShort(u2nameAndTypeIndex);
131
public void accept(ClassFile classFile, AttrInfoVisitor attrInfoVisitor)
133
attrInfoVisitor.visitEnclosingMethodAttrInfo(classFile, this);