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_Class_info.java,v 1.1.1.1 2004/05/09 16:57:48 vlad_r Exp $
8 */
9package com.vladium.jcd.cls.constant;
10
11import java.io.IOException;
12
13import com.vladium.jcd.cls.ClassDef;
14import com.vladium.jcd.lib.UDataInputStream;
15import com.vladium.jcd.lib.UDataOutputStream;
16
17// ----------------------------------------------------------------------------
18/**
19 * The CONSTANT_Class_info structure is used to represent a class or an interface.<P>
20 *
21 * The value of the name_index item must be a valid index into the constant pool
22 * table. The constant pool entry at that index must be a {@link CONSTANT_Utf8_info}
23 * structure representing a valid fully qualified Java class name that has been
24 * converted to the class file's internal form.
25 *
26 * @author (C) 2001, Vlad Roubtsov
27 */
28public
29final class CONSTANT_Class_info extends CONSTANT_info
30{
31    // public: ................................................................
32
33    public static final byte TAG = 7;
34
35    public int m_name_index;
36
37
38    public CONSTANT_Class_info (final int name_index)
39    {
40        m_name_index = name_index;
41    }
42
43
44    public final byte tag ()
45    {
46        return TAG;
47    }
48
49    /**
50     * Returns the JVM class name within the constant pool context of 'cls'
51     * class definition.
52     *
53     * @param cls class that contains this constant
54     * @return class name [in JVM format]
55     */
56    public String getName (final ClassDef cls)
57    {
58        return ((CONSTANT_Utf8_info) cls.getConstants ().get (m_name_index)).m_value;
59    }
60
61    // Visitor:
62
63    public Object accept (final ICONSTANTVisitor visitor, final Object ctx)
64    {
65        return visitor.visit (this, ctx);
66    }
67
68
69    public String toString ()
70    {
71        return "CONSTANT_Class: [name_index = " + m_name_index + ']';
72    }
73
74    // Cloneable: inherited clone() is Ok
75
76    // IClassFormatOutput:
77
78    public void writeInClassFormat (final UDataOutputStream out) throws IOException
79    {
80        super.writeInClassFormat (out);
81
82        out.writeU2 (m_name_index);
83    }
84
85    // protected: .............................................................
86
87
88    protected CONSTANT_Class_info (final UDataInputStream bytes) throws IOException
89    {
90        m_name_index = bytes.readU2 ();
91    }
92
93    // package: ...............................................................
94
95    // private: ...............................................................
96
97} // end of class
98// ----------------------------------------------------------------------------
99