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

« back to all changes in this revision

Viewing changes to src/proguard/classfile/attribute/EnclosingMethodAttrInfo.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: EnclosingMethodAttrInfo.java,v 1.2 2004/10/31 18:13:38 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 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.
 
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.attribute;
 
23
 
 
24
import proguard.classfile.*;
 
25
import proguard.classfile.visitor.*;
 
26
 
 
27
import java.io.*;
 
28
 
 
29
/**
 
30
 * Representation of an enclosing method attribute.
 
31
 *
 
32
 * @author Eric Lafortune
 
33
 */
 
34
public class EnclosingMethodAttrInfo extends AttrInfo
 
35
{
 
36
    private static final int CONSTANT_FIELD_SIZE = 4;
 
37
 
 
38
 
 
39
    public int u2classIndex;
 
40
    public int u2nameAndTypeIndex;
 
41
 
 
42
    /**
 
43
     * An extra field pointing to the referenced ClassFile object.
 
44
     * This field is typically filled out by the <code>{@link
 
45
     * ClassFileReferenceInitializer}</code>.
 
46
     */
 
47
    public ClassFile referencedClassFile;
 
48
 
 
49
    /**
 
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>.
 
53
     */
 
54
    public MethodInfo referencedMethodInfo;
 
55
 
 
56
 
 
57
    protected EnclosingMethodAttrInfo()
 
58
    {
 
59
    }
 
60
 
 
61
 
 
62
    /**
 
63
     * Returns the class name.
 
64
     */
 
65
    public String getClassName(ClassFile classFile)
 
66
    {
 
67
        return classFile.getCpClassNameString(u2classIndex);
 
68
    }
 
69
 
 
70
    /**
 
71
     * Returns the method/field name.
 
72
     */
 
73
    public String getName(ClassFile classFile)
 
74
    {
 
75
        return classFile.getCpNameString(u2nameAndTypeIndex);
 
76
    }
 
77
 
 
78
    /**
 
79
     * Returns the type.
 
80
     */
 
81
    public String getType(ClassFile classFile)
 
82
    {
 
83
        return classFile.getCpTypeString(u2nameAndTypeIndex);
 
84
    }
 
85
 
 
86
 
 
87
    /**
 
88
     * Lets the referenced class file accept the given visitor.
 
89
     */
 
90
    public void referencedClassAccept(ClassFileVisitor classFileVisitor)
 
91
    {
 
92
        if (referencedClassFile != null)
 
93
        {
 
94
            referencedClassFile.accept(classFileVisitor);
 
95
        }
 
96
    }
 
97
 
 
98
 
 
99
    /**
 
100
     * Lets the referenced class member accept the given visitor.
 
101
     */
 
102
    public void referencedMethodInfoAccept(MemberInfoVisitor memberInfoVisitor)
 
103
    {
 
104
        if (referencedMethodInfo != null)
 
105
        {
 
106
            referencedMethodInfo.accept(referencedClassFile,
 
107
                                        memberInfoVisitor);
 
108
        }
 
109
    }
 
110
 
 
111
 
 
112
    // Implementations for AttrInfo.
 
113
 
 
114
    protected int getLength()
 
115
    {
 
116
        return CONSTANT_FIELD_SIZE;
 
117
    }
 
118
 
 
119
    protected void readInfo(DataInput din, ClassFile classFile) throws IOException
 
120
    {
 
121
        u2classIndex       = din.readUnsignedShort();
 
122
        u2nameAndTypeIndex = din.readUnsignedShort();
 
123
    }
 
124
 
 
125
    protected void writeInfo(DataOutput dout) throws IOException
 
126
    {
 
127
        dout.writeShort(u2classIndex);
 
128
        dout.writeShort(u2nameAndTypeIndex);
 
129
    }
 
130
 
 
131
    public void accept(ClassFile classFile, AttrInfoVisitor attrInfoVisitor)
 
132
    {
 
133
        attrInfoVisitor.visitEnclosingMethodAttrInfo(classFile, this);
 
134
    }
 
135
}