KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > jcd > cls > constant > CONSTANT_NameAndType_info


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: CONSTANT_NameAndType_info.java,v 1.1.1.1 2004/05/09 16:57:49 vlad_r Exp $
8  */

9 package com.vladium.jcd.cls.constant;
10
11 import java.io.IOException JavaDoc;
12
13 import com.vladium.jcd.cls.ClassDef;
14 import com.vladium.jcd.lib.UDataInputStream;
15 import com.vladium.jcd.lib.UDataOutputStream;
16
17 // ----------------------------------------------------------------------------
18
/**
19  * The CONSTANT_NameAndType_info structure is used to represent a field or method,
20  * without indicating which class or interface type it belongs to.<P>
21  *
22  * The value of the name_index item must be a valid index into the constant pool
23  * table. The constant pool entry at that index must be a {@link CONSTANT_Utf8_info}
24  * structure representing a valid Java field name or method name stored as a simple
25  * (not fully qualified) name, that is, as a Java identifier.<P>
26  *
27  * The value of the descriptor_index item must be a valid index into the constant
28  * pool table. The constant pool entry at that index must be a {@link CONSTANT_Utf8_info}
29  * structure representing a valid Java field descriptor or method descriptor.
30  *
31  * @author (C) 2001, Vlad Roubtsov
32  */

33 public
34 final class CONSTANT_NameAndType_info extends CONSTANT_info
35 {
36     // public: ................................................................
37

38     public static final byte TAG = 12;
39     
40     
41     public int m_name_index;
42     public int m_descriptor_index;
43     
44     
45     public CONSTANT_NameAndType_info (final int name_index, final int descriptor_index)
46     {
47         m_name_index = name_index;
48         m_descriptor_index = descriptor_index;
49     }
50     
51     public final byte tag ()
52     {
53         return TAG;
54     }
55     
56     public String JavaDoc getName (final ClassDef cls)
57     {
58         return ((CONSTANT_Utf8_info) cls.getConstants ().get (m_name_index)).m_value;
59     }
60     
61     public String JavaDoc getDescriptor (final ClassDef cls)
62     {
63         return ((CONSTANT_Utf8_info) cls.getConstants ().get (m_descriptor_index)).m_value;
64     }
65     
66     // Visitor:
67

68     public Object JavaDoc accept (final ICONSTANTVisitor visitor, final Object JavaDoc ctx)
69     {
70         return visitor.visit (this, ctx);
71     }
72      
73     public String JavaDoc toString ()
74     {
75         return "CONSTANT_NameAndType: [name_index = " + m_name_index + ", descriptor_index = " + m_descriptor_index + ']';
76     }
77     
78     // Cloneable: inherited clone() is Ok
79

80     // IClassFormatOutput:
81

82     public void writeInClassFormat (final UDataOutputStream out) throws IOException JavaDoc
83     {
84         super.writeInClassFormat (out);
85         
86         out.writeU2 (m_name_index);
87         out.writeU2 (m_descriptor_index);
88     }
89     
90     // protected: .............................................................
91

92     
93     protected CONSTANT_NameAndType_info (final UDataInputStream bytes) throws IOException JavaDoc
94     {
95         m_name_index = bytes.readU2 ();
96         m_descriptor_index = bytes.readU2 ();
97     }
98     
99     // package: ...............................................................
100

101     // private: ...............................................................
102

103 } // end of class
104
// ----------------------------------------------------------------------------
105
Popular Tags