KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import java.io.*;
27
28 /**
29  * This Constant represents a name and type constant in the constant pool.
30  *
31  * @author Eric Lafortune
32  */

33 public class NameAndTypeConstant extends Constant
34 {
35     public int u2nameIndex;
36     public int u2descriptorIndex;
37
38
39     /**
40      * Creates an uninitialized NameAndTypeConstant.
41      */

42     public NameAndTypeConstant()
43     {
44     }
45
46
47     /**
48      * Creates a new NameAndTypeConstant with the given name and type indices.
49      * @param u2nameIndex the index of the name in the constant pool.
50      * @param u2descriptorIndex the index of the descriptor in the constant
51      * pool.
52      */

53     public NameAndTypeConstant(int u2nameIndex,
54                                int u2descriptorIndex)
55     {
56         this.u2nameIndex = u2nameIndex;
57         this.u2descriptorIndex = u2descriptorIndex;
58     }
59
60
61     /**
62      * Returns the name index.
63      */

64     protected int getNameIndex()
65     {
66         return u2nameIndex;
67     }
68
69     /**
70      * Sets the name index.
71      */

72     protected void setNameIndex(int index)
73     {
74         u2nameIndex = index;
75     }
76
77     /**
78      * Returns the descriptor index.
79      */

80     protected int getDescriptorIndex()
81     {
82         return u2descriptorIndex;
83     }
84
85     /**
86      * Sets the descriptor index.
87      */

88     protected void setDescriptorIndex(int index)
89     {
90         u2descriptorIndex = index;
91     }
92
93     /**
94      * Returns the name.
95      */

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

104     public String JavaDoc getType(Clazz clazz)
105     {
106         return clazz.getString(u2descriptorIndex);
107     }
108
109
110     // Implementations for Constant.
111

112     public int getTag()
113     {
114         return ClassConstants.CONSTANT_NameAndType;
115     }
116
117     public void accept(Clazz clazz, ConstantVisitor constantVisitor)
118     {
119         constantVisitor.visitNameAndTypeConstant(clazz, this);
120     }
121 }
122
Popular Tags