KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > attribute > EnclosingMethodAttribute


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This library 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 library 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 Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.classfile.attribute;
22
23 import proguard.classfile.*;
24 import proguard.classfile.attribute.visitor.AttributeVisitor;
25 import proguard.classfile.visitor.*;
26
27 import java.io.*;
28
29 /**
30  * This Attribute represents an enclosing method attribute.
31  *
32  * @author Eric Lafortune
33  */

34 public class EnclosingMethodAttribute extends Attribute
35 {
36     public int u2classIndex;
37     public int u2nameAndTypeIndex;
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 optionally pointing to the referenced Method object.
49      * This field is typically filled out by the <code>{@link
50      * proguard.classfile.util.ClassReferenceInitializer
51      * ClassReferenceInitializer}</code>.
52      */

53     public Method referencedMethod;
54
55
56     /**
57      * Creates an uninitialized EnclosingMethodAttribute.
58      */

59     public EnclosingMethodAttribute()
60     {
61     }
62
63
64     /**
65      * Returns the class name.
66      */

67     public String JavaDoc getClassName(Clazz clazz)
68     {
69         return clazz.getClassName(u2classIndex);
70     }
71
72     /**
73      * Returns the method/field name.
74      */

75     public String JavaDoc getName(Clazz clazz)
76     {
77         return clazz.getName(u2nameAndTypeIndex);
78     }
79
80     /**
81      * Returns the type.
82      */

83     public String JavaDoc getType(Clazz clazz)
84     {
85         return clazz.getType(u2nameAndTypeIndex);
86     }
87
88
89     /**
90      * Lets the referenced class accept the given visitor.
91      */

92     public void referencedClassAccept(ClassVisitor classVisitor)
93     {
94         if (referencedClass != null)
95         {
96             referencedClass.accept(classVisitor);
97         }
98     }
99
100
101     /**
102      * Lets the referenced class member accept the given visitor.
103      */

104     public void referencedMethodAccept(MemberVisitor memberVisitor)
105     {
106         if (referencedMethod != null)
107         {
108             referencedMethod.accept(referencedClass,
109                                     memberVisitor);
110         }
111     }
112
113
114     // Implementations for Attribute.
115

116     public void accept(Clazz clazz, AttributeVisitor attributeVisitor)
117     {
118         attributeVisitor.visitEnclosingMethodAttribute(clazz, this);
119     }
120 }
121
Popular Tags