author | mbaesken |
Wed, 10 Apr 2019 08:51:38 +0200 | |
changeset 54485 | ddc19ea5059c |
parent 52804 | 28094715ae71 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
52804
28094715ae71
8214718: Update missing copyright year in build system
ihse
parents:
51499
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
36511 | 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 |
package build.tools.module; |
|
26 |
||
27 |
import java.io.BufferedWriter; |
|
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
28 |
import java.io.IOException; |
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
29 |
import java.io.PrintWriter; |
36511 | 30 |
import java.nio.file.Files; |
31 |
import java.nio.file.Path; |
|
32 |
import java.nio.file.Paths; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
33 |
import java.util.ArrayList; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
34 |
import java.util.Arrays; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
35 |
import java.util.Collections; |
36511 | 36 |
import java.util.HashMap; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
37 |
import java.util.LinkedHashSet; |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
38 |
import java.util.List; |
36511 | 39 |
import java.util.Map; |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
40 |
import java.util.Objects; |
36511 | 41 |
import java.util.Set; |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
42 |
import java.util.stream.Collectors; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
43 |
import java.util.stream.Stream; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
44 |
import static java.util.stream.Collectors.*; |
36511 | 45 |
|
46 |
/** |
|
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
47 |
* A build tool to extend the module-info.java in the source tree for |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
48 |
* platform-specific exports, opens, uses, and provides and write to |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
49 |
* the specified output file. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
50 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
51 |
* GenModuleInfoSource will be invoked for each module that has |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
52 |
* module-info.java.extra in the source directory. |
36511 | 53 |
* |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
54 |
* The extra exports, opens, uses, provides can be specified |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
55 |
* in module-info.java.extra. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
56 |
* Injecting platform-specific requires is not supported. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
57 |
* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
58 |
* @see build.tools.module.ModuleInfoExtraTest for basic testing |
36511 | 59 |
*/ |
60 |
public class GenModuleInfoSource { |
|
61 |
private final static String USAGE = |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
62 |
"Usage: GenModuleInfoSource -o <output file> \n" + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
63 |
" --source-file <module-info-java>\n" + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
64 |
" --modules <module-name>[,<module-name>...]\n" + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
65 |
" <module-info.java.extra> ...\n"; |
36511 | 66 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
67 |
static boolean verbose = false; |
36511 | 68 |
public static void main(String... args) throws Exception { |
69 |
Path outfile = null; |
|
70 |
Path moduleInfoJava = null; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
71 |
Set<String> modules = Collections.emptySet(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
72 |
List<Path> extras = new ArrayList<>(); |
36511 | 73 |
// validate input arguments |
74 |
for (int i = 0; i < args.length; i++){ |
|
75 |
String option = args[i]; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
76 |
String arg = i+1 < args.length ? args[i+1] : null; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
77 |
switch (option) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
78 |
case "-o": |
36511 | 79 |
outfile = Paths.get(arg); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
80 |
i++; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
81 |
break; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
82 |
case "--source-file": |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
83 |
moduleInfoJava = Paths.get(arg); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
84 |
if (Files.notExists(moduleInfoJava)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
85 |
throw new IllegalArgumentException(moduleInfoJava + " not exist"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
86 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
87 |
i++; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
88 |
break; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
89 |
case "--modules": |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
90 |
modules = Arrays.stream(arg.split(",")) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
91 |
.collect(toSet()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
92 |
i++; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
93 |
break; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
94 |
case "-v": |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
95 |
verbose = true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
96 |
break; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
97 |
default: |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
98 |
Path file = Paths.get(option); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
99 |
if (Files.notExists(file)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
100 |
throw new IllegalArgumentException(file + " not exist"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
101 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
102 |
extras.add(file); |
36511 | 103 |
} |
104 |
} |
|
105 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
106 |
if (moduleInfoJava == null || outfile == null || |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
107 |
modules.isEmpty() || extras.isEmpty()) { |
36511 | 108 |
System.err.println(USAGE); |
109 |
System.exit(-1); |
|
110 |
} |
|
111 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
112 |
GenModuleInfoSource genModuleInfo = |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
113 |
new GenModuleInfoSource(moduleInfoJava, extras, modules); |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
114 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
115 |
// generate new module-info.java |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
116 |
genModuleInfo.generate(outfile); |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
117 |
} |
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
118 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
119 |
final Path sourceFile; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
120 |
final List<Path> extraFiles; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
121 |
final ModuleInfo extras; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
122 |
final Set<String> modules; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
123 |
final ModuleInfo moduleInfo; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
124 |
GenModuleInfoSource(Path sourceFile, List<Path> extraFiles, Set<String> modules) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
125 |
throws IOException |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
126 |
{ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
127 |
this.sourceFile = sourceFile; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
128 |
this.extraFiles = extraFiles; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
129 |
this.modules = modules; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
130 |
this.moduleInfo = new ModuleInfo(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
131 |
this.moduleInfo.parse(sourceFile); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
132 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
133 |
// parse module-info.java.extra |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
134 |
this.extras = new ModuleInfo(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
135 |
for (Path file : extraFiles) { |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
136 |
extras.parseExtra(file); |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
137 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
138 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
139 |
// merge with module-info.java.extra |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
140 |
moduleInfo.augmentModuleInfo(extras, modules); |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
141 |
} |
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
142 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
143 |
void generate(Path output) throws IOException { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
144 |
List<String> lines = Files.readAllLines(sourceFile); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
145 |
try (BufferedWriter bw = Files.newBufferedWriter(output); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
146 |
PrintWriter writer = new PrintWriter(bw)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
147 |
// write the copyright header and lines up to module declaration |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
148 |
for (String l : lines) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
149 |
writer.println(l); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
150 |
if (l.trim().startsWith("module ")) { |
42355
30cac79609ee
8170633: backslashes in gensrc/module-info.java comments need escaping
mchung
parents:
42338
diff
changeset
|
151 |
// print URI rather than file path to avoid escape |
30cac79609ee
8170633: backslashes in gensrc/module-info.java comments need escaping
mchung
parents:
42338
diff
changeset
|
152 |
writer.format(" // source file: %s%n", sourceFile.toUri()); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
153 |
for (Path file: extraFiles) { |
42355
30cac79609ee
8170633: backslashes in gensrc/module-info.java comments need escaping
mchung
parents:
42338
diff
changeset
|
154 |
writer.format(" // %s%n", file.toUri()); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
155 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
156 |
break; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
157 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
158 |
} |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
159 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
160 |
// requires |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
161 |
for (String l : lines) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
162 |
if (l.trim().startsWith("requires")) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
163 |
writer.println(l); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
164 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
165 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
166 |
// write exports, opens, uses, and provides |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
167 |
moduleInfo.print(writer); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
168 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
169 |
// close |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
170 |
writer.println("}"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
171 |
} |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
172 |
} |
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
173 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
174 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
175 |
class ModuleInfo { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
176 |
final Map<String, Statement> exports = new HashMap<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
177 |
final Map<String, Statement> opens = new HashMap<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
178 |
final Map<String, Statement> uses = new HashMap<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
179 |
final Map<String, Statement> provides = new HashMap<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
180 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
181 |
Statement getStatement(String directive, String name) { |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
182 |
Objects.requireNonNull(name); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
183 |
switch (directive) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
184 |
case "exports": |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
185 |
if (moduleInfo.exports.containsKey(name) && |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
186 |
moduleInfo.exports.get(name).isUnqualified()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
187 |
throw new IllegalArgumentException(sourceFile + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
188 |
" already has " + directive + " " + name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
189 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
190 |
return exports.computeIfAbsent(name, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
191 |
_n -> new Statement("exports", "to", name)); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
192 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
193 |
case "opens": |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
194 |
if (moduleInfo.opens.containsKey(name) && |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
195 |
moduleInfo.opens.get(name).isUnqualified()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
196 |
throw new IllegalArgumentException(sourceFile + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
197 |
" already has " + directive + " " + name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
198 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
199 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
200 |
if (moduleInfo.opens.containsKey(name)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
201 |
throw new IllegalArgumentException(sourceFile + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
202 |
" already has " + directive + " " + name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
203 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
204 |
return opens.computeIfAbsent(name, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
205 |
_n -> new Statement("opens", "to", name)); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
206 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
207 |
case "uses": |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
208 |
return uses.computeIfAbsent(name, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
209 |
_n -> new Statement("uses", "", name)); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
210 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
211 |
case "provides": |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
212 |
return provides.computeIfAbsent(name, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
213 |
_n -> new Statement("provides", "with", name, true)); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
214 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
215 |
default: |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
216 |
throw new IllegalArgumentException(directive); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
217 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
218 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
219 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
220 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
221 |
/* |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
222 |
* Augment this ModuleInfo with module-info.java.extra |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
223 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
224 |
void augmentModuleInfo(ModuleInfo extraFiles, Set<String> modules) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
225 |
// API package exported in the original module-info.java |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
226 |
extraFiles.exports.entrySet() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
227 |
.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
228 |
.filter(e -> exports.containsKey(e.getKey()) && |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
229 |
e.getValue().filter(modules)) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
230 |
.forEach(e -> mergeExportsOrOpens(exports.get(e.getKey()), |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
231 |
e.getValue(), |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
232 |
modules)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
233 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
234 |
// add exports that are not defined in the original module-info.java |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
235 |
extraFiles.exports.entrySet() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
236 |
.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
237 |
.filter(e -> !exports.containsKey(e.getKey()) && |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
238 |
e.getValue().filter(modules)) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
239 |
.forEach(e -> addTargets(getStatement("exports", e.getKey()), |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
240 |
e.getValue(), |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
241 |
modules)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
242 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
243 |
// API package opened in the original module-info.java |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
244 |
extraFiles.opens.entrySet() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
245 |
.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
246 |
.filter(e -> opens.containsKey(e.getKey()) && |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
247 |
e.getValue().filter(modules)) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
248 |
.forEach(e -> mergeExportsOrOpens(opens.get(e.getKey()), |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
249 |
e.getValue(), |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
250 |
modules)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
251 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
252 |
// add opens that are not defined in the original module-info.java |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
253 |
extraFiles.opens.entrySet() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
254 |
.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
255 |
.filter(e -> !opens.containsKey(e.getKey()) && |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
256 |
e.getValue().filter(modules)) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
257 |
.forEach(e -> addTargets(getStatement("opens", e.getKey()), |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
258 |
e.getValue(), |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
259 |
modules)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
260 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
261 |
// provides |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
262 |
extraFiles.provides.keySet() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
263 |
.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
264 |
.filter(service -> provides.containsKey(service)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
265 |
.forEach(service -> mergeProvides(service, |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
266 |
extraFiles.provides.get(service))); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
267 |
extraFiles.provides.keySet() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
268 |
.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
269 |
.filter(service -> !provides.containsKey(service)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
270 |
.forEach(service -> provides.put(service, |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
271 |
extraFiles.provides.get(service))); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
272 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
273 |
// uses |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
274 |
extraFiles.uses.keySet() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
275 |
.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
276 |
.filter(service -> !uses.containsKey(service)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
277 |
.forEach(service -> uses.put(service, extraFiles.uses.get(service))); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
278 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
279 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
280 |
// add qualified exports or opens to known modules only |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
281 |
private void addTargets(Statement statement, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
282 |
Statement extra, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
283 |
Set<String> modules) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
284 |
{ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
285 |
extra.targets.stream() |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
286 |
.filter(mn -> modules.contains(mn)) |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
287 |
.forEach(mn -> statement.addTarget(mn)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
288 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
289 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
290 |
private void mergeExportsOrOpens(Statement statement, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
291 |
Statement extra, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
292 |
Set<String> modules) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
293 |
{ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
294 |
String pn = statement.name; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
295 |
if (statement.isUnqualified() && extra.isQualified()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
296 |
throw new RuntimeException("can't add qualified exports to " + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
297 |
"unqualified exports " + pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
298 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
299 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
300 |
Set<String> mods = extra.targets.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
301 |
.filter(mn -> statement.targets.contains(mn)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
302 |
.collect(toSet()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
303 |
if (mods.size() > 0) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
304 |
throw new RuntimeException("qualified exports " + pn + " to " + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
305 |
mods.toString() + " already declared in " + sourceFile); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
306 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
307 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
308 |
// add qualified exports or opens to known modules only |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
309 |
addTargets(statement, extra, modules); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
310 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
311 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
312 |
private void mergeProvides(String service, Statement extra) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
313 |
Statement statement = provides.get(service); |
36511 | 314 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
315 |
Set<String> mods = extra.targets.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
316 |
.filter(mn -> statement.targets.contains(mn)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
317 |
.collect(toSet()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
318 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
319 |
if (mods.size() > 0) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
320 |
throw new RuntimeException("qualified exports " + service + " to " + |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
321 |
mods.toString() + " already declared in " + sourceFile); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
322 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
323 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
324 |
extra.targets.stream() |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
325 |
.forEach(mn -> statement.addTarget(mn)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
326 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
327 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
328 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
329 |
void print(PrintWriter writer) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
330 |
// print unqualified exports |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
331 |
exports.entrySet().stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
332 |
.filter(e -> e.getValue().targets.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
333 |
.sorted(Map.Entry.comparingByKey()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
334 |
.forEach(e -> writer.println(e.getValue())); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
335 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
336 |
// print qualified exports |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
337 |
exports.entrySet().stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
338 |
.filter(e -> !e.getValue().targets.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
339 |
.sorted(Map.Entry.comparingByKey()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
340 |
.forEach(e -> writer.println(e.getValue())); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
341 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
342 |
// print unqualified opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
343 |
opens.entrySet().stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
344 |
.filter(e -> e.getValue().targets.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
345 |
.sorted(Map.Entry.comparingByKey()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
346 |
.forEach(e -> writer.println(e.getValue())); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
347 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
348 |
// print qualified opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
349 |
opens.entrySet().stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
350 |
.filter(e -> !e.getValue().targets.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
351 |
.sorted(Map.Entry.comparingByKey()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
352 |
.forEach(e -> writer.println(e.getValue())); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
353 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
354 |
// uses and provides |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
355 |
writer.println(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
356 |
uses.entrySet().stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
357 |
.sorted(Map.Entry.comparingByKey()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
358 |
.forEach(e -> writer.println(e.getValue())); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
359 |
provides.entrySet().stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
360 |
.sorted(Map.Entry.comparingByKey()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
361 |
.forEach(e -> writer.println(e.getValue())); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
362 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
363 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
364 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
365 |
private void parse(Path file) throws IOException { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
366 |
Parser parser = new Parser(file); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
367 |
parser.run(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
368 |
if (verbose) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
369 |
parser.dump(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
370 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
371 |
process(parser, false); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
372 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
373 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
374 |
private void parseExtra(Path file) throws IOException { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
375 |
Parser parser = new Parser(file); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
376 |
parser.run(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
377 |
if (verbose) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
378 |
parser.dump(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
379 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
380 |
process(parser, true); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
381 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
382 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
383 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
384 |
private void process(Parser parser, boolean extraFile) throws IOException { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
385 |
// no duplicate statement local in each file |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
386 |
Map<String, Statement> exports = new HashMap<>(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
387 |
Map<String, Statement> opens = new HashMap<>(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
388 |
Map<String, Statement> uses = new HashMap<>(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
389 |
Map<String, Statement> provides = new HashMap<>(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
390 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
391 |
String token = null; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
392 |
boolean hasCurlyBracket = false; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
393 |
while ((token = parser.nextToken()) != null) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
394 |
if (token.equals("module")) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
395 |
String modulename = nextIdentifier(parser); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
396 |
if (extraFile) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
397 |
throw parser.newError("cannot declare module in " + parser.sourceFile); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
398 |
} |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
399 |
skipTokenOrThrow(parser, "{", "missing {"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
400 |
hasCurlyBracket = true; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
401 |
} else if (token.equals("requires")) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
402 |
token = nextIdentifier(parser); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
403 |
if (token.equals("transitive")) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
404 |
token = nextIdentifier(parser); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
405 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
406 |
if (extraFile) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
407 |
throw parser.newError("cannot declare requires in " + parser.sourceFile); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
408 |
} |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
409 |
skipTokenOrThrow(parser, ";", "missing semicolon"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
410 |
} else if (isExportsOpensProvidesUses(token)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
411 |
// new statement |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
412 |
String keyword = token; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
413 |
String name = nextIdentifier(parser); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
414 |
Statement statement = getStatement(keyword, name); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
415 |
switch (keyword) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
416 |
case "exports": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
417 |
if (exports.containsKey(name)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
418 |
throw parser.newError("multiple " + keyword + " " + name); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
419 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
420 |
exports.put(name, statement); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
421 |
break; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
422 |
case "opens": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
423 |
if (opens.containsKey(name)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
424 |
throw parser.newError("multiple " + keyword + " " + name); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
425 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
426 |
opens.put(name, statement); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
427 |
break; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
428 |
case "uses": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
429 |
if (uses.containsKey(name)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
430 |
throw parser.newError("multiple " + keyword + " " + name); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
431 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
432 |
uses.put(name, statement); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
433 |
break; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
434 |
case "provides": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
435 |
if (provides.containsKey(name)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
436 |
throw parser.newError("multiple " + keyword + " " + name); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
437 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
438 |
provides.put(name, statement); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
439 |
break; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
440 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
441 |
String lookAhead = lookAhead(parser); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
442 |
if (lookAhead.equals(statement.qualifier)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
443 |
parser.nextToken(); // skip qualifier |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
444 |
while ((lookAhead = parser.peekToken()) != null) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
445 |
// add target name |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
446 |
name = nextIdentifier(parser); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
447 |
statement.addTarget(name); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
448 |
lookAhead = lookAhead(parser); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
449 |
if (lookAhead.equals(",") || lookAhead.equals(";")) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
450 |
parser.nextToken(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
451 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
452 |
throw parser.newError("missing semicolon"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
453 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
454 |
if (lookAhead.equals(";")) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
455 |
break; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
456 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
457 |
} |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
458 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
459 |
skipTokenOrThrow(parser, ";", "missing semicolon"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
460 |
} |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
461 |
} else if (token.equals(";")) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
462 |
continue; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
463 |
} else if (hasCurlyBracket && token.equals("}")) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
464 |
hasCurlyBracket = false; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
465 |
if (parser.peekToken() != null) { // must be EOF |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
466 |
throw parser.newError("is malformed"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
467 |
} |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
468 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
469 |
throw parser.newError("missing keyword"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
470 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
471 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
472 |
if (hasCurlyBracket) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
473 |
parser.newError("missing }"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
474 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
475 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
476 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
477 |
private boolean isExportsOpensProvidesUses(String word) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
478 |
switch (word) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
479 |
case "exports": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
480 |
case "opens": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
481 |
case "provides": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
482 |
case "uses": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
483 |
return true; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
484 |
default: |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
485 |
return false; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
486 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
487 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
488 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
489 |
private String lookAhead(Parser parser) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
490 |
String lookAhead = parser.peekToken(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
491 |
if (lookAhead == null) { // EOF |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
492 |
throw parser.newError("reach end of file"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
493 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
494 |
return lookAhead; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
495 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
496 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
497 |
private String nextIdentifier(Parser parser) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
498 |
String lookAhead = parser.peekToken(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
499 |
boolean maybeIdentifier = true; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
500 |
switch (lookAhead) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
501 |
case "module": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
502 |
case "requires": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
503 |
case "exports": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
504 |
case "opens": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
505 |
case "provides": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
506 |
case "uses": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
507 |
case "to": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
508 |
case "with": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
509 |
case ",": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
510 |
case ";": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
511 |
case "{": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
512 |
case "}": |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
513 |
maybeIdentifier = false; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
514 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
515 |
if (lookAhead == null || !maybeIdentifier) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
516 |
throw parser.newError("<identifier> missing"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
517 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
518 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
519 |
return parser.nextToken(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
520 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
521 |
|
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
522 |
private String skipTokenOrThrow(Parser parser, String token, String msg) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
523 |
// look ahead to report the proper line number |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
524 |
String lookAhead = parser.peekToken(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
525 |
if (!token.equals(lookAhead)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
526 |
throw parser.newError(msg); |
36511 | 527 |
} |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
528 |
return parser.nextToken(); |
36511 | 529 |
} |
530 |
} |
|
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
531 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
532 |
static class Statement { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
533 |
final String directive; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
534 |
final String qualifier; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
535 |
final String name; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
536 |
final Set<String> targets = new LinkedHashSet<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
537 |
final boolean ordered; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
538 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
539 |
Statement(String directive, String qualifier, String name) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
540 |
this(directive, qualifier, name, false); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
541 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
542 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
543 |
Statement(String directive, String qualifier, String name, boolean ordered) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
544 |
this.directive = directive; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
545 |
this.qualifier = qualifier; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
546 |
this.name = name; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
547 |
this.ordered = ordered; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
548 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
549 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
550 |
Statement addTarget(String mn) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
551 |
if (mn.isEmpty()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
552 |
throw new IllegalArgumentException("empty module name"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
553 |
targets.add(mn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
554 |
return this; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
555 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
556 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
557 |
boolean isQualified() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
558 |
return targets.size() > 0; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
559 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
560 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
561 |
boolean isUnqualified() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
562 |
return targets.isEmpty(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
563 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
564 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
565 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
566 |
* Returns true if this statement is unqualified or it has |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
567 |
* at least one target in the given names. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
568 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
569 |
boolean filter(Set<String> names) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
570 |
if (isUnqualified()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
571 |
return true; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
572 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
573 |
return targets.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
574 |
.filter(mn -> names.contains(mn)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
575 |
.findAny().isPresent(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
576 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
577 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
578 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
579 |
@Override |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
580 |
public String toString() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
581 |
StringBuilder sb = new StringBuilder(" "); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
582 |
sb.append(directive).append(" ").append(name); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
583 |
if (targets.isEmpty()) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
584 |
sb.append(";"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
585 |
} else if (targets.size() == 1) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
586 |
sb.append(" ").append(qualifier) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
587 |
.append(orderedTargets().collect(joining(",", " ", ";"))); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
588 |
} else { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
589 |
sb.append(" ").append(qualifier) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
590 |
.append(orderedTargets() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
591 |
.map(target -> String.format(" %s", target)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
592 |
.collect(joining(",\n", "\n", ";"))); |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
593 |
} |
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
594 |
return sb.toString(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
595 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
596 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
597 |
public Stream<String> orderedTargets() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
598 |
return ordered ? targets.stream() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
599 |
: targets.stream().sorted(); |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
600 |
} |
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
601 |
} |
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
602 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
603 |
static void trace(String fmt, Object... params) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
604 |
if (verbose) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
605 |
System.out.format(fmt, params); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
37676
diff
changeset
|
606 |
} |
36742
286b583dc969
8153035: GenModuleInfoSource strips away the API comments
mchung
parents:
36511
diff
changeset
|
607 |
} |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
608 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
609 |
static class Parser { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
610 |
private static final List<String> EMPTY = List.of(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
611 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
612 |
private final Path sourceFile; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
613 |
private boolean inCommentBlock = false; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
614 |
private List<List<String>> tokens = new ArrayList<>(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
615 |
private int lineNumber = 1; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
616 |
private int index = 0; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
617 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
618 |
Parser(Path file) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
619 |
this.sourceFile = file; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
620 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
621 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
622 |
void run() throws IOException { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
623 |
List<String> lines = Files.readAllLines(sourceFile); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
624 |
for (int lineNumber = 1; lineNumber <= lines.size(); lineNumber++) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
625 |
String l = lines.get(lineNumber - 1).trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
626 |
tokenize(l); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
627 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
628 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
629 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
630 |
/* |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
631 |
* Tokenize the given string. Comments are skipped. |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
632 |
*/ |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
633 |
List<String> tokenize(String l) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
634 |
while (!l.isEmpty()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
635 |
if (inCommentBlock) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
636 |
int comment = l.indexOf("*/"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
637 |
if (comment == -1) |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
638 |
return emptyTokens(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
639 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
640 |
// end comment block |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
641 |
inCommentBlock = false; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
642 |
if ((comment + 2) >= l.length()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
643 |
return emptyTokens(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
644 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
645 |
l = l.substring(comment + 2, l.length()).trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
646 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
647 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
648 |
// skip comment |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
649 |
int comment = l.indexOf("//"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
650 |
if (comment >= 0) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
651 |
l = l.substring(0, comment).trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
652 |
if (l.isEmpty()) return emptyTokens(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
653 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
654 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
655 |
if (l.isEmpty()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
656 |
return emptyTokens(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
657 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
658 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
659 |
int beginComment = l.indexOf("/*"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
660 |
int endComment = l.indexOf("*/"); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
661 |
if (beginComment == -1) |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
662 |
return tokens(l); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
663 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
664 |
String s1 = l.substring(0, beginComment).trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
665 |
if (endComment > 0) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
666 |
String s2 = l.substring(endComment + 2, l.length()).trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
667 |
if (s1.isEmpty()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
668 |
l = s2; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
669 |
} else if (s2.isEmpty()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
670 |
l = s1; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
671 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
672 |
l = s1 + " " + s2; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
673 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
674 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
675 |
inCommentBlock = true; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
676 |
return tokens(s1); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
677 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
678 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
679 |
return tokens(l); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
680 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
681 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
682 |
private List<String> emptyTokens() { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
683 |
this.tokens.add(EMPTY); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
684 |
return EMPTY; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
685 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
686 |
private List<String> tokens(String l) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
687 |
List<String> tokens = new ArrayList<>(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
688 |
for (String s : l.split("\\s+")) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
689 |
int pos=0; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
690 |
s = s.trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
691 |
if (s.isEmpty()) |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
692 |
continue; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
693 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
694 |
int i = s.indexOf(',', pos); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
695 |
int j = s.indexOf(';', pos); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
696 |
while ((i >= 0 && i < s.length()) || (j >= 0 && j < s.length())) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
697 |
if (j == -1 || (i >= 0 && i < j)) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
698 |
String n = s.substring(pos, i).trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
699 |
if (!n.isEmpty()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
700 |
tokens.add(n); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
701 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
702 |
tokens.add(s.substring(i, i + 1)); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
703 |
pos = i + 1; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
704 |
i = s.indexOf(',', pos); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
705 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
706 |
String n = s.substring(pos, j).trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
707 |
if (!n.isEmpty()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
708 |
tokens.add(n); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
709 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
710 |
tokens.add(s.substring(j, j + 1)); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
711 |
pos = j + 1; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
712 |
j = s.indexOf(';', pos); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
713 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
714 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
715 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
716 |
String n = s.substring(pos).trim(); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
717 |
if (!n.isEmpty()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
718 |
tokens.add(n); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
719 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
720 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
721 |
this.tokens.add(tokens); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
722 |
return tokens; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
723 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
724 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
725 |
/* |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
726 |
* Returns next token. |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
727 |
*/ |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
728 |
String nextToken() { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
729 |
while (lineNumber <= tokens.size()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
730 |
List<String> l = tokens.get(lineNumber-1); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
731 |
if (index < l.size()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
732 |
return l.get(index++); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
733 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
734 |
lineNumber++; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
735 |
index = 0; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
736 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
737 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
738 |
return null; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
739 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
740 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
741 |
/* |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
742 |
* Peeks next token. |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
743 |
*/ |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
744 |
String peekToken() { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
745 |
int ln = lineNumber; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
746 |
int i = index; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
747 |
while (ln <= tokens.size()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
748 |
List<String> l = tokens.get(ln-1); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
749 |
if (i < l.size()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
750 |
return l.get(i++); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
751 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
752 |
ln++; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
753 |
i = 0; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
754 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
755 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
756 |
return null; |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
757 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
758 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
759 |
Error newError(String msg) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
760 |
if (lineNumber <= tokens.size()) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
761 |
throw new Error(sourceFile + ", line " + |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
762 |
lineNumber + ", " + msg + " \"" + lineAt(lineNumber) + "\""); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
763 |
} else { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
764 |
throw new Error(sourceFile + ", line " + lineNumber + ", " + msg); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
765 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
766 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
767 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
768 |
void dump() { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
769 |
for (int i = 1; i <= tokens.size(); i++) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
770 |
System.out.format("%d: %s%n", i, lineAt(i)); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
771 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
772 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
773 |
|
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
774 |
private String lineAt(int i) { |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
775 |
return tokens.get(i-1).stream().collect(Collectors.joining(" ")); |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
776 |
} |
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
777 |
} |
36511 | 778 |
} |
51339
554bb4e2d10d
8202941: GenModuleInfoSource build tool does not detect missing semicolons
mchung
parents:
47216
diff
changeset
|
779 |