KickJava   Java API By Example, From Geeks To Geeks.

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


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.constant.visitor.ConstantVisitor;
25 import proguard.classfile.visitor.ClassVisitor;
26
27 /**
28  * This Constant represents a class constant in the constant pool.
29  *
30  * @author Eric Lafortune
31  */

32 public class ClassConstant extends Constant
33 {
34     public int u2nameIndex;
35
36     /**
37      * An extra field pointing to the referenced Clazz object.
38      * This field is filled out by the <code>{@link
39      * proguard.classfile.util.ClassReferenceInitializer ClassReferenceInitializer}</code>.
40      */

41     public Clazz referencedClass;
42
43
44     /**
45      * Creates an uninitialized ClassConstant.
46      */

47     public ClassConstant()
48     {
49     }
50
51
52     /**
53      * Creates a new ClassConstant with the given name index.
54      * @param u2nameIndex the index of the name in the constant pool.
55      * @param referencedClass the referenced class.
56      */

57     public ClassConstant(int u2nameIndex,
58                          Clazz referencedClass)
59     {
60         this.u2nameIndex = u2nameIndex;
61         this.referencedClass = referencedClass;
62     }
63
64
65     /**
66      * Returns the name.
67      */

68     public String JavaDoc getName(Clazz clazz)
69     {
70         return clazz.getString(u2nameIndex);
71     }
72
73
74     // Implementations for Constant.
75

76     public int getTag()
77     {
78         return ClassConstants.CONSTANT_Class;
79     }
80
81     public void accept(Clazz clazz, ConstantVisitor constantVisitor)
82     {
83         constantVisitor.visitClassConstant(clazz, this);
84     }
85
86
87     /**
88      * Lets the referenced class accept the given visitor.
89      */

90     public void referencedClassAccept(ClassVisitor classVisitor)
91     {
92         if (referencedClass != null)
93         {
94             referencedClass.accept(classVisitor);
95         }
96     }
97 }
98
Popular Tags