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: SourceFileAttribute_info.java,v 1.1.1.1 2004/05/09 16:57:48 vlad_r Exp $
8 */
9package com.vladium.jcd.cls.attribute;
10
11import java.io.IOException;
12
13import com.vladium.jcd.cls.ClassDef;
14import com.vladium.jcd.cls.constant.CONSTANT_Utf8_info;
15import com.vladium.jcd.lib.UDataInputStream;
16import com.vladium.jcd.lib.UDataOutputStream;
17
18// ----------------------------------------------------------------------------
19/**
20 *
21 * @author (C) 2001, Vlad Roubtsov
22 */
23public
24final class SourceFileAttribute_info extends Attribute_info
25{
26    // public: ................................................................
27
28
29    public int m_sourcefile_index;
30
31
32    public SourceFileAttribute_info (final int attribute_name_index)
33    {
34        super (attribute_name_index, 0);
35    }
36
37
38    public long length ()
39    {
40        return 8;
41    }
42
43    public CONSTANT_Utf8_info getSourceFile (final ClassDef cls)
44    {
45        return (CONSTANT_Utf8_info) cls.getConstants ().get (m_sourcefile_index);
46    }
47
48    // Visitor:
49
50    public void accept (final IAttributeVisitor visitor, final Object ctx)
51    {
52        visitor.visit (this, ctx);
53    }
54
55    public String toString ()
56    {
57        return "SourceFileAttribute_info: [attribute_name_index = " + m_name_index + ", attribute_length = " + m_attribute_length + ']';
58    }
59
60    // Cloneable:
61
62    /**
63     * Performs a deep copy.
64     */
65    public Object clone ()
66    {
67        return super.clone ();
68    }
69
70    // IClassFormatOutput:
71
72    public void writeInClassFormat (final UDataOutputStream out) throws IOException
73    {
74        super.writeInClassFormat (out);
75
76        out.writeU2 (m_sourcefile_index);
77    }
78
79    // protected: .............................................................
80
81    // package: ...............................................................
82
83
84    SourceFileAttribute_info (final int attribute_name_index, final long attribute_length,
85                              final UDataInputStream bytes)
86        throws IOException
87    {
88        super (attribute_name_index, attribute_length);
89
90        m_sourcefile_index = bytes.readU2 ();
91    }
92
93    // private: ...............................................................
94
95} // end of class
96// ----------------------------------------------------------------------------
97
98