author | alanb |
Fri, 10 Feb 2017 09:06:10 +0000 | |
changeset 43767 | 9cff98a149cb |
parent 42822 | a84956e7ee4d |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
36526 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.classfile; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
30 |
import com.sun.tools.classfile.ConstantPool.CONSTANT_Module_info; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
31 |
|
36526 | 32 |
/** |
33 |
* See Jigsaw. |
|
34 |
* |
|
35 |
* <p><b>This is NOT part of any supported API. |
|
36 |
* If you write code that depends on this, you do so at your own risk. |
|
37 |
* This code and its internal interfaces are subject to change or |
|
38 |
* deletion without notice.</b> |
|
39 |
*/ |
|
40 |
public class Module_attribute extends Attribute { |
|
43767
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42822
diff
changeset
|
41 |
public static final int ACC_TRANSITIVE = 0x20; |
9cff98a149cb
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42822
diff
changeset
|
42 |
public static final int ACC_STATIC_PHASE = 0x40; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
43 |
public static final int ACC_OPEN = 0x20; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
44 |
public static final int ACC_SYNTHETIC = 0x1000; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
45 |
public static final int ACC_MANDATED = 0x8000; |
36526 | 46 |
|
47 |
Module_attribute(ClassReader cr, int name_index, int length) throws IOException { |
|
48 |
super(name_index, length); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
49 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
50 |
module_name = cr.readUnsignedShort(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
51 |
module_flags = cr.readUnsignedShort(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
52 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
53 |
module_version_index = cr.readUnsignedShort(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
54 |
|
36526 | 55 |
requires_count = cr.readUnsignedShort(); |
56 |
requires = new RequiresEntry[requires_count]; |
|
57 |
for (int i = 0; i < requires_count; i++) |
|
58 |
requires[i] = new RequiresEntry(cr); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
59 |
|
36526 | 60 |
exports_count = cr.readUnsignedShort(); |
61 |
exports = new ExportsEntry[exports_count]; |
|
62 |
for (int i = 0; i < exports_count; i++) |
|
63 |
exports[i] = new ExportsEntry(cr); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
64 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
65 |
opens_count = cr.readUnsignedShort(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
66 |
opens = new OpensEntry[opens_count]; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
67 |
for (int i = 0; i < opens_count; i++) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
68 |
opens[i] = new OpensEntry(cr); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
69 |
|
36526 | 70 |
uses_count = cr.readUnsignedShort(); |
71 |
uses_index = new int[uses_count]; |
|
72 |
for (int i = 0; i < uses_count; i++) |
|
73 |
uses_index[i] = cr.readUnsignedShort(); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
74 |
|
36526 | 75 |
provides_count = cr.readUnsignedShort(); |
76 |
provides = new ProvidesEntry[provides_count]; |
|
77 |
for (int i = 0; i < provides_count; i++) |
|
78 |
provides[i] = new ProvidesEntry(cr); |
|
79 |
} |
|
80 |
||
81 |
public Module_attribute(int name_index, |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
82 |
int module_name, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
83 |
int module_flags, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
84 |
int module_version_index, |
36526 | 85 |
RequiresEntry[] requires, |
86 |
ExportsEntry[] exports, |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
87 |
OpensEntry[] opens, |
36526 | 88 |
int[] uses, |
89 |
ProvidesEntry[] provides) { |
|
90 |
super(name_index, 2); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
91 |
this.module_name = module_name; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
92 |
this.module_flags = module_flags; |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
93 |
this.module_version_index = module_version_index; |
36526 | 94 |
requires_count = requires.length; |
95 |
this.requires = requires; |
|
96 |
exports_count = exports.length; |
|
97 |
this.exports = exports; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
98 |
opens_count = opens.length; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
99 |
this.opens = opens; |
36526 | 100 |
uses_count = uses.length; |
101 |
this.uses_index = uses; |
|
102 |
provides_count = provides.length; |
|
103 |
this.provides = provides; |
|
104 |
} |
|
105 |
||
106 |
public String getUses(int index, ConstantPool constant_pool) throws ConstantPoolException { |
|
107 |
int i = uses_index[index]; |
|
108 |
return constant_pool.getClassInfo(i).getName(); |
|
109 |
} |
|
110 |
||
111 |
@Override |
|
112 |
public <R, D> R accept(Visitor<R, D> visitor, D data) { |
|
113 |
return visitor.visitModule(this, data); |
|
114 |
} |
|
115 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
116 |
public final int module_name; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
117 |
public final int module_flags; |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
118 |
public final int module_version_index; |
36526 | 119 |
public final int requires_count; |
120 |
public final RequiresEntry[] requires; |
|
121 |
public final int exports_count; |
|
122 |
public final ExportsEntry[] exports; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
123 |
public final int opens_count; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
124 |
public final OpensEntry[] opens; |
36526 | 125 |
public final int uses_count; |
126 |
public final int[] uses_index; |
|
127 |
public final int provides_count; |
|
128 |
public final ProvidesEntry[] provides; |
|
129 |
||
130 |
public static class RequiresEntry { |
|
131 |
RequiresEntry(ClassReader cr) throws IOException { |
|
132 |
requires_index = cr.readUnsignedShort(); |
|
133 |
requires_flags = cr.readUnsignedShort(); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
134 |
requires_version_index = cr.readUnsignedShort(); |
36526 | 135 |
} |
136 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
137 |
public RequiresEntry(int index, int flags, int version_index) { |
36526 | 138 |
this.requires_index = index; |
139 |
this.requires_flags = flags; |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
140 |
this.requires_version_index = version_index; |
36526 | 141 |
} |
142 |
||
143 |
public String getRequires(ConstantPool constant_pool) throws ConstantPoolException { |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
144 |
CONSTANT_Module_info info = constant_pool.getModuleInfo(requires_index); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
145 |
return info.getName(); |
36526 | 146 |
} |
147 |
||
148 |
public static final int length = 4; |
|
149 |
||
150 |
public final int requires_index; |
|
151 |
public final int requires_flags; |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
152 |
public final int requires_version_index; |
36526 | 153 |
} |
154 |
||
155 |
public static class ExportsEntry { |
|
156 |
ExportsEntry(ClassReader cr) throws IOException { |
|
157 |
exports_index = cr.readUnsignedShort(); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
158 |
exports_flags = cr.readUnsignedShort(); |
36526 | 159 |
exports_to_count = cr.readUnsignedShort(); |
160 |
exports_to_index = new int[exports_to_count]; |
|
161 |
for (int i = 0; i < exports_to_count; i++) |
|
162 |
exports_to_index[i] = cr.readUnsignedShort(); |
|
163 |
} |
|
164 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
165 |
public ExportsEntry(int index, int flags, int[] to) { |
36526 | 166 |
this.exports_index = index; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
167 |
this.exports_flags = flags; |
36526 | 168 |
this.exports_to_count = to.length; |
169 |
this.exports_to_index = to; |
|
170 |
} |
|
171 |
||
172 |
public int length() { |
|
173 |
return 4 + 2 * exports_to_index.length; |
|
174 |
} |
|
175 |
||
176 |
public final int exports_index; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
177 |
public final int exports_flags; |
36526 | 178 |
public final int exports_to_count; |
179 |
public final int[] exports_to_index; |
|
180 |
} |
|
181 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
182 |
public static class OpensEntry { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
183 |
OpensEntry(ClassReader cr) throws IOException { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
184 |
opens_index = cr.readUnsignedShort(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
185 |
opens_flags = cr.readUnsignedShort(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
186 |
opens_to_count = cr.readUnsignedShort(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
187 |
opens_to_index = new int[opens_to_count]; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
188 |
for (int i = 0; i < opens_to_count; i++) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
189 |
opens_to_index[i] = cr.readUnsignedShort(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
190 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
191 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
192 |
public OpensEntry(int index, int flags, int[] to) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
193 |
this.opens_index = index; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
194 |
this.opens_flags = flags; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
195 |
this.opens_to_count = to.length; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
196 |
this.opens_to_index = to; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
197 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
198 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
199 |
public int length() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
200 |
return 4 + 2 * opens_to_index.length; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
201 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
202 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
203 |
public final int opens_index; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
204 |
public final int opens_flags; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
205 |
public final int opens_to_count; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
206 |
public final int[] opens_to_index; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
207 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
208 |
|
36526 | 209 |
public static class ProvidesEntry { |
210 |
ProvidesEntry(ClassReader cr) throws IOException { |
|
211 |
provides_index = cr.readUnsignedShort(); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
212 |
with_count = cr.readUnsignedShort(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
213 |
with_index = new int[with_count]; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
214 |
for (int i = 0; i < with_count; i++) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
215 |
with_index[i] = cr.readUnsignedShort(); |
36526 | 216 |
} |
217 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
218 |
public ProvidesEntry(int provides, int[] with) { |
36526 | 219 |
this.provides_index = provides; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
220 |
this.with_count = with.length; |
36526 | 221 |
this.with_index = with; |
222 |
} |
|
223 |
||
224 |
public static final int length = 4; |
|
225 |
||
226 |
public final int provides_index; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
227 |
public final int with_count; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
36526
diff
changeset
|
228 |
public final int[] with_index; |
36526 | 229 |
} |
230 |
} |