MethodParameters_attribute.java revision 2942:08092deced3f
1182081Sjhb/*
2182081Sjhb * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3182081Sjhb * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4182081Sjhb *
5182081Sjhb * This code is free software; you can redistribute it and/or modify it
6182081Sjhb * under the terms of the GNU General Public License version 2 only, as
7182081Sjhb * published by the Free Software Foundation.  Oracle designates this
8182081Sjhb * particular file as subject to the "Classpath" exception as provided
9182081Sjhb * by Oracle in the LICENSE file that accompanied this code.
10182081Sjhb *
11182081Sjhb * This code is distributed in the hope that it will be useful, but WITHOUT
12182081Sjhb * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13182081Sjhb * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14182081Sjhb * version 2 for more details (a copy is included in the LICENSE file that
15182081Sjhb * accompanied this code).
16182081Sjhb *
17182081Sjhb * You should have received a copy of the GNU General Public License version
18182081Sjhb * 2 along with this work; if not, write to the Free Software Foundation,
19182081Sjhb * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20182081Sjhb *
21182081Sjhb * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22182081Sjhb * or visit www.oracle.com if you need additional information or have any
23182081Sjhb * questions.
24182081Sjhb */
25182081Sjhb
26182081Sjhbpackage com.sun.tools.classfile;
27182081Sjhb
28182081Sjhbimport java.io.IOException;
29182081Sjhb
30182081Sjhb/**
31182081Sjhb * See JVMS, section 4.8.13.
32182081Sjhb *
33182081Sjhb *  <p><b>This is NOT part of any supported API.
34182081Sjhb *  If you write code that depends on this, you do so at your own risk.
35182081Sjhb *  This code and its internal interfaces are subject to change or
36182081Sjhb *  deletion without notice.</b>
37182081Sjhb */
38182081Sjhbpublic class MethodParameters_attribute extends Attribute {
39182081Sjhb
40182081Sjhb    public final int method_parameter_table_length;
41182081Sjhb    public final Entry[] method_parameter_table;
42182081Sjhb
43182081Sjhb    MethodParameters_attribute(ClassReader cr,
44182081Sjhb                              int name_index,
45182081Sjhb                              int length)
46182081Sjhb        throws IOException {
47182081Sjhb        super(name_index, length);
48182081Sjhb
49182081Sjhb        method_parameter_table_length = cr.readUnsignedByte();
50182081Sjhb        method_parameter_table = new Entry[method_parameter_table_length];
51182081Sjhb        for (int i = 0; i < method_parameter_table_length; i++)
52182081Sjhb            method_parameter_table[i] = new Entry(cr);
53182081Sjhb    }
54182081Sjhb
55182081Sjhb    public MethodParameters_attribute(ConstantPool constant_pool,
56182081Sjhb                                      Entry[] method_parameter_table)
57182081Sjhb        throws ConstantPoolException {
58182081Sjhb        this(constant_pool.getUTF8Index(Attribute.MethodParameters),
59182081Sjhb             method_parameter_table);
60182081Sjhb    }
61182081Sjhb
62182081Sjhb    public MethodParameters_attribute(int name_index,
63182081Sjhb                                      Entry[] method_parameter_table) {
64182081Sjhb        super(name_index, 1 + method_parameter_table.length * Entry.length());
65182081Sjhb        this.method_parameter_table_length = method_parameter_table.length;
66182081Sjhb        this.method_parameter_table = method_parameter_table;
67182081Sjhb    }
68182081Sjhb
69182081Sjhb    public <R, D> R accept(Visitor<R, D> visitor, D data) {
70197444Sjkim        return visitor.visitMethodParameters(this, data);
71182081Sjhb    }
72182081Sjhb
73182081Sjhb    public static class Entry {
74182081Sjhb        Entry(ClassReader cr) throws IOException {
75182081Sjhb            name_index = cr.readUnsignedShort();
76182081Sjhb            flags = cr.readUnsignedShort();
77182081Sjhb        }
78182081Sjhb
79182081Sjhb        public static int length() {
80182081Sjhb            return 6;
81182081Sjhb        }
82182081Sjhb
83182081Sjhb        public final int name_index;
84182081Sjhb        public final int flags;
85182081Sjhb    }
86182081Sjhb
87182081Sjhb}
88182081Sjhb