author | anazarov |
Wed, 18 Jan 2017 21:09:19 +0300 | |
changeset 43259 | 1a8c1621084d |
parent 42822 | a84956e7ee4d |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, 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. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
import com.sun.tools.classfile.ClassFile; |
|
25 |
import com.sun.tools.classfile.ConstantPool; |
|
26 |
import com.sun.tools.classfile.ConstantPoolException; |
|
27 |
import com.sun.tools.classfile.Module_attribute; |
|
28 |
||
29 |
import java.io.IOException; |
|
30 |
import java.lang.annotation.Retention; |
|
31 |
import java.lang.annotation.RetentionPolicy; |
|
32 |
import java.lang.reflect.Method; |
|
33 |
import java.nio.file.Files; |
|
34 |
import java.nio.file.Path; |
|
35 |
import java.nio.file.Paths; |
|
36 |
import java.util.ArrayList; |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36778
diff
changeset
|
37 |
import java.util.Arrays; |
36526 | 38 |
import java.util.HashMap; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
39 |
import java.util.LinkedHashMap; |
36526 | 40 |
import java.util.List; |
41 |
import java.util.Map; |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
42 |
import java.util.Objects; |
36526 | 43 |
import java.util.regex.Pattern; |
44 |
import java.util.stream.Collectors; |
|
45 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
46 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
47 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
48 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
49 |
|
36526 | 50 |
public class ModuleTestBase { |
51 |
protected final ToolBox tb = new ToolBox(); |
|
52 |
private final TestResult tr = new TestResult(); |
|
53 |
||
54 |
||
55 |
protected void run() throws Exception { |
|
56 |
boolean noTests = true; |
|
57 |
for (Method method : this.getClass().getMethods()) { |
|
58 |
if (method.isAnnotationPresent(Test.class)) { |
|
59 |
noTests = false; |
|
60 |
try { |
|
61 |
tr.addTestCase(method.getName()); |
|
62 |
method.invoke(this, Paths.get(method.getName())); |
|
63 |
} catch (Throwable th) { |
|
64 |
tr.addFailure(th); |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
if (noTests) throw new AssertionError("Tests are not found."); |
|
69 |
tr.checkStatus(); |
|
70 |
} |
|
71 |
||
72 |
protected void testModuleAttribute(Path modulePath, ModuleDescriptor moduleDescriptor) throws Exception { |
|
73 |
ClassFile classFile = ClassFile.read(modulePath.resolve("module-info.class")); |
|
74 |
Module_attribute moduleAttribute = (Module_attribute) classFile.getAttribute("Module"); |
|
75 |
ConstantPool constantPool = classFile.constant_pool; |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
76 |
testModuleName(moduleDescriptor, moduleAttribute, constantPool); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
77 |
testModuleFlags(moduleDescriptor, moduleAttribute); |
36526 | 78 |
testRequires(moduleDescriptor, moduleAttribute, constantPool); |
79 |
testExports(moduleDescriptor, moduleAttribute, constantPool); |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
80 |
testOpens(moduleDescriptor, moduleAttribute, constantPool); |
36526 | 81 |
testProvides(moduleDescriptor, moduleAttribute, constantPool); |
82 |
testUses(moduleDescriptor, moduleAttribute, constantPool); |
|
83 |
} |
|
84 |
||
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
85 |
private void testModuleName(ModuleDescriptor moduleDescriptor, Module_attribute module, ConstantPool constantPool) throws ConstantPoolException { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
86 |
tr.checkEquals(constantPool.getModuleInfo(module.module_name).getName(), moduleDescriptor.name, "Unexpected module name"); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
87 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
88 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
89 |
private void testModuleFlags(ModuleDescriptor moduleDescriptor, Module_attribute module) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
90 |
tr.checkEquals(module.module_flags, moduleDescriptor.flags, "Unexpected module flags"); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
91 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
92 |
|
36526 | 93 |
private void testRequires(ModuleDescriptor moduleDescriptor, Module_attribute module, ConstantPool constantPool) throws ConstantPoolException { |
94 |
tr.checkEquals(module.requires_count, moduleDescriptor.requires.size(), "Wrong amount of requires."); |
|
95 |
||
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
96 |
List<Requires> actualRequires = new ArrayList<>(); |
36526 | 97 |
for (Module_attribute.RequiresEntry require : module.requires) { |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
98 |
actualRequires.add(new Requires( |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
99 |
require.getRequires(constantPool), |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
100 |
require.requires_flags)); |
36526 | 101 |
} |
102 |
tr.checkContains(actualRequires, moduleDescriptor.requires, "Lists of requires don't match"); |
|
103 |
} |
|
104 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
105 |
private void testExports(ModuleDescriptor moduleDescriptor, Module_attribute module, ConstantPool constantPool) throws ConstantPoolException { |
36526 | 106 |
tr.checkEquals(module.exports_count, moduleDescriptor.exports.size(), "Wrong amount of exports."); |
107 |
for (Module_attribute.ExportsEntry export : module.exports) { |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
108 |
String pkg = constantPool.getPackageInfo(export.exports_index).getName(); |
36526 | 109 |
if (tr.checkTrue(moduleDescriptor.exports.containsKey(pkg), "Unexpected export " + pkg)) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
110 |
Export expectedExport = moduleDescriptor.exports.get(pkg); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
111 |
tr.checkEquals(expectedExport.mask, export.exports_flags, "Wrong export flags"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
112 |
List<String> expectedTo = expectedExport.to; |
36526 | 113 |
tr.checkEquals(export.exports_to_count, expectedTo.size(), "Wrong amount of exports to"); |
114 |
List<String> actualTo = new ArrayList<>(); |
|
115 |
for (int toIdx : export.exports_to_index) { |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
116 |
actualTo.add(constantPool.getModuleInfo(toIdx).getName()); |
36526 | 117 |
} |
118 |
tr.checkContains(actualTo, expectedTo, "Lists of \"exports to\" don't match."); |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
122 |
||
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
123 |
private void testOpens(ModuleDescriptor moduleDescriptor, Module_attribute module, ConstantPool constantPool) throws ConstantPoolException { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
124 |
tr.checkEquals(module.opens_count, moduleDescriptor.opens.size(), "Wrong amount of opens."); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
125 |
for (Module_attribute.OpensEntry open : module.opens) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
126 |
String pkg = constantPool.getPackageInfo(open.opens_index).getName(); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
127 |
if (tr.checkTrue(moduleDescriptor.opens.containsKey(pkg), "Unexpected open " + pkg)) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
128 |
Open expectedOpen = moduleDescriptor.opens.get(pkg); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
129 |
tr.checkEquals(expectedOpen.mask, open.opens_flags, "Wrong open flags"); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
130 |
List<String> expectedTo = expectedOpen.to; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
131 |
tr.checkEquals(open.opens_to_count, expectedTo.size(), "Wrong amount of opens to"); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
132 |
List<String> actualTo = new ArrayList<>(); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
133 |
for (int toIdx : open.opens_to_index) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
134 |
actualTo.add(constantPool.getModuleInfo(toIdx).getName()); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
135 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
136 |
tr.checkContains(actualTo, expectedTo, "Lists of \"opens to\" don't match."); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
137 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
138 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
139 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
140 |
|
36526 | 141 |
private void testUses(ModuleDescriptor moduleDescriptor, Module_attribute module, ConstantPool constantPool) throws ConstantPoolException { |
142 |
tr.checkEquals(module.uses_count, moduleDescriptor.uses.size(), "Wrong amount of uses."); |
|
143 |
List<String> actualUses = new ArrayList<>(); |
|
144 |
for (int usesIdx : module.uses_index) { |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
145 |
String uses = constantPool.getClassInfo(usesIdx).getBaseName(); |
36526 | 146 |
actualUses.add(uses); |
147 |
} |
|
148 |
tr.checkContains(actualUses, moduleDescriptor.uses, "Lists of uses don't match"); |
|
149 |
} |
|
150 |
||
151 |
private void testProvides(ModuleDescriptor moduleDescriptor, Module_attribute module, ConstantPool constantPool) throws ConstantPoolException { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
152 |
int moduleProvidesCount = Arrays.asList(module.provides).stream() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
153 |
.mapToInt(e -> e.with_index.length) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
154 |
.sum(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
155 |
int moduleDescriptorProvidesCount = moduleDescriptor.provides.values().stream() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
156 |
.mapToInt(impls -> impls.size()) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
157 |
.sum(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
158 |
tr.checkEquals(moduleProvidesCount, moduleDescriptorProvidesCount, "Wrong amount of provides."); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
159 |
Map<String, List<String>> actualProvides = new HashMap<>(); |
36526 | 160 |
for (Module_attribute.ProvidesEntry provide : module.provides) { |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
161 |
String provides = constantPool.getClassInfo(provide.provides_index).getBaseName(); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
162 |
List<String> impls = new ArrayList<>(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
163 |
for (int i = 0; i < provide.with_count; i++) { |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
164 |
String with = constantPool.getClassInfo(provide.with_index[i]).getBaseName(); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
165 |
impls.add(with); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
166 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
167 |
actualProvides.put(provides, impls); |
36526 | 168 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
169 |
tr.checkContains(actualProvides.entrySet(), moduleDescriptor.provides.entrySet(), "Lists of provides don't match"); |
36526 | 170 |
} |
171 |
||
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36778
diff
changeset
|
172 |
protected void compile(Path base, String... options) throws IOException { |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
173 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
36778
diff
changeset
|
174 |
.options(options) |
36526 | 175 |
.files(findJavaFiles(base)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
176 |
.run(Task.Expect.SUCCESS) |
36526 | 177 |
.writeAll(); |
178 |
} |
|
179 |
||
180 |
private static Path[] findJavaFiles(Path src) throws IOException { |
|
181 |
return Files.find(src, Integer.MAX_VALUE, (path, attr) -> path.toString().endsWith(".java")) |
|
182 |
.toArray(Path[]::new); |
|
183 |
} |
|
184 |
||
185 |
@Retention(RetentionPolicy.RUNTIME) |
|
186 |
@interface Test { |
|
187 |
} |
|
188 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
189 |
interface Mask { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
190 |
int getMask(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
191 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
192 |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
193 |
public enum ModuleFlag implements Mask { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
194 |
OPEN("open", Module_attribute.ACC_OPEN); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
195 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
196 |
private final String token; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
197 |
private final int mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
198 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
199 |
ModuleFlag(String token, int mask) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
200 |
this.token = token; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
201 |
this.mask = mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
202 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
203 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
204 |
@Override |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
205 |
public int getMask() { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
206 |
return mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
207 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
208 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
209 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
210 |
public enum RequiresFlag implements Mask { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
211 |
TRANSITIVE("transitive", Module_attribute.ACC_TRANSITIVE), |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
212 |
STATIC("static", Module_attribute.ACC_STATIC_PHASE), |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
213 |
MANDATED("", Module_attribute.ACC_MANDATED); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
214 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
215 |
private final String token; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
216 |
private final int mask; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
217 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
218 |
RequiresFlag(String token, int mask) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
219 |
this.token = token; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
220 |
this.mask = mask; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
221 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
222 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
223 |
@Override |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
224 |
public int getMask() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
225 |
return mask; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
226 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
227 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
228 |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
229 |
public enum ExportsFlag implements Mask { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
230 |
SYNTHETIC("", Module_attribute.ACC_SYNTHETIC); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
231 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
232 |
private final String token; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
233 |
private final int mask; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
234 |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
235 |
ExportsFlag(String token, int mask) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
236 |
this.token = token; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
237 |
this.mask = mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
238 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
239 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
240 |
@Override |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
241 |
public int getMask() { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
242 |
return mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
243 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
244 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
245 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
246 |
public enum OpensFlag implements Mask { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
247 |
SYNTHETIC("", Module_attribute.ACC_SYNTHETIC); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
248 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
249 |
private final String token; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
250 |
private final int mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
251 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
252 |
OpensFlag(String token, int mask) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
253 |
this.token = token; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
254 |
this.mask = mask; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
255 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
256 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
257 |
@Override |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
258 |
public int getMask() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
259 |
return mask; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
260 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
261 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
262 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
263 |
private class Export { |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
264 |
private final String pkg; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
265 |
private final int mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
266 |
private final List<String> to = new ArrayList<>(); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
267 |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
268 |
Export(String pkg, int mask) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
269 |
this.pkg = pkg; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
270 |
this.mask = mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
271 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
272 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
273 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
274 |
private class Open { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
275 |
private final String pkg; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
276 |
private final int mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
277 |
private final List<String> to = new ArrayList<>(); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
278 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
279 |
Open(String pkg, int mask) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
280 |
this.pkg = pkg; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
281 |
this.mask = mask; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
282 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
283 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
284 |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
285 |
private class Requires { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
286 |
private final String module; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
287 |
private final int mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
288 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
289 |
Requires(String module, int mask) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
290 |
this.module = module; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
291 |
this.mask = mask; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
292 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
293 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
294 |
@Override |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
295 |
public boolean equals(Object o) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
296 |
if (this == o) return true; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
297 |
if (o == null || getClass() != o.getClass()) return false; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
298 |
Requires requires = (Requires) o; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
299 |
return mask == requires.mask && |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
300 |
Objects.equals(module, requires.module); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
301 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
302 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
303 |
@Override |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
304 |
public int hashCode() { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
305 |
return Objects.hash(module, mask); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
306 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
307 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
308 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
309 |
protected class ModuleDescriptor { |
36526 | 310 |
|
311 |
private final String name; |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
312 |
private final int flags; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
313 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
314 |
private final List<Requires> requires = new ArrayList<>(); |
36526 | 315 |
|
316 |
{ |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
317 |
requires.add(new Requires("java.base", computeMask(RequiresFlag.MANDATED))); |
36526 | 318 |
} |
319 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
320 |
private final Map<String, Export> exports = new HashMap<>(); |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
321 |
private final Map<String, Open> opens = new HashMap<>(); |
36526 | 322 |
|
323 |
//List of service and implementation |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
324 |
private final Map<String, List<String>> provides = new LinkedHashMap<>(); |
36526 | 325 |
private final List<String> uses = new ArrayList<>(); |
326 |
||
327 |
private static final String LINE_END = ";\n"; |
|
328 |
||
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
329 |
StringBuilder content = new StringBuilder(""); |
36526 | 330 |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
331 |
public ModuleDescriptor(String moduleName, ModuleFlag... flags) { |
36526 | 332 |
this.name = moduleName; |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
333 |
this.flags = computeMask(flags); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
334 |
for (ModuleFlag flag : flags) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
335 |
content.append(flag.token).append(" "); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
336 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
337 |
content.append("module ").append(moduleName).append('{').append('\n'); |
36526 | 338 |
} |
339 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
340 |
public ModuleDescriptor requires(String module) { |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
341 |
this.requires.add(new Requires(module, 0)); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
342 |
content.append(" requires ").append(module).append(LINE_END); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
343 |
|
36526 | 344 |
return this; |
345 |
} |
|
346 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
347 |
public ModuleDescriptor requires(String module, RequiresFlag... flags) { |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
348 |
this.requires.add(new Requires(module, computeMask(flags))); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
349 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
350 |
content.append(" requires "); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
351 |
for (RequiresFlag flag : flags) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
352 |
content.append(flag.token).append(" "); |
36526 | 353 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
354 |
content.append(module).append(LINE_END); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
355 |
|
36526 | 356 |
return this; |
357 |
} |
|
358 |
||
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
359 |
public ModuleDescriptor exports(String pkg, ExportsFlag... flags) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
360 |
this.exports.put(toInternalForm(pkg), new Export(toInternalForm(pkg), computeMask(flags))); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
361 |
content.append(" exports "); |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
362 |
for (ExportsFlag flag : flags) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
363 |
content.append(flag.token).append(" "); |
36526 | 364 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
365 |
content.append(pkg).append(LINE_END); |
36526 | 366 |
return this; |
367 |
} |
|
368 |
||
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
369 |
public ModuleDescriptor exportsTo(String pkg, String to, ExportsFlag... flags) { |
36526 | 370 |
List<String> tos = Pattern.compile(",") |
371 |
.splitAsStream(to) |
|
372 |
.map(String::trim) |
|
373 |
.collect(Collectors.toList()); |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
374 |
this.exports.compute(toInternalForm(pkg), (k,v) -> new Export(k, computeMask(flags))) |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
375 |
.to.addAll(tos); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
376 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
377 |
content.append(" exports "); |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
378 |
for (ExportsFlag flag : flags) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
379 |
content.append(flag.token).append(" "); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
380 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
381 |
content.append(pkg).append(" to ").append(to).append(LINE_END); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
382 |
return this; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
383 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
384 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
385 |
public ModuleDescriptor opens(String pkg, OpensFlag... flags) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
386 |
this.opens.put(toInternalForm(pkg), new Open(toInternalForm(pkg), computeMask(flags))); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
387 |
content.append(" opens "); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
388 |
for (OpensFlag flag : flags) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
389 |
content.append(flag.token).append(" "); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
390 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
391 |
content.append(pkg).append(LINE_END); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
392 |
return this; |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
393 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
394 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
395 |
public ModuleDescriptor opensTo(String pkg, String to, OpensFlag... flags) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
396 |
List<String> tos = Pattern.compile(",") |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
397 |
.splitAsStream(to) |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
398 |
.map(String::trim) |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
399 |
.collect(Collectors.toList()); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
400 |
this.opens.compute(toInternalForm(pkg), (k,v) -> new Open(toInternalForm(k), computeMask(flags))) |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
401 |
.to.addAll(tos); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
402 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
403 |
content.append(" opens "); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
404 |
for (OpensFlag flag : flags) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
405 |
content.append(flag.token).append(" "); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
406 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
407 |
content.append(pkg).append(" to ").append(to).append(LINE_END); |
36526 | 408 |
return this; |
409 |
} |
|
410 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
411 |
public ModuleDescriptor provides(String provides, String... with) { |
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
412 |
List<String> impls = Arrays.stream(with) |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
413 |
.map(this::toInternalForm) |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
414 |
.collect(Collectors.toList()); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
415 |
this.provides.put(toInternalForm(provides), impls); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
416 |
content.append(" provides ") |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
417 |
.append(provides) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
418 |
.append(" with ") |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
419 |
.append(String.join(",", with)) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
420 |
.append(LINE_END); |
36526 | 421 |
return this; |
422 |
} |
|
423 |
||
424 |
public ModuleDescriptor uses(String... uses) { |
|
425 |
for (String use : uses) { |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
426 |
this.uses.add(toInternalForm(use)); |
36526 | 427 |
content.append(" uses ").append(use).append(LINE_END); |
428 |
} |
|
429 |
return this; |
|
430 |
} |
|
431 |
||
432 |
public ModuleDescriptor write(Path path) throws IOException { |
|
433 |
String src = content.append('}').toString(); |
|
434 |
||
435 |
tb.createDirectories(path); |
|
436 |
tb.writeJavaFiles(path, src); |
|
437 |
return this; |
|
438 |
} |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
439 |
|
43259
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
440 |
private String toInternalForm(String name) { |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
441 |
return name.replace('.', '/'); |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
442 |
} |
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
443 |
|
1a8c1621084d
8170250: update/improve testing of classfile module attribute
anazarov
parents:
42822
diff
changeset
|
444 |
private int computeMask(Mask... masks) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
445 |
return Arrays.stream(masks) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
446 |
.map(Mask::getMask) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
447 |
.reduce((a, b) -> a | b) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
448 |
.orElseGet(() -> 0); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
449 |
} |
36526 | 450 |
} |
451 |
} |