KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > constant > RefConstant


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.constant;
22
23 import proguard.classfile.*;
24 import proguard.classfile.visitor.*;
25
26 import java.io.*;
27
28 /**
29  * This Constant represents a ref constant in the constant pool.
30  *
31  * @author Eric Lafortune
32  */

33 public abstract class RefConstant extends Constant
34 {
35     public int u2classIndex;
36     public int u2nameAndTypeIndex;
37
38     /**
39      * An extra field pointing to the referenced Clazz object.
40      * This field is typically filled out by the <code>{@link
41      * proguard.classfile.util.ClassReferenceInitializer
42      * ClassReferenceInitializer}</code>.
43      */

44     public Clazz referencedClass;
45
46     /**
47      * An extra field optionally pointing to the referenced Member object.
48      * This field is typically filled out by the <code>{@link
49      * proguard.classfile.util.ClassReferenceInitializer
50      * ClassReferenceInitializer}</code>.
51      */

52     public Member referencedMember;
53
54
55     protected RefConstant()
56     {
57     }
58
59
60     /**
61      * Returns the class index.
62      */

63     public int getClassIndex()
64     {
65         return u2classIndex;
66     }
67
68     /**
69      * Returns the name-and-type index.
70      */

71     public int getNameAndTypeIndex()
72     {
73         return u2nameAndTypeIndex;
74     }
75
76     /**
77      * Sets the name-and-type index.
78      */

79     public void setNameAndTypeIndex(int index)
80     {
81         u2nameAndTypeIndex = index;
82     }
83
84     /**
85      * Returns the class name.
86      */

87     public String JavaDoc getClassName(Clazz clazz)
88     {
89         return clazz.getClassName(u2classIndex);
90     }
91
92     /**
93      * Returns the method/field name.
94      */

95     public String JavaDoc getName(Clazz clazz)
96     {
97         return clazz.getName(u2nameAndTypeIndex);
98     }
99
100     /**
101      * Returns the type.
102      */

103     public String JavaDoc getType(Clazz clazz)
104     {
105         return clazz.getType(u2nameAndTypeIndex);
106     }
107
108
109     /**
110      * Lets the referenced class accept the given visitor.
111      */

112     public void referencedClassAccept(ClassVisitor classVisitor)
113     {
114         if (referencedClass != null)
115         {
116             referencedClass.accept(classVisitor);
117         }
118     }
119
120
121     /**
122      * Lets the referenced class member accept the given visitor.
123      */

124     public void referencedMemberAccept(MemberVisitor memberVisitor)
125     {
126         if (referencedMember != null)
127         {
128             referencedMember.accept(referencedClass,
129                                     memberVisitor);
130         }
131     }
132 }
133
Popular Tags