author | jlahoda |
Mon, 16 Jul 2018 16:31:33 +0200 | |
changeset 51123 | d7c4c42ab260 |
parent 50738 | 6cc2dc161c64 |
child 53100 | abe21b82ff7c |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
48427
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
2 |
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. |
36526 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
||
27 |
package com.sun.tools.javac.comp; |
|
28 |
||
29 |
import java.io.IOException; |
|
30 |
import java.util.Arrays; |
|
31 |
import java.util.Collection; |
|
32 |
import java.util.Collections; |
|
33 |
import java.util.EnumSet; |
|
34 |
import java.util.HashMap; |
|
35 |
import java.util.HashSet; |
|
36 |
import java.util.LinkedHashMap; |
|
37 |
import java.util.LinkedHashSet; |
|
38 |
import java.util.Map; |
|
39 |
import java.util.Set; |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
40 |
import java.util.function.Consumer; |
36526 | 41 |
import java.util.function.Predicate; |
42 |
import java.util.regex.Matcher; |
|
43 |
import java.util.regex.Pattern; |
|
43270
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
44 |
import java.util.stream.Collectors; |
36526 | 45 |
import java.util.stream.Stream; |
46 |
||
47 |
import javax.lang.model.SourceVersion; |
|
48 |
import javax.tools.JavaFileManager; |
|
49 |
import javax.tools.JavaFileManager.Location; |
|
50 |
import javax.tools.JavaFileObject; |
|
51 |
import javax.tools.JavaFileObject.Kind; |
|
52 |
import javax.tools.StandardLocation; |
|
53 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
54 |
import com.sun.source.tree.ModuleTree.ModuleKind; |
39361
cd0aca7db174
8159439: javac throws NPE with Module attribute and super_class != 0
vromero
parents:
38827
diff
changeset
|
55 |
import com.sun.tools.javac.code.ClassFinder; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
56 |
import com.sun.tools.javac.code.DeferredLintHandler; |
36526 | 57 |
import com.sun.tools.javac.code.Directive; |
58 |
import com.sun.tools.javac.code.Directive.ExportsDirective; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
59 |
import com.sun.tools.javac.code.Directive.ExportsFlag; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
60 |
import com.sun.tools.javac.code.Directive.OpensDirective; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
61 |
import com.sun.tools.javac.code.Directive.OpensFlag; |
36526 | 62 |
import com.sun.tools.javac.code.Directive.RequiresDirective; |
63 |
import com.sun.tools.javac.code.Directive.RequiresFlag; |
|
64 |
import com.sun.tools.javac.code.Directive.UsesDirective; |
|
65 |
import com.sun.tools.javac.code.Flags; |
|
48427
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
66 |
import com.sun.tools.javac.code.Flags.Flag; |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
67 |
import com.sun.tools.javac.code.Lint.LintCategory; |
36526 | 68 |
import com.sun.tools.javac.code.ModuleFinder; |
69 |
import com.sun.tools.javac.code.Source; |
|
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47485
diff
changeset
|
70 |
import com.sun.tools.javac.code.Source.Feature; |
36526 | 71 |
import com.sun.tools.javac.code.Symbol; |
72 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
|
73 |
import com.sun.tools.javac.code.Symbol.Completer; |
|
74 |
import com.sun.tools.javac.code.Symbol.CompletionFailure; |
|
75 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
76 |
import com.sun.tools.javac.code.Symbol.ModuleFlags; |
36526 | 77 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
78 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
|
79 |
import com.sun.tools.javac.code.Symtab; |
|
80 |
import com.sun.tools.javac.code.Type; |
|
38827
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
38619
diff
changeset
|
81 |
import com.sun.tools.javac.code.Types; |
36526 | 82 |
import com.sun.tools.javac.jvm.ClassWriter; |
83 |
import com.sun.tools.javac.jvm.JNIWriter; |
|
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
84 |
import com.sun.tools.javac.jvm.Target; |
36526 | 85 |
import com.sun.tools.javac.main.Option; |
86 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
|
87 |
import com.sun.tools.javac.resources.CompilerProperties.Warnings; |
|
88 |
import com.sun.tools.javac.tree.JCTree; |
|
89 |
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
90 |
import com.sun.tools.javac.tree.JCTree.JCDirective; |
36526 | 91 |
import com.sun.tools.javac.tree.JCTree.JCExports; |
92 |
import com.sun.tools.javac.tree.JCTree.JCExpression; |
|
93 |
import com.sun.tools.javac.tree.JCTree.JCModuleDecl; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
94 |
import com.sun.tools.javac.tree.JCTree.JCOpens; |
36526 | 95 |
import com.sun.tools.javac.tree.JCTree.JCProvides; |
96 |
import com.sun.tools.javac.tree.JCTree.JCRequires; |
|
97 |
import com.sun.tools.javac.tree.JCTree.JCUses; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
98 |
import com.sun.tools.javac.tree.JCTree.Tag; |
36526 | 99 |
import com.sun.tools.javac.tree.TreeInfo; |
100 |
import com.sun.tools.javac.util.Assert; |
|
101 |
import com.sun.tools.javac.util.Context; |
|
102 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
103 |
import com.sun.tools.javac.util.List; |
|
104 |
import com.sun.tools.javac.util.ListBuffer; |
|
105 |
import com.sun.tools.javac.util.Log; |
|
106 |
import com.sun.tools.javac.util.Name; |
|
107 |
import com.sun.tools.javac.util.Names; |
|
108 |
import com.sun.tools.javac.util.Options; |
|
109 |
||
110 |
import static com.sun.tools.javac.code.Flags.ABSTRACT; |
|
37854
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37848
diff
changeset
|
111 |
import static com.sun.tools.javac.code.Flags.ENUM; |
36526 | 112 |
import static com.sun.tools.javac.code.Flags.PUBLIC; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
113 |
import static com.sun.tools.javac.code.Flags.UNATTRIBUTED; |
48427
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
114 |
|
44290
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
115 |
import com.sun.tools.javac.code.Kinds; |
48427
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
116 |
|
42841
1768507dae6b
8171412: tools/javac/modules/AddLimitMods.java failed with "error: module not found"
jjg
parents:
42827
diff
changeset
|
117 |
import static com.sun.tools.javac.code.Kinds.Kind.ERR; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
118 |
import static com.sun.tools.javac.code.Kinds.Kind.MDL; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
119 |
import static com.sun.tools.javac.code.Kinds.Kind.MTH; |
48427
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
120 |
|
43270
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
121 |
import com.sun.tools.javac.code.Symbol.ModuleResolutionFlags; |
48427
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
122 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
123 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
36526 | 124 |
|
125 |
/** |
|
126 |
* TODO: fill in |
|
127 |
* |
|
128 |
* <p><b>This is NOT part of any supported API. |
|
129 |
* If you write code that depends on this, you do so at your own risk. |
|
130 |
* This code and its internal interfaces are subject to change or |
|
131 |
* deletion without notice.</b> |
|
132 |
*/ |
|
133 |
public class Modules extends JCTree.Visitor { |
|
134 |
private static final String ALL_SYSTEM = "ALL-SYSTEM"; |
|
135 |
private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH"; |
|
136 |
||
137 |
private final Log log; |
|
138 |
private final Names names; |
|
139 |
private final Symtab syms; |
|
140 |
private final Attr attr; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
141 |
private final Check chk; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
142 |
private final DeferredLintHandler deferredLintHandler; |
36526 | 143 |
private final TypeEnvs typeEnvs; |
38827
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
38619
diff
changeset
|
144 |
private final Types types; |
36526 | 145 |
private final JavaFileManager fileManager; |
146 |
private final ModuleFinder moduleFinder; |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
147 |
private final Source source; |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
148 |
private final Target target; |
36526 | 149 |
private final boolean allowModules; |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
150 |
private final boolean allowAccessIntoSystem; |
36526 | 151 |
|
152 |
public final boolean multiModuleMode; |
|
153 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
154 |
private final Name java_se; |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
155 |
private final Name java_; |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
156 |
|
36526 | 157 |
ModuleSymbol defaultModule; |
158 |
||
159 |
private final String addExportsOpt; |
|
160 |
private Map<ModuleSymbol, Set<ExportsDirective>> addExports; |
|
161 |
private final String addReadsOpt; |
|
162 |
private Map<ModuleSymbol, Set<RequiresDirective>> addReads; |
|
163 |
private final String addModsOpt; |
|
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
164 |
private final Set<String> extraAddMods = new HashSet<>(); |
36526 | 165 |
private final String limitModsOpt; |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
166 |
private final Set<String> extraLimitMods = new HashSet<>(); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
167 |
private final String moduleVersionOpt; |
36526 | 168 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
169 |
private final boolean lintOptions; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
170 |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
171 |
private Set<ModuleSymbol> rootModules = null; |
43579
0d00f3ea77bc
8172240: javac should not need the transitive closure to compile a module
vromero
parents:
43577
diff
changeset
|
172 |
private final Set<ModuleSymbol> warnedMissing = new HashSet<>(); |
36526 | 173 |
|
44290
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
174 |
public PackageNameFinder findPackageInFile; |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
175 |
|
36526 | 176 |
public static Modules instance(Context context) { |
177 |
Modules instance = context.get(Modules.class); |
|
178 |
if (instance == null) |
|
179 |
instance = new Modules(context); |
|
180 |
return instance; |
|
181 |
} |
|
182 |
||
183 |
protected Modules(Context context) { |
|
184 |
context.put(Modules.class, this); |
|
185 |
log = Log.instance(context); |
|
186 |
names = Names.instance(context); |
|
187 |
syms = Symtab.instance(context); |
|
188 |
attr = Attr.instance(context); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
189 |
chk = Check.instance(context); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
190 |
deferredLintHandler = DeferredLintHandler.instance(context); |
36526 | 191 |
typeEnvs = TypeEnvs.instance(context); |
192 |
moduleFinder = ModuleFinder.instance(context); |
|
38827
884d32899770
8152062: obscure error message for bad 'provides'
vromero
parents:
38619
diff
changeset
|
193 |
types = Types.instance(context); |
36526 | 194 |
fileManager = context.get(JavaFileManager.class); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
195 |
source = Source.instance(context); |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
196 |
target = Target.instance(context); |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47485
diff
changeset
|
197 |
allowModules = Feature.MODULES.allowedInSource(source); |
36526 | 198 |
Options options = Options.instance(context); |
199 |
||
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
200 |
allowAccessIntoSystem = options.isUnset(Option.RELEASE); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
201 |
lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
202 |
|
36526 | 203 |
multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH); |
204 |
ClassWriter classWriter = ClassWriter.instance(context); |
|
205 |
classWriter.multiModuleMode = multiModuleMode; |
|
206 |
JNIWriter jniWriter = JNIWriter.instance(context); |
|
207 |
jniWriter.multiModuleMode = multiModuleMode; |
|
208 |
||
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
209 |
java_se = names.fromString("java.se"); |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
210 |
java_ = names.fromString("java."); |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
211 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39917
diff
changeset
|
212 |
addExportsOpt = options.get(Option.ADD_EXPORTS); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39917
diff
changeset
|
213 |
addReadsOpt = options.get(Option.ADD_READS); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39917
diff
changeset
|
214 |
addModsOpt = options.get(Option.ADD_MODULES); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39917
diff
changeset
|
215 |
limitModsOpt = options.get(Option.LIMIT_MODULES); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
216 |
moduleVersionOpt = options.get(Option.MODULE_VERSION); |
36526 | 217 |
} |
44812 | 218 |
//where |
219 |
private static final String XMODULES_PREFIX = "-Xmodule:"; |
|
36526 | 220 |
|
221 |
int depth = -1; |
|
222 |
||
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
223 |
public void addExtraAddModules(String... extras) { |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
224 |
extraAddMods.addAll(Arrays.asList(extras)); |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
225 |
} |
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
226 |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
227 |
boolean inInitModules; |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
228 |
public void initModules(List<JCCompilationUnit> trees) { |
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
229 |
Assert.check(!inInitModules); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
230 |
try { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
231 |
inInitModules = true; |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
232 |
Assert.checkNull(rootModules); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
233 |
enter(trees, modules -> { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
234 |
Assert.checkNull(rootModules); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
235 |
Assert.checkNull(allModules); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
236 |
this.rootModules = modules; |
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
237 |
setupAllModules(); //initialize the module graph |
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
238 |
Assert.checkNonNull(allModules); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
239 |
inInitModules = false; |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
240 |
}, null); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
241 |
} finally { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
242 |
inInitModules = false; |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
243 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
244 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
245 |
|
36526 | 246 |
public boolean enter(List<JCCompilationUnit> trees, ClassSymbol c) { |
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
247 |
Assert.check(rootModules != null || inInitModules || !allowModules); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
248 |
return enter(trees, modules -> {}, c); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
249 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
250 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
251 |
private boolean enter(List<JCCompilationUnit> trees, Consumer<Set<ModuleSymbol>> init, ClassSymbol c) { |
38619 | 252 |
if (!allowModules) { |
36526 | 253 |
for (JCCompilationUnit tree: trees) { |
254 |
tree.modle = syms.noModule; |
|
255 |
} |
|
256 |
defaultModule = syms.noModule; |
|
257 |
return true; |
|
258 |
} |
|
259 |
||
260 |
int startErrors = log.nerrors; |
|
261 |
||
262 |
depth++; |
|
263 |
try { |
|
264 |
// scan trees for module defs |
|
265 |
Set<ModuleSymbol> roots = enterModules(trees, c); |
|
266 |
||
42824 | 267 |
setCompilationUnitModules(trees, roots, c); |
36526 | 268 |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
269 |
init.accept(roots); |
36526 | 270 |
|
271 |
for (ModuleSymbol msym: roots) { |
|
272 |
msym.complete(); |
|
273 |
} |
|
39361
cd0aca7db174
8159439: javac throws NPE with Module attribute and super_class != 0
vromero
parents:
38827
diff
changeset
|
274 |
} catch (CompletionFailure ex) { |
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
275 |
chk.completionError(null, ex); |
36526 | 276 |
} finally { |
277 |
depth--; |
|
278 |
} |
|
279 |
||
280 |
return (log.nerrors == startErrors); |
|
281 |
} |
|
282 |
||
283 |
public Completer getCompleter() { |
|
284 |
return mainCompleter; |
|
285 |
} |
|
286 |
||
287 |
public ModuleSymbol getDefaultModule() { |
|
288 |
return defaultModule; |
|
289 |
} |
|
290 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
291 |
public boolean modulesInitialized() { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
292 |
return allModules != null; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
293 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
294 |
|
36526 | 295 |
private Set<ModuleSymbol> enterModules(List<JCCompilationUnit> trees, ClassSymbol c) { |
296 |
Set<ModuleSymbol> modules = new LinkedHashSet<>(); |
|
297 |
for (JCCompilationUnit tree : trees) { |
|
298 |
JavaFileObject prev = log.useSource(tree.sourcefile); |
|
299 |
try { |
|
300 |
enterModule(tree, c, modules); |
|
301 |
} finally { |
|
302 |
log.useSource(prev); |
|
303 |
} |
|
304 |
} |
|
305 |
return modules; |
|
306 |
} |
|
307 |
||
308 |
||
309 |
private void enterModule(JCCompilationUnit toplevel, ClassSymbol c, Set<ModuleSymbol> modules) { |
|
310 |
boolean isModuleInfo = toplevel.sourcefile.isNameCompatible("module-info", Kind.SOURCE); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
311 |
boolean isModuleDecl = toplevel.getModuleDecl() != null; |
41999
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
41942
diff
changeset
|
312 |
if (isModuleDecl) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
313 |
JCModuleDecl decl = toplevel.getModuleDecl(); |
41999
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
41942
diff
changeset
|
314 |
if (!isModuleInfo) { |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
41942
diff
changeset
|
315 |
log.error(decl.pos(), Errors.ModuleDeclSbInModuleInfoJava); |
dbf796210eff
8168312: javac throws NPE if annotation processor is specified and module is declared in a file named arbitrarily
sadayapalam
parents:
41942
diff
changeset
|
316 |
} |
36526 | 317 |
Name name = TreeInfo.fullName(decl.qualId); |
318 |
ModuleSymbol sym; |
|
319 |
if (c != null) { |
|
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
320 |
sym = (ModuleSymbol) c.owner; |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
321 |
Assert.checkNonNull(sym.name); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
322 |
Name treeName = TreeInfo.fullName(decl.qualId); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
323 |
if (sym.name != treeName) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
324 |
log.error(decl.pos(), Errors.ModuleNameMismatch(name, sym.name)); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
325 |
} |
36526 | 326 |
} else { |
327 |
sym = syms.enterModule(name); |
|
328 |
if (sym.module_info.sourcefile != null && sym.module_info.sourcefile != toplevel.sourcefile) { |
|
329 |
log.error(decl.pos(), Errors.DuplicateModule(sym)); |
|
330 |
return; |
|
331 |
} |
|
332 |
} |
|
333 |
sym.completer = getSourceCompleter(toplevel); |
|
334 |
sym.module_info.sourcefile = toplevel.sourcefile; |
|
335 |
decl.sym = sym; |
|
336 |
||
337 |
if (multiModuleMode || modules.isEmpty()) { |
|
338 |
modules.add(sym); |
|
339 |
} else { |
|
340 |
log.error(toplevel.pos(), Errors.TooManyModules); |
|
341 |
} |
|
342 |
||
343 |
Env<AttrContext> provisionalEnv = new Env<>(decl, null); |
|
344 |
||
345 |
provisionalEnv.toplevel = toplevel; |
|
346 |
typeEnvs.put(sym, provisionalEnv); |
|
347 |
} else if (isModuleInfo) { |
|
348 |
if (multiModuleMode) { |
|
349 |
JCTree tree = toplevel.defs.isEmpty() ? toplevel : toplevel.defs.head; |
|
350 |
log.error(tree.pos(), Errors.ExpectedModule); |
|
351 |
} |
|
352 |
} |
|
353 |
} |
|
354 |
||
42824 | 355 |
private void setCompilationUnitModules(List<JCCompilationUnit> trees, Set<ModuleSymbol> rootModules, ClassSymbol c) { |
36526 | 356 |
// update the module for each compilation unit |
357 |
if (multiModuleMode) { |
|
358 |
checkNoAllModulePath(); |
|
359 |
for (JCCompilationUnit tree: trees) { |
|
360 |
if (tree.defs.isEmpty()) { |
|
361 |
tree.modle = syms.unnamedModule; |
|
362 |
continue; |
|
363 |
} |
|
364 |
||
365 |
JavaFileObject prev = log.useSource(tree.sourcefile); |
|
366 |
try { |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
367 |
Location msplocn = getModuleLocation(tree); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
368 |
Location plocn = fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) ? |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
369 |
fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
370 |
tree.sourcefile) : |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
371 |
null; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
372 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
373 |
if (plocn != null) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
374 |
Name name = names.fromString(fileManager.inferModuleName(plocn)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
375 |
ModuleSymbol msym = moduleFinder.findModule(name); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
376 |
tree.modle = msym; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
377 |
rootModules.add(msym); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
378 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
379 |
if (msplocn != null) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
380 |
Name mspname = names.fromString(fileManager.inferModuleName(msplocn)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
381 |
if (name != mspname) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
382 |
log.error(tree.pos(), Errors.FilePatchedAndMsp(name, mspname)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
383 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
384 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
385 |
} else if (msplocn != null) { |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
386 |
if (tree.getModuleDecl() != null) { |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
387 |
JavaFileObject canonical = |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
388 |
fileManager.getJavaFileForInput(msplocn, "module-info", Kind.SOURCE); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
389 |
if (canonical == null || !fileManager.isSameFile(canonical, tree.sourcefile)) { |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
390 |
log.error(tree.pos(), Errors.ModuleNotFoundOnModuleSourcePath); |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
391 |
} |
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
392 |
} |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
393 |
Name name = names.fromString(fileManager.inferModuleName(msplocn)); |
36526 | 394 |
ModuleSymbol msym; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
395 |
JCModuleDecl decl = tree.getModuleDecl(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
396 |
if (decl != null) { |
36526 | 397 |
msym = decl.sym; |
398 |
if (msym.name != name) { |
|
399 |
log.error(decl.qualId, Errors.ModuleNameMismatch(msym.name, name)); |
|
400 |
} |
|
401 |
} else { |
|
43267 | 402 |
if (tree.getPackage() == null) { |
403 |
log.error(tree.pos(), Errors.UnnamedPkgNotAllowedNamedModules); |
|
404 |
} |
|
36526 | 405 |
msym = syms.enterModule(name); |
406 |
} |
|
407 |
if (msym.sourceLocation == null) { |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
408 |
msym.sourceLocation = msplocn; |
44289
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
409 |
if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
410 |
msym.patchLocation = fileManager.getLocationForModule( |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
411 |
StandardLocation.PATCH_MODULE_PATH, msym.name.toString()); |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
412 |
} |
36526 | 413 |
if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) { |
44289
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
414 |
Location outputLocn = fileManager.getLocationForModule( |
36526 | 415 |
StandardLocation.CLASS_OUTPUT, msym.name.toString()); |
44289
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
416 |
if (msym.patchLocation == null) { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
417 |
msym.classLocation = outputLocn; |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
418 |
} else { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
419 |
msym.patchOutputLocation = outputLocn; |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
420 |
} |
36526 | 421 |
} |
422 |
} |
|
423 |
tree.modle = msym; |
|
424 |
rootModules.add(msym); |
|
42824 | 425 |
} else if (c != null && c.packge().modle == syms.unnamedModule) { |
426 |
tree.modle = syms.unnamedModule; |
|
36526 | 427 |
} else { |
43267 | 428 |
if (tree.getModuleDecl() != null) { |
429 |
log.error(tree.pos(), Errors.ModuleNotFoundOnModuleSourcePath); |
|
430 |
} else { |
|
431 |
log.error(tree.pos(), Errors.NotInModuleOnModuleSourcePath); |
|
432 |
} |
|
36526 | 433 |
tree.modle = syms.errModule; |
434 |
} |
|
435 |
} catch (IOException e) { |
|
436 |
throw new Error(e); // FIXME |
|
437 |
} finally { |
|
438 |
log.useSource(prev); |
|
439 |
} |
|
440 |
} |
|
441 |
if (syms.unnamedModule.sourceLocation == null) { |
|
442 |
syms.unnamedModule.completer = getUnnamedModuleCompleter(); |
|
443 |
syms.unnamedModule.sourceLocation = StandardLocation.SOURCE_PATH; |
|
444 |
syms.unnamedModule.classLocation = StandardLocation.CLASS_PATH; |
|
445 |
} |
|
446 |
defaultModule = syms.unnamedModule; |
|
447 |
} else { |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
448 |
ModuleSymbol module = null; |
36526 | 449 |
if (defaultModule == null) { |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
450 |
String moduleOverride = singleModuleOverride(trees); |
36526 | 451 |
switch (rootModules.size()) { |
452 |
case 0: |
|
453 |
defaultModule = moduleFinder.findSingleModule(); |
|
454 |
if (defaultModule == syms.unnamedModule) { |
|
455 |
if (moduleOverride != null) { |
|
456 |
checkNoAllModulePath(); |
|
457 |
defaultModule = moduleFinder.findModule(names.fromString(moduleOverride)); |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
458 |
defaultModule.patchOutputLocation = StandardLocation.CLASS_OUTPUT; |
36526 | 459 |
} else { |
460 |
// Question: why not do findAllModules and initVisiblePackages here? |
|
461 |
// i.e. body of unnamedModuleCompleter |
|
462 |
defaultModule.completer = getUnnamedModuleCompleter(); |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
463 |
defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; |
36526 | 464 |
defaultModule.classLocation = StandardLocation.CLASS_PATH; |
465 |
} |
|
466 |
} else { |
|
467 |
checkNoAllModulePath(); |
|
468 |
defaultModule.complete(); |
|
469 |
// Question: why not do completeModule here? |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42824
diff
changeset
|
470 |
defaultModule.completer = sym -> completeModule((ModuleSymbol) sym); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
471 |
defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; |
36526 | 472 |
} |
473 |
rootModules.add(defaultModule); |
|
474 |
break; |
|
475 |
case 1: |
|
476 |
checkNoAllModulePath(); |
|
477 |
defaultModule = rootModules.iterator().next(); |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
478 |
defaultModule.sourceLocation = StandardLocation.SOURCE_PATH; |
44289
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
479 |
if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
480 |
try { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
481 |
defaultModule.patchLocation = fileManager.getLocationForModule( |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
482 |
StandardLocation.PATCH_MODULE_PATH, defaultModule.name.toString()); |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
483 |
} catch (IOException ex) { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
484 |
throw new Error(ex); |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
485 |
} |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
486 |
} |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
487 |
if (defaultModule.patchLocation == null) { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
488 |
defaultModule.classLocation = StandardLocation.CLASS_OUTPUT; |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
489 |
} else { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
490 |
defaultModule.patchOutputLocation = StandardLocation.CLASS_OUTPUT; |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
491 |
} |
36526 | 492 |
break; |
493 |
default: |
|
494 |
Assert.error("too many modules"); |
|
495 |
} |
|
44289
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
496 |
} else if (rootModules.size() == 1) { |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
497 |
module = rootModules.iterator().next(); |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
498 |
module.complete(); |
842ccb558d7d
8175057: module-info on patch path should not produce an error
jlahoda
parents:
44063
diff
changeset
|
499 |
module.completer = sym -> completeModule((ModuleSymbol) sym); |
36526 | 500 |
} else { |
501 |
Assert.check(rootModules.isEmpty()); |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
502 |
String moduleOverride = singleModuleOverride(trees); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
503 |
if (moduleOverride != null) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
504 |
module = moduleFinder.findModule(names.fromString(moduleOverride)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
505 |
} else { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
506 |
module = defaultModule; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
507 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
508 |
rootModules.add(module); |
36526 | 509 |
} |
510 |
||
511 |
if (defaultModule != syms.unnamedModule) { |
|
512 |
syms.unnamedModule.completer = getUnnamedModuleCompleter(); |
|
513 |
syms.unnamedModule.classLocation = StandardLocation.CLASS_PATH; |
|
514 |
} |
|
515 |
||
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
516 |
if (module == null) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
517 |
module = defaultModule; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
518 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
519 |
|
44822 | 520 |
for (JCCompilationUnit tree : trees) { |
521 |
if (defaultModule != syms.unnamedModule |
|
522 |
&& defaultModule.sourceLocation == StandardLocation.SOURCE_PATH |
|
523 |
&& fileManager.hasLocation(StandardLocation.SOURCE_PATH)) { |
|
524 |
checkSourceLocation(tree, module); |
|
525 |
} |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
526 |
tree.modle = module; |
36526 | 527 |
} |
528 |
} |
|
529 |
} |
|
530 |
||
44822 | 531 |
private void checkSourceLocation(JCCompilationUnit tree, ModuleSymbol msym) { |
532 |
try { |
|
533 |
JavaFileObject fo = tree.sourcefile; |
|
534 |
if (fileManager.contains(msym.sourceLocation, fo)) { |
|
535 |
return; |
|
536 |
} |
|
537 |
if (msym.patchLocation != null && fileManager.contains(msym.patchLocation, fo)) { |
|
538 |
return; |
|
539 |
} |
|
540 |
if (fileManager.hasLocation(StandardLocation.SOURCE_OUTPUT)) { |
|
541 |
if (fileManager.contains(StandardLocation.SOURCE_OUTPUT, fo)) { |
|
542 |
return; |
|
543 |
} |
|
544 |
} else { |
|
545 |
if (fileManager.contains(StandardLocation.CLASS_OUTPUT, fo)) { |
|
546 |
return; |
|
547 |
} |
|
548 |
} |
|
549 |
} catch (IOException e) { |
|
550 |
throw new Error(e); |
|
551 |
} |
|
552 |
||
553 |
JavaFileObject prev = log.useSource(tree.sourcefile); |
|
554 |
try { |
|
45504
ea7475564d07
8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents:
45217
diff
changeset
|
555 |
log.error(tree.pos(), Errors.FileSbOnSourceOrPatchPathForModule); |
44822 | 556 |
} finally { |
557 |
log.useSource(prev); |
|
558 |
} |
|
559 |
} |
|
560 |
||
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
561 |
private String singleModuleOverride(List<JCCompilationUnit> trees) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
562 |
if (!fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) { |
45685 | 563 |
return null; |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
564 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
565 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
566 |
Set<String> override = new LinkedHashSet<>(); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
567 |
for (JCCompilationUnit tree : trees) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
568 |
JavaFileObject fo = tree.sourcefile; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
569 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
570 |
try { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
571 |
Location loc = |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
572 |
fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, fo); |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
573 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
574 |
if (loc != null) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
575 |
override.add(fileManager.inferModuleName(loc)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
576 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
577 |
} catch (IOException ex) { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
578 |
throw new Error(ex); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
579 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
580 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
581 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
582 |
switch (override.size()) { |
45685 | 583 |
case 0: return null; |
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
584 |
case 1: return override.iterator().next(); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
585 |
default: |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
586 |
log.error(Errors.TooManyPatchedModules(override)); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
587 |
return null; |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
588 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
589 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
590 |
|
43267 | 591 |
/** |
592 |
* Determine the location for the module on the module source path |
|
593 |
* or source output directory which contains a given CompilationUnit. |
|
594 |
* If the source output directory is unset, the class output directory |
|
595 |
* will be checked instead. |
|
596 |
* {@code null} is returned if no such module can be found. |
|
597 |
* @param tree the compilation unit tree |
|
598 |
* @return the location for the enclosing module |
|
599 |
* @throws IOException if there is a problem while searching for the module. |
|
600 |
*/ |
|
36526 | 601 |
private Location getModuleLocation(JCCompilationUnit tree) throws IOException { |
43267 | 602 |
JavaFileObject fo = tree.sourcefile; |
603 |
||
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
604 |
Location loc = |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
605 |
fileManager.getLocationForModule(StandardLocation.MODULE_SOURCE_PATH, fo); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
606 |
if (loc == null) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
607 |
Location sourceOutput = fileManager.hasLocation(StandardLocation.SOURCE_OUTPUT) ? |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
608 |
StandardLocation.SOURCE_OUTPUT : StandardLocation.CLASS_OUTPUT; |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
609 |
loc = |
44063
5f0cf4126949
8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents:
43865
diff
changeset
|
610 |
fileManager.getLocationForModule(sourceOutput, fo); |
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
611 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
612 |
return loc; |
36526 | 613 |
} |
614 |
||
615 |
private void checkNoAllModulePath() { |
|
616 |
if (addModsOpt != null && Arrays.asList(addModsOpt.split(",")).contains(ALL_MODULE_PATH)) { |
|
617 |
log.error(Errors.AddmodsAllModulePathInvalid); |
|
618 |
} |
|
619 |
} |
|
620 |
||
621 |
private final Completer mainCompleter = new Completer() { |
|
622 |
@Override |
|
623 |
public void complete(Symbol sym) throws CompletionFailure { |
|
624 |
ModuleSymbol msym = moduleFinder.findModule((ModuleSymbol) sym); |
|
625 |
||
42841
1768507dae6b
8171412: tools/javac/modules/AddLimitMods.java failed with "error: module not found"
jjg
parents:
42827
diff
changeset
|
626 |
if (msym.kind == ERR) { |
36526 | 627 |
//make sure the module is initialized: |
628 |
msym.directives = List.nil(); |
|
629 |
msym.exports = List.nil(); |
|
630 |
msym.provides = List.nil(); |
|
631 |
msym.requires = List.nil(); |
|
632 |
msym.uses = List.nil(); |
|
633 |
} else if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) { |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
634 |
setupAutomaticModule(msym); |
36526 | 635 |
} else { |
636 |
msym.module_info.complete(); |
|
637 |
} |
|
638 |
||
639 |
// If module-info comes from a .java file, the underlying |
|
640 |
// call of classFinder.fillIn will have called through the |
|
641 |
// source completer, to Enter, and then to Modules.enter, |
|
642 |
// which will call completeModule. |
|
643 |
// But, if module-info comes from a .class file, the underlying |
|
644 |
// call of classFinder.fillIn will just call ClassReader to read |
|
645 |
// the .class file, and so we call completeModule here. |
|
646 |
if (msym.module_info.classfile == null || msym.module_info.classfile.getKind() == Kind.CLASS) { |
|
647 |
completeModule(msym); |
|
648 |
} |
|
649 |
} |
|
650 |
||
651 |
@Override |
|
652 |
public String toString() { |
|
653 |
return "mainCompleter"; |
|
654 |
} |
|
655 |
}; |
|
656 |
||
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
657 |
private void setupAutomaticModule(ModuleSymbol msym) throws CompletionFailure { |
36526 | 658 |
try { |
659 |
ListBuffer<Directive> directives = new ListBuffer<>(); |
|
660 |
ListBuffer<ExportsDirective> exports = new ListBuffer<>(); |
|
661 |
Set<String> seenPackages = new HashSet<>(); |
|
662 |
||
663 |
for (JavaFileObject clazz : fileManager.list(msym.classLocation, "", EnumSet.of(Kind.CLASS), true)) { |
|
664 |
String binName = fileManager.inferBinaryName(msym.classLocation, clazz); |
|
665 |
String pack = binName.lastIndexOf('.') != (-1) ? binName.substring(0, binName.lastIndexOf('.')) : ""; //unnamed package???? |
|
666 |
if (seenPackages.add(pack)) { |
|
667 |
ExportsDirective d = new ExportsDirective(syms.enterPackage(msym, names.fromString(pack)), null); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
668 |
//TODO: opens? |
36526 | 669 |
directives.add(d); |
670 |
exports.add(d); |
|
671 |
} |
|
672 |
} |
|
673 |
||
674 |
msym.exports = exports.toList(); |
|
675 |
msym.provides = List.nil(); |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
676 |
msym.requires = List.nil(); |
36526 | 677 |
msym.uses = List.nil(); |
678 |
msym.directives = directives.toList(); |
|
679 |
} catch (IOException ex) { |
|
680 |
throw new IllegalStateException(ex); |
|
681 |
} |
|
682 |
} |
|
683 |
||
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
684 |
private void completeAutomaticModule(ModuleSymbol msym) throws CompletionFailure { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
685 |
ListBuffer<Directive> directives = new ListBuffer<>(); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
686 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
687 |
directives.addAll(msym.directives); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
688 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
689 |
ListBuffer<RequiresDirective> requires = new ListBuffer<>(); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
690 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
691 |
for (ModuleSymbol ms : allModules()) { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
692 |
if (ms == syms.unnamedModule || ms == msym) |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
693 |
continue; |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
694 |
Set<RequiresFlag> flags = (ms.flags_field & Flags.AUTOMATIC_MODULE) != 0 ? |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
695 |
EnumSet.of(RequiresFlag.TRANSITIVE) : EnumSet.noneOf(RequiresFlag.class); |
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
696 |
RequiresDirective d = new RequiresDirective(ms, flags); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
697 |
directives.add(d); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
698 |
requires.add(d); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
699 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
700 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
701 |
RequiresDirective requiresUnnamed = new RequiresDirective(syms.unnamedModule); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
702 |
directives.add(requiresUnnamed); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
703 |
requires.add(requiresUnnamed); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
704 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
705 |
msym.requires = requires.toList(); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
706 |
msym.directives = directives.toList(); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
707 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
708 |
|
36526 | 709 |
private Completer getSourceCompleter(JCCompilationUnit tree) { |
710 |
return new Completer() { |
|
711 |
@Override |
|
712 |
public void complete(Symbol sym) throws CompletionFailure { |
|
713 |
ModuleSymbol msym = (ModuleSymbol) sym; |
|
714 |
msym.flags_field |= UNATTRIBUTED; |
|
715 |
ModuleVisitor v = new ModuleVisitor(); |
|
716 |
JavaFileObject prev = log.useSource(tree.sourcefile); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
717 |
JCModuleDecl moduleDecl = tree.getModuleDecl(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
718 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(moduleDecl.pos()); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
719 |
|
36526 | 720 |
try { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
721 |
moduleDecl.accept(v); |
36526 | 722 |
completeModule(msym); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
723 |
checkCyclicDependencies(moduleDecl); |
36526 | 724 |
} finally { |
725 |
log.useSource(prev); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
726 |
deferredLintHandler.setPos(prevLintPos); |
36526 | 727 |
msym.flags_field &= ~UNATTRIBUTED; |
728 |
} |
|
729 |
} |
|
730 |
||
731 |
@Override |
|
732 |
public String toString() { |
|
733 |
return "SourceCompleter: " + tree.sourcefile.getName(); |
|
734 |
} |
|
735 |
||
736 |
}; |
|
737 |
} |
|
738 |
||
42815
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
739 |
public boolean isRootModule(ModuleSymbol module) { |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
740 |
Assert.checkNonNull(rootModules); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
741 |
return rootModules.contains(module); |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
742 |
} |
050370edaade
8072988: Update javax.annotation.processing for modules
jlahoda
parents:
42408
diff
changeset
|
743 |
|
44291
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
44290
diff
changeset
|
744 |
public Set<ModuleSymbol> getRootModules() { |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
44290
diff
changeset
|
745 |
Assert.checkNonNull(rootModules); |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
44290
diff
changeset
|
746 |
return rootModules; |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
44290
diff
changeset
|
747 |
} |
e1b620ac6c98
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents:
44290
diff
changeset
|
748 |
|
36526 | 749 |
class ModuleVisitor extends JCTree.Visitor { |
750 |
private ModuleSymbol sym; |
|
751 |
private final Set<ModuleSymbol> allRequires = new HashSet<>(); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
752 |
private final Map<PackageSymbol,List<ExportsDirective>> allExports = new HashMap<>(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
753 |
private final Map<PackageSymbol,List<OpensDirective>> allOpens = new HashMap<>(); |
36526 | 754 |
|
755 |
@Override |
|
756 |
public void visitModuleDef(JCModuleDecl tree) { |
|
757 |
sym = Assert.checkNonNull(tree.sym); |
|
758 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
759 |
if (tree.getModuleType() == ModuleKind.OPEN) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
760 |
sym.flags.add(ModuleFlags.OPEN); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
761 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
762 |
sym.flags_field |= (tree.mods.flags & Flags.DEPRECATED); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
763 |
|
36526 | 764 |
sym.requires = List.nil(); |
765 |
sym.exports = List.nil(); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
766 |
sym.opens = List.nil(); |
36526 | 767 |
tree.directives.forEach(t -> t.accept(this)); |
768 |
sym.requires = sym.requires.reverse(); |
|
769 |
sym.exports = sym.exports.reverse(); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
770 |
sym.opens = sym.opens.reverse(); |
36526 | 771 |
ensureJavaBase(); |
772 |
} |
|
773 |
||
774 |
@Override |
|
775 |
public void visitRequires(JCRequires tree) { |
|
776 |
ModuleSymbol msym = lookupModule(tree.moduleName); |
|
777 |
if (msym.kind != MDL) { |
|
778 |
log.error(tree.moduleName.pos(), Errors.ModuleNotFound(msym)); |
|
43579
0d00f3ea77bc
8172240: javac should not need the transitive closure to compile a module
vromero
parents:
43577
diff
changeset
|
779 |
warnedMissing.add(msym); |
36526 | 780 |
} else if (allRequires.contains(msym)) { |
781 |
log.error(tree.moduleName.pos(), Errors.DuplicateRequires(msym)); |
|
782 |
} else { |
|
783 |
allRequires.add(msym); |
|
784 |
Set<RequiresFlag> flags = EnumSet.noneOf(RequiresFlag.class); |
|
48427
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
785 |
if (tree.isTransitive) { |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
786 |
if (msym == syms.java_base && source.compareTo(Source.JDK10) >= 0) { |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
787 |
log.error(tree.pos(), Errors.ModifierNotAllowedHere(names.transitive)); |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
788 |
} else { |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
789 |
flags.add(RequiresFlag.TRANSITIVE); |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
790 |
} |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
791 |
} |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
792 |
if (tree.isStaticPhase) { |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
793 |
if (msym == syms.java_base && source.compareTo(Source.JDK10) >= 0) { |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
794 |
log.error(tree.pos(), Errors.ModNotAllowedHere(EnumSet.of(Flag.STATIC))); |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
795 |
} else { |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
796 |
flags.add(RequiresFlag.STATIC_PHASE); |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
797 |
} |
b08405cc467a
8193125: javac should not compile a module if it requires java.base with modifiers
jjg
parents:
48054
diff
changeset
|
798 |
} |
36526 | 799 |
RequiresDirective d = new RequiresDirective(msym, flags); |
800 |
tree.directive = d; |
|
801 |
sym.requires = sym.requires.prepend(d); |
|
802 |
} |
|
803 |
} |
|
804 |
||
805 |
@Override |
|
806 |
public void visitExports(JCExports tree) { |
|
807 |
Name name = TreeInfo.fullName(tree.qualid); |
|
808 |
PackageSymbol packge = syms.enterPackage(sym, name); |
|
809 |
attr.setPackageSymbols(tree.qualid, packge); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
810 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
811 |
List<ExportsDirective> exportsForPackage = allExports.computeIfAbsent(packge, p -> List.nil()); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
812 |
for (ExportsDirective d : exportsForPackage) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
813 |
reportExportsConflict(tree, packge); |
36526 | 814 |
} |
815 |
||
816 |
List<ModuleSymbol> toModules = null; |
|
817 |
if (tree.moduleNames != null) { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
818 |
Set<ModuleSymbol> to = new LinkedHashSet<>(); |
36526 | 819 |
for (JCExpression n: tree.moduleNames) { |
820 |
ModuleSymbol msym = lookupModule(n); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
821 |
chk.checkModuleExists(n.pos(), msym); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
822 |
for (ExportsDirective d : exportsForPackage) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
823 |
checkDuplicateExportsToModule(n, msym, d); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
824 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
825 |
if (!to.add(msym)) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
826 |
reportExportsConflictToModule(n, msym); |
36526 | 827 |
} |
828 |
} |
|
829 |
toModules = List.from(to); |
|
830 |
} |
|
831 |
||
832 |
if (toModules == null || !toModules.isEmpty()) { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
833 |
Set<ExportsFlag> flags = EnumSet.noneOf(ExportsFlag.class); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
834 |
ExportsDirective d = new ExportsDirective(packge, toModules, flags); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
835 |
sym.exports = sym.exports.prepend(d); |
36526 | 836 |
tree.directive = d; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
837 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
838 |
allExports.put(packge, exportsForPackage.prepend(d)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
839 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
840 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
841 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
842 |
private void reportExportsConflict(JCExports tree, PackageSymbol packge) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
843 |
log.error(tree.qualid.pos(), Errors.ConflictingExports(packge)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
844 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
845 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
846 |
private void checkDuplicateExportsToModule(JCExpression name, ModuleSymbol msym, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
847 |
ExportsDirective d) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
848 |
if (d.modules != null) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
849 |
for (ModuleSymbol other : d.modules) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
850 |
if (msym == other) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
851 |
reportExportsConflictToModule(name, msym); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
852 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
853 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
854 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
855 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
856 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
857 |
private void reportExportsConflictToModule(JCExpression name, ModuleSymbol msym) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
858 |
log.error(name.pos(), Errors.ConflictingExportsToModule(msym)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
859 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
860 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
861 |
@Override |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
862 |
public void visitOpens(JCOpens tree) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
863 |
Name name = TreeInfo.fullName(tree.qualid); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
864 |
PackageSymbol packge = syms.enterPackage(sym, name); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
865 |
attr.setPackageSymbols(tree.qualid, packge); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
866 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
867 |
if (sym.flags.contains(ModuleFlags.OPEN)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
868 |
log.error(tree.pos(), Errors.NoOpensUnlessStrong); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
869 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
870 |
List<OpensDirective> opensForPackage = allOpens.computeIfAbsent(packge, p -> List.nil()); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
871 |
for (OpensDirective d : opensForPackage) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
872 |
reportOpensConflict(tree, packge); |
36526 | 873 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
874 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
875 |
List<ModuleSymbol> toModules = null; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
876 |
if (tree.moduleNames != null) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
877 |
Set<ModuleSymbol> to = new LinkedHashSet<>(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
878 |
for (JCExpression n: tree.moduleNames) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
879 |
ModuleSymbol msym = lookupModule(n); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
880 |
chk.checkModuleExists(n.pos(), msym); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
881 |
for (OpensDirective d : opensForPackage) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
882 |
checkDuplicateOpensToModule(n, msym, d); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
883 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
884 |
if (!to.add(msym)) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
885 |
reportOpensConflictToModule(n, msym); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
886 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
887 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
888 |
toModules = List.from(to); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
889 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
890 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
891 |
if (toModules == null || !toModules.isEmpty()) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
892 |
Set<OpensFlag> flags = EnumSet.noneOf(OpensFlag.class); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
893 |
OpensDirective d = new OpensDirective(packge, toModules, flags); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
894 |
sym.opens = sym.opens.prepend(d); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
895 |
tree.directive = d; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
896 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
897 |
allOpens.put(packge, opensForPackage.prepend(d)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
898 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
899 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
900 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
901 |
private void reportOpensConflict(JCOpens tree, PackageSymbol packge) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
902 |
log.error(tree.qualid.pos(), Errors.ConflictingOpens(packge)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
903 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
904 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
905 |
private void checkDuplicateOpensToModule(JCExpression name, ModuleSymbol msym, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
906 |
OpensDirective d) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
907 |
if (d.modules != null) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
908 |
for (ModuleSymbol other : d.modules) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
909 |
if (msym == other) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
910 |
reportOpensConflictToModule(name, msym); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
911 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
912 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
913 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
914 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
915 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
916 |
private void reportOpensConflictToModule(JCExpression name, ModuleSymbol msym) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
917 |
log.error(name.pos(), Errors.ConflictingOpensToModule(msym)); |
36526 | 918 |
} |
919 |
||
920 |
@Override |
|
921 |
public void visitProvides(JCProvides tree) { } |
|
922 |
||
923 |
@Override |
|
924 |
public void visitUses(JCUses tree) { } |
|
925 |
||
926 |
private void ensureJavaBase() { |
|
927 |
if (sym.name == names.java_base) |
|
928 |
return; |
|
929 |
||
930 |
for (RequiresDirective d: sym.requires) { |
|
931 |
if (d.module.name == names.java_base) |
|
932 |
return; |
|
933 |
} |
|
934 |
||
935 |
ModuleSymbol java_base = syms.enterModule(names.java_base); |
|
936 |
Directive.RequiresDirective d = |
|
937 |
new Directive.RequiresDirective(java_base, |
|
938 |
EnumSet.of(Directive.RequiresFlag.MANDATED)); |
|
939 |
sym.requires = sym.requires.prepend(d); |
|
940 |
} |
|
941 |
||
942 |
private ModuleSymbol lookupModule(JCExpression moduleName) { |
|
943 |
Name name = TreeInfo.fullName(moduleName); |
|
944 |
ModuleSymbol msym = moduleFinder.findModule(name); |
|
945 |
TreeInfo.setSymbol(moduleName, msym); |
|
946 |
return msym; |
|
947 |
} |
|
948 |
} |
|
949 |
||
950 |
public Completer getUsesProvidesCompleter() { |
|
951 |
return sym -> { |
|
952 |
ModuleSymbol msym = (ModuleSymbol) sym; |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
953 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
954 |
msym.complete(); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
955 |
|
36526 | 956 |
Env<AttrContext> env = typeEnvs.get(msym); |
957 |
UsesProvidesVisitor v = new UsesProvidesVisitor(msym, env); |
|
958 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
959 |
JCModuleDecl decl = env.toplevel.getModuleDecl(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
960 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(decl.pos()); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
961 |
|
36526 | 962 |
try { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
963 |
decl.accept(v); |
36526 | 964 |
} finally { |
965 |
log.useSource(prev); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
966 |
deferredLintHandler.setPos(prevLintPos); |
36526 | 967 |
} |
968 |
}; |
|
969 |
} |
|
970 |
||
971 |
class UsesProvidesVisitor extends JCTree.Visitor { |
|
972 |
private final ModuleSymbol msym; |
|
973 |
private final Env<AttrContext> env; |
|
974 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
975 |
private final Set<ClassSymbol> allUses = new HashSet<>(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
976 |
private final Map<ClassSymbol, Set<ClassSymbol>> allProvides = new HashMap<>(); |
36526 | 977 |
|
978 |
public UsesProvidesVisitor(ModuleSymbol msym, Env<AttrContext> env) { |
|
979 |
this.msym = msym; |
|
980 |
this.env = env; |
|
981 |
} |
|
982 |
||
983 |
@Override @SuppressWarnings("unchecked") |
|
984 |
public void visitModuleDef(JCModuleDecl tree) { |
|
985 |
msym.directives = List.nil(); |
|
986 |
msym.provides = List.nil(); |
|
987 |
msym.uses = List.nil(); |
|
988 |
tree.directives.forEach(t -> t.accept(this)); |
|
989 |
msym.directives = msym.directives.reverse(); |
|
990 |
msym.provides = msym.provides.reverse(); |
|
991 |
msym.uses = msym.uses.reverse(); |
|
992 |
||
993 |
if (msym.requires.nonEmpty() && msym.requires.head.flags.contains(RequiresFlag.MANDATED)) |
|
994 |
msym.directives = msym.directives.prepend(msym.requires.head); |
|
995 |
||
996 |
msym.directives = msym.directives.appendList(List.from(addReads.getOrDefault(msym, Collections.emptySet()))); |
|
997 |
||
998 |
checkForCorrectness(); |
|
999 |
} |
|
1000 |
||
1001 |
@Override |
|
1002 |
public void visitExports(JCExports tree) { |
|
44290
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1003 |
Iterable<Symbol> packageContent = tree.directive.packge.members().getSymbols(); |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1004 |
List<JavaFileObject> filesToCheck = List.nil(); |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1005 |
boolean packageNotEmpty = false; |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1006 |
for (Symbol sym : packageContent) { |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1007 |
if (sym.kind != Kinds.Kind.TYP) |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1008 |
continue; |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1009 |
ClassSymbol csym = (ClassSymbol) sym; |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1010 |
if (sym.completer.isTerminal() || |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1011 |
csym.classfile.getKind() == Kind.CLASS) { |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1012 |
packageNotEmpty = true; |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1013 |
filesToCheck = List.nil(); |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1014 |
break; |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1015 |
} |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1016 |
if (csym.classfile.getKind() == Kind.SOURCE) { |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1017 |
filesToCheck = filesToCheck.prepend(csym.classfile); |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1018 |
} |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1019 |
} |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1020 |
for (JavaFileObject jfo : filesToCheck) { |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1021 |
if (findPackageInFile.findPackageNameOf(jfo) == tree.directive.packge.fullname) { |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1022 |
packageNotEmpty = true; |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1023 |
break; |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1024 |
} |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1025 |
} |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1026 |
if (!packageNotEmpty) { |
36526 | 1027 |
log.error(tree.qualid.pos(), Errors.PackageEmptyOrNotFound(tree.directive.packge)); |
1028 |
} |
|
1029 |
msym.directives = msym.directives.prepend(tree.directive); |
|
1030 |
} |
|
1031 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1032 |
@Override |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1033 |
public void visitOpens(JCOpens tree) { |
43588
6a0e0ea0e93b
8172901: javac: 'opens' statement cannot specify non observable package
jjg
parents:
43579
diff
changeset
|
1034 |
chk.checkPackageExistsForOpens(tree.qualid, tree.directive.packge); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1035 |
msym.directives = msym.directives.prepend(tree.directive); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1036 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1037 |
|
36526 | 1038 |
MethodSymbol noArgsConstructor(ClassSymbol tsym) { |
1039 |
for (Symbol sym : tsym.members().getSymbolsByName(names.init)) { |
|
1040 |
MethodSymbol mSym = (MethodSymbol)sym; |
|
1041 |
if (mSym.params().isEmpty()) { |
|
1042 |
return mSym; |
|
1043 |
} |
|
1044 |
} |
|
1045 |
return null; |
|
1046 |
} |
|
1047 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1048 |
MethodSymbol factoryMethod(ClassSymbol tsym) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1049 |
for (Symbol sym : tsym.members().getSymbolsByName(names.provider, sym -> sym.kind == MTH)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1050 |
MethodSymbol mSym = (MethodSymbol)sym; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1051 |
if (mSym.isStatic() && (mSym.flags() & Flags.PUBLIC) != 0 && mSym.params().isEmpty()) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1052 |
return mSym; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1053 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1054 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1055 |
return null; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1056 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1057 |
|
36526 | 1058 |
Map<Directive.ProvidesDirective, JCProvides> directiveToTreeMap = new HashMap<>(); |
1059 |
||
1060 |
@Override |
|
1061 |
public void visitProvides(JCProvides tree) { |
|
1062 |
Type st = attr.attribType(tree.serviceName, env, syms.objectType); |
|
1063 |
ClassSymbol service = (ClassSymbol) st.tsym; |
|
43577
1a1b1242f7aa
8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents:
43271
diff
changeset
|
1064 |
if (allProvides.containsKey(service)) { |
1a1b1242f7aa
8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents:
43271
diff
changeset
|
1065 |
log.error(tree.serviceName.pos(), Errors.RepeatedProvidesForService(service)); |
1a1b1242f7aa
8172807: Javac doesn't report errors on duplicate provides with different service implementations
jjg
parents:
43271
diff
changeset
|
1066 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1067 |
ListBuffer<ClassSymbol> impls = new ListBuffer<>(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1068 |
for (JCExpression implName : tree.implNames) { |
43865
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1069 |
Type it; |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1070 |
boolean prevVisitingServiceImplementation = env.info.visitingServiceImplementation; |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1071 |
try { |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1072 |
env.info.visitingServiceImplementation = true; |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1073 |
it = attr.attribType(implName, env, syms.objectType); |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1074 |
} finally { |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1075 |
env.info.visitingServiceImplementation = prevVisitingServiceImplementation; |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1076 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1077 |
ClassSymbol impl = (ClassSymbol) it.tsym; |
43865
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1078 |
if ((impl.flags_field & PUBLIC) == 0) { |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1079 |
log.error(implName.pos(), Errors.NotDefPublic(impl, impl.location())); |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
43772
diff
changeset
|
1080 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1081 |
//find provider factory: |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1082 |
MethodSymbol factory = factoryMethod(impl); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1083 |
if (factory != null) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1084 |
Type returnType = factory.type.getReturnType(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1085 |
if (!types.isSubtype(returnType, st)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1086 |
log.error(implName.pos(), Errors.ServiceImplementationProviderReturnMustBeSubtypeOfServiceInterface); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1087 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1088 |
} else { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1089 |
if (!types.isSubtype(it, st)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1090 |
log.error(implName.pos(), Errors.ServiceImplementationMustBeSubtypeOfServiceInterface); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1091 |
} else if ((impl.flags() & ABSTRACT) != 0) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1092 |
log.error(implName.pos(), Errors.ServiceImplementationIsAbstract(impl)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1093 |
} else if (impl.isInner()) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1094 |
log.error(implName.pos(), Errors.ServiceImplementationIsInner(impl)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1095 |
} else { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1096 |
MethodSymbol constr = noArgsConstructor(impl); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1097 |
if (constr == null) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1098 |
log.error(implName.pos(), Errors.ServiceImplementationDoesntHaveANoArgsConstructor(impl)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1099 |
} else if ((constr.flags() & PUBLIC) == 0) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1100 |
log.error(implName.pos(), Errors.ServiceImplementationNoArgsConstructorNotPublic(impl)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1101 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1102 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1103 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1104 |
if (it.hasTag(CLASS)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1105 |
if (allProvides.computeIfAbsent(service, s -> new HashSet<>()).add(impl)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1106 |
impls.append(impl); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1107 |
} else { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1108 |
log.error(implName.pos(), Errors.DuplicateProvides(service, impl)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1109 |
} |
36526 | 1110 |
} |
1111 |
} |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1112 |
if (st.hasTag(CLASS) && !impls.isEmpty()) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1113 |
Directive.ProvidesDirective d = new Directive.ProvidesDirective(service, impls.toList()); |
36526 | 1114 |
msym.provides = msym.provides.prepend(d); |
1115 |
msym.directives = msym.directives.prepend(d); |
|
1116 |
directiveToTreeMap.put(d, tree); |
|
1117 |
} |
|
1118 |
} |
|
1119 |
||
1120 |
@Override |
|
1121 |
public void visitRequires(JCRequires tree) { |
|
43271
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43270
diff
changeset
|
1122 |
if (tree.directive != null && allModules().contains(tree.directive.module)) { |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1123 |
chk.checkDeprecated(tree.moduleName.pos(), msym, tree.directive.module); |
44576 | 1124 |
chk.checkModuleRequires(tree.moduleName.pos(), tree.directive); |
39915
5d1e0740e709
8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents:
39366
diff
changeset
|
1125 |
msym.directives = msym.directives.prepend(tree.directive); |
5d1e0740e709
8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents:
39366
diff
changeset
|
1126 |
} |
36526 | 1127 |
} |
1128 |
||
1129 |
@Override |
|
1130 |
public void visitUses(JCUses tree) { |
|
1131 |
Type st = attr.attribType(tree.qualid, env, syms.objectType); |
|
37854
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37848
diff
changeset
|
1132 |
Symbol sym = TreeInfo.symbol(tree.qualid); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37848
diff
changeset
|
1133 |
if ((sym.flags() & ENUM) != 0) { |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37848
diff
changeset
|
1134 |
log.error(tree.qualid.pos(), Errors.ServiceDefinitionIsEnum(st.tsym)); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37848
diff
changeset
|
1135 |
} else if (st.hasTag(CLASS)) { |
36526 | 1136 |
ClassSymbol service = (ClassSymbol) st.tsym; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1137 |
if (allUses.add(service)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1138 |
Directive.UsesDirective d = new Directive.UsesDirective(service); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1139 |
msym.uses = msym.uses.prepend(d); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1140 |
msym.directives = msym.directives.prepend(d); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1141 |
} else { |
36526 | 1142 |
log.error(tree.pos(), Errors.DuplicateUses(service)); |
1143 |
} |
|
1144 |
} |
|
1145 |
} |
|
1146 |
||
1147 |
private void checkForCorrectness() { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1148 |
for (Directive.ProvidesDirective provides : msym.provides) { |
36526 | 1149 |
JCProvides tree = directiveToTreeMap.get(provides); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1150 |
for (ClassSymbol impl : provides.impls) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1151 |
/* The implementation must be defined in the same module as the provides directive |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1152 |
* (else, error) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1153 |
*/ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1154 |
PackageSymbol implementationDefiningPackage = impl.packge(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1155 |
if (implementationDefiningPackage.modle != msym) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1156 |
// TODO: should use tree for the implentation name, not the entire provides tree |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1157 |
// TODO: should improve error message to identify the implementation type |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1158 |
log.error(tree.pos(), Errors.ServiceImplementationNotInRightModule(implementationDefiningPackage.modle)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1159 |
} |
36526 | 1160 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1161 |
/* There is no inherent requirement that module that provides a service should actually |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1162 |
* use it itself. However, it is a pointless declaration if the service package is not |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1163 |
* exported and there is no uses for the service. |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1164 |
*/ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1165 |
PackageSymbol interfaceDeclaringPackage = provides.service.packge(); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1166 |
boolean isInterfaceDeclaredInCurrentModule = interfaceDeclaringPackage.modle == msym; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1167 |
boolean isInterfaceExportedFromAReadableModule = |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1168 |
msym.visiblePackages.get(interfaceDeclaringPackage.fullname) == interfaceDeclaringPackage; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1169 |
if (isInterfaceDeclaredInCurrentModule && !isInterfaceExportedFromAReadableModule) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1170 |
// ok the interface is declared in this module. Let's check if it's exported |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1171 |
boolean warn = true; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1172 |
for (ExportsDirective export : msym.exports) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1173 |
if (interfaceDeclaringPackage == export.packge) { |
36526 | 1174 |
warn = false; |
1175 |
break; |
|
1176 |
} |
|
1177 |
} |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1178 |
if (warn) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1179 |
for (UsesDirective uses : msym.uses) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1180 |
if (provides.service == uses.service) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1181 |
warn = false; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1182 |
break; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1183 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1184 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1185 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1186 |
if (warn) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1187 |
log.warning(tree.pos(), Warnings.ServiceProvidedButNotExportedOrUsed(provides.service)); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1188 |
} |
36526 | 1189 |
} |
1190 |
} |
|
1191 |
} |
|
1192 |
} |
|
1193 |
} |
|
1194 |
||
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1195 |
private Set<ModuleSymbol> allModules; |
36526 | 1196 |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1197 |
public Set<ModuleSymbol> allModules() { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1198 |
Assert.checkNonNull(allModules); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1199 |
return allModules; |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1200 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1201 |
|
40311
bb76098875c8
8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents:
40308
diff
changeset
|
1202 |
private void setupAllModules() { |
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1203 |
Assert.checkNonNull(rootModules); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1204 |
Assert.checkNull(allModules); |
36526 | 1205 |
|
1206 |
Set<ModuleSymbol> observable; |
|
1207 |
||
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1208 |
if (limitModsOpt == null && extraLimitMods.isEmpty()) { |
36526 | 1209 |
observable = null; |
1210 |
} else { |
|
1211 |
Set<ModuleSymbol> limitMods = new HashSet<>(); |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1212 |
if (limitModsOpt != null) { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1213 |
for (String limit : limitModsOpt.split(",")) { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1214 |
if (!isValidName(limit)) |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1215 |
continue; |
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1216 |
limitMods.add(syms.enterModule(names.fromString(limit))); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1217 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1218 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1219 |
for (String limit : extraLimitMods) { |
36526 | 1220 |
limitMods.add(syms.enterModule(names.fromString(limit))); |
1221 |
} |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1222 |
observable = computeTransitiveClosure(limitMods, rootModules, null); |
36526 | 1223 |
observable.addAll(rootModules); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1224 |
if (lintOptions) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1225 |
for (ModuleSymbol msym : limitMods) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1226 |
if (!observable.contains(msym)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1227 |
log.warning(LintCategory.OPTIONS, |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1228 |
Warnings.ModuleForOptionNotFound(Option.LIMIT_MODULES, msym)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1229 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1230 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1231 |
} |
36526 | 1232 |
} |
1233 |
||
42841
1768507dae6b
8171412: tools/javac/modules/AddLimitMods.java failed with "error: module not found"
jjg
parents:
42827
diff
changeset
|
1234 |
Predicate<ModuleSymbol> observablePred = sym -> |
1768507dae6b
8171412: tools/javac/modules/AddLimitMods.java failed with "error: module not found"
jjg
parents:
42827
diff
changeset
|
1235 |
(observable == null) ? (moduleFinder.findModule(sym).kind != ERR) : observable.contains(sym); |
36526 | 1236 |
Predicate<ModuleSymbol> systemModulePred = sym -> (sym.flags() & Flags.SYSTEM_MODULE) != 0; |
1237 |
Set<ModuleSymbol> enabledRoot = new LinkedHashSet<>(); |
|
1238 |
||
1239 |
if (rootModules.contains(syms.unnamedModule)) { |
|
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1240 |
Predicate<ModuleSymbol> jdkModulePred; |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1241 |
if (target.allApiModulesAreRoots()) { |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1242 |
jdkModulePred = sym -> { |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1243 |
sym.complete(); |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1244 |
return sym.exports.stream().anyMatch(e -> e.modules == null); |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1245 |
}; |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1246 |
} else { |
50738
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1247 |
ModuleSymbol javaSE = syms.getModule(java_se); |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1248 |
if (javaSE != null && (observable == null || observable.contains(javaSE))) { |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1249 |
jdkModulePred = sym -> { |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1250 |
sym.complete(); |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1251 |
return !sym.name.startsWith(java_) |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1252 |
&& sym.exports.stream().anyMatch(e -> e.modules == null); |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1253 |
}; |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1254 |
enabledRoot.add(javaSE); |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1255 |
} else { |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1256 |
jdkModulePred = sym -> true; |
6cc2dc161c64
8197532: Re-examine policy for the default set of modules when compiling or running code on the class path
alanb
parents:
50285
diff
changeset
|
1257 |
} |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1258 |
} |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1259 |
|
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1260 |
Predicate<ModuleSymbol> noIncubatorPred = sym -> { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1261 |
sym.complete(); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1262 |
return !sym.resolutionFlags.contains(ModuleResolutionFlags.DO_NOT_RESOLVE_BY_DEFAULT); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1263 |
}; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1264 |
|
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
1265 |
for (ModuleSymbol sym : new HashSet<>(syms.getAllModules())) { |
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1266 |
try { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1267 |
if (systemModulePred.test(sym) && observablePred.test(sym) && jdkModulePred.test(sym) && noIncubatorPred.test(sym)) { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1268 |
enabledRoot.add(sym); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1269 |
} |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1270 |
} catch (CompletionFailure ex) { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1271 |
chk.completionError(null, ex); |
36526 | 1272 |
} |
1273 |
} |
|
1274 |
} |
|
1275 |
||
1276 |
enabledRoot.addAll(rootModules); |
|
1277 |
||
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1278 |
if (addModsOpt != null || !extraAddMods.isEmpty()) { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1279 |
Set<String> fullAddMods = new HashSet<>(); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1280 |
fullAddMods.addAll(extraAddMods); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1281 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1282 |
if (addModsOpt != null) { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1283 |
fullAddMods.addAll(Arrays.asList(addModsOpt.split(","))); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1284 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1285 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1286 |
for (String added : fullAddMods) { |
36526 | 1287 |
Stream<ModuleSymbol> modules; |
1288 |
switch (added) { |
|
1289 |
case ALL_SYSTEM: |
|
43270
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1290 |
modules = new HashSet<>(syms.getAllModules()) |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1291 |
.stream() |
44573
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1292 |
.filter(systemModulePred.and(observablePred)); |
36526 | 1293 |
break; |
1294 |
case ALL_MODULE_PATH: |
|
43270
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1295 |
modules = new HashSet<>(syms.getAllModules()) |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1296 |
.stream() |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1297 |
.filter(systemModulePred.negate().and(observablePred)); |
36526 | 1298 |
break; |
1299 |
default: |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1300 |
if (!isValidName(added)) |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1301 |
continue; |
36526 | 1302 |
modules = Stream.of(syms.enterModule(names.fromString(added))); |
1303 |
break; |
|
1304 |
} |
|
1305 |
modules.forEach(sym -> { |
|
1306 |
enabledRoot.add(sym); |
|
1307 |
if (observable != null) |
|
1308 |
observable.add(sym); |
|
1309 |
}); |
|
1310 |
} |
|
1311 |
} |
|
1312 |
||
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1313 |
Set<ModuleSymbol> result = computeTransitiveClosure(enabledRoot, rootModules, observable); |
36526 | 1314 |
|
1315 |
result.add(syms.unnamedModule); |
|
1316 |
||
44573
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1317 |
boolean hasAutomatic = result.stream().anyMatch(IS_AUTOMATIC); |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1318 |
|
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1319 |
if (hasAutomatic) { |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1320 |
syms.getAllModules() |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1321 |
.stream() |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1322 |
.filter(IS_AUTOMATIC) |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1323 |
.forEach(result::add); |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1324 |
} |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1325 |
|
43270
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1326 |
String incubatingModules = result.stream() |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1327 |
.filter(msym -> msym.resolutionFlags.contains(ModuleResolutionFlags.WARN_INCUBATING)) |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1328 |
.map(msym -> msym.name.toString()) |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1329 |
.collect(Collectors.joining(",")); |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1330 |
|
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1331 |
if (!incubatingModules.isEmpty()) { |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1332 |
log.warning(Warnings.IncubatingModules(incubatingModules)); |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1333 |
} |
de9a02e20567
8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents:
43267
diff
changeset
|
1334 |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1335 |
allModules = result; |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
1336 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
1337 |
//add module versions from options, if any: |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
1338 |
if (moduleVersionOpt != null) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
1339 |
Name version = names.fromString(moduleVersionOpt); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
1340 |
rootModules.forEach(m -> m.version = version); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42408
diff
changeset
|
1341 |
} |
36526 | 1342 |
} |
44573
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1343 |
//where: |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1344 |
private static final Predicate<ModuleSymbol> IS_AUTOMATIC = |
245bb4e6f983
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44291
diff
changeset
|
1345 |
m -> (m.flags_field & Flags.AUTOMATIC_MODULE) != 0; |
36526 | 1346 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1347 |
public boolean isInModuleGraph(ModuleSymbol msym) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1348 |
return allModules == null || allModules.contains(msym); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1349 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1350 |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1351 |
private Set<ModuleSymbol> computeTransitiveClosure(Set<? extends ModuleSymbol> base, |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1352 |
Set<? extends ModuleSymbol> rootModules, |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1353 |
Set<ModuleSymbol> observable) { |
43579
0d00f3ea77bc
8172240: javac should not need the transitive closure to compile a module
vromero
parents:
43577
diff
changeset
|
1354 |
List<ModuleSymbol> primaryTodo = List.nil(); |
0d00f3ea77bc
8172240: javac should not need the transitive closure to compile a module
vromero
parents:
43577
diff
changeset
|
1355 |
List<ModuleSymbol> secondaryTodo = List.nil(); |
36526 | 1356 |
|
1357 |
for (ModuleSymbol ms : base) { |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1358 |
if (rootModules.contains(ms)) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1359 |
primaryTodo = primaryTodo.prepend(ms); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1360 |
} else { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1361 |
secondaryTodo = secondaryTodo.prepend(ms); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1362 |
} |
36526 | 1363 |
} |
1364 |
||
1365 |
Set<ModuleSymbol> result = new LinkedHashSet<>(); |
|
1366 |
result.add(syms.java_base); |
|
1367 |
||
43579
0d00f3ea77bc
8172240: javac should not need the transitive closure to compile a module
vromero
parents:
43577
diff
changeset
|
1368 |
while (primaryTodo.nonEmpty() || secondaryTodo.nonEmpty()) { |
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1369 |
try { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1370 |
ModuleSymbol current; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1371 |
boolean isPrimaryTodo; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1372 |
if (primaryTodo.nonEmpty()) { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1373 |
current = primaryTodo.head; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1374 |
primaryTodo = primaryTodo.tail; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1375 |
isPrimaryTodo = true; |
43579
0d00f3ea77bc
8172240: javac should not need the transitive closure to compile a module
vromero
parents:
43577
diff
changeset
|
1376 |
} else { |
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1377 |
current = secondaryTodo.head; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1378 |
secondaryTodo = secondaryTodo.tail; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1379 |
isPrimaryTodo = false; |
43579
0d00f3ea77bc
8172240: javac should not need the transitive closure to compile a module
vromero
parents:
43577
diff
changeset
|
1380 |
} |
45910
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1381 |
if (observable != null && !observable.contains(current)) |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1382 |
continue; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1383 |
if (!result.add(current) || current == syms.unnamedModule || ((current.flags_field & Flags.AUTOMATIC_MODULE) != 0)) |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1384 |
continue; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1385 |
current.complete(); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1386 |
if (current.kind == ERR && (isPrimaryTodo || base.contains(current)) && warnedMissing.add(current)) { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1387 |
log.error(Errors.ModuleNotFound(current)); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1388 |
} |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1389 |
for (RequiresDirective rd : current.requires) { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1390 |
if (rd.module == syms.java_base) continue; |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1391 |
if ((rd.isTransitive() && isPrimaryTodo) || rootModules.contains(current)) { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1392 |
primaryTodo = primaryTodo.prepend(rd.module); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1393 |
} else { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1394 |
secondaryTodo = secondaryTodo.prepend(rd.module); |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1395 |
} |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1396 |
} |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1397 |
} catch (CompletionFailure ex) { |
c7092e4591b2
8182450: javac aborts when generating ct.sym intermittently
jlahoda
parents:
45744
diff
changeset
|
1398 |
chk.completionError(null, ex); |
36526 | 1399 |
} |
1400 |
} |
|
1401 |
||
1402 |
return result; |
|
1403 |
} |
|
1404 |
||
1405 |
public ModuleSymbol getObservableModule(Name name) { |
|
1406 |
ModuleSymbol mod = syms.getModule(name); |
|
1407 |
||
1408 |
if (allModules().contains(mod)) { |
|
1409 |
return mod; |
|
1410 |
} |
|
1411 |
||
1412 |
return null; |
|
1413 |
} |
|
1414 |
||
1415 |
private Completer getUnnamedModuleCompleter() { |
|
1416 |
moduleFinder.findAllModules(); |
|
1417 |
return new Symbol.Completer() { |
|
1418 |
@Override |
|
1419 |
public void complete(Symbol sym) throws CompletionFailure { |
|
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
1420 |
if (inInitModules) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
1421 |
sym.completer = this; |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
1422 |
return ; |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40768
diff
changeset
|
1423 |
} |
36526 | 1424 |
ModuleSymbol msym = (ModuleSymbol) sym; |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1425 |
Set<ModuleSymbol> allModules = new HashSet<>(allModules()); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1426 |
allModules.remove(syms.unnamedModule); |
36526 | 1427 |
for (ModuleSymbol m : allModules) { |
1428 |
m.complete(); |
|
1429 |
} |
|
1430 |
initVisiblePackages(msym, allModules); |
|
1431 |
} |
|
1432 |
||
1433 |
@Override |
|
1434 |
public String toString() { |
|
1435 |
return "unnamedModule Completer"; |
|
1436 |
} |
|
1437 |
}; |
|
1438 |
} |
|
1439 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1440 |
private final Map<ModuleSymbol, Set<ModuleSymbol>> requiresTransitiveCache = new HashMap<>(); |
36526 | 1441 |
|
1442 |
private void completeModule(ModuleSymbol msym) { |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1443 |
if (inInitModules) { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1444 |
msym.completer = sym -> completeModule(msym); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1445 |
return ; |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1446 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1447 |
|
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1448 |
if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) { |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1449 |
completeAutomaticModule(msym); |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1450 |
} |
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1451 |
|
36526 | 1452 |
Assert.checkNonNull(msym.requires); |
1453 |
||
1454 |
initAddReads(); |
|
1455 |
||
1456 |
msym.requires = msym.requires.appendList(List.from(addReads.getOrDefault(msym, Collections.emptySet()))); |
|
1457 |
||
1458 |
List<RequiresDirective> requires = msym.requires; |
|
1459 |
||
1460 |
while (requires.nonEmpty()) { |
|
1461 |
if (!allModules().contains(requires.head.module)) { |
|
1462 |
Env<AttrContext> env = typeEnvs.get(msym); |
|
1463 |
if (env != null) { |
|
1464 |
JavaFileObject origSource = log.useSource(env.toplevel.sourcefile); |
|
1465 |
try { |
|
1466 |
log.error(/*XXX*/env.tree, Errors.ModuleNotFound(requires.head.module)); |
|
1467 |
} finally { |
|
1468 |
log.useSource(origSource); |
|
1469 |
} |
|
1470 |
} else { |
|
1471 |
Assert.check((msym.flags() & Flags.AUTOMATIC_MODULE) == 0); |
|
1472 |
} |
|
43271
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43270
diff
changeset
|
1473 |
msym.requires = List.filter(msym.requires, requires.head); |
36526 | 1474 |
} |
1475 |
requires = requires.tail; |
|
1476 |
} |
|
1477 |
||
1478 |
Set<ModuleSymbol> readable = new LinkedHashSet<>(); |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1479 |
Set<ModuleSymbol> requiresTransitive = new HashSet<>(); |
39366
8bf5fe72ca88
8155026: javac grants implied readability to explicit modules
jlahoda
parents:
39361
diff
changeset
|
1480 |
|
8bf5fe72ca88
8155026: javac grants implied readability to explicit modules
jlahoda
parents:
39361
diff
changeset
|
1481 |
for (RequiresDirective d : msym.requires) { |
8bf5fe72ca88
8155026: javac grants implied readability to explicit modules
jlahoda
parents:
39361
diff
changeset
|
1482 |
d.module.complete(); |
8bf5fe72ca88
8155026: javac grants implied readability to explicit modules
jlahoda
parents:
39361
diff
changeset
|
1483 |
readable.add(d.module); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1484 |
Set<ModuleSymbol> s = retrieveRequiresTransitive(d.module); |
39366
8bf5fe72ca88
8155026: javac grants implied readability to explicit modules
jlahoda
parents:
39361
diff
changeset
|
1485 |
Assert.checkNonNull(s, () -> "no entry in cache for " + d.module); |
8bf5fe72ca88
8155026: javac grants implied readability to explicit modules
jlahoda
parents:
39361
diff
changeset
|
1486 |
readable.addAll(s); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1487 |
if (d.flags.contains(RequiresFlag.TRANSITIVE)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1488 |
requiresTransitive.add(d.module); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1489 |
requiresTransitive.addAll(s); |
36526 | 1490 |
} |
39366
8bf5fe72ca88
8155026: javac grants implied readability to explicit modules
jlahoda
parents:
39361
diff
changeset
|
1491 |
} |
36526 | 1492 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1493 |
requiresTransitiveCache.put(msym, requiresTransitive); |
36526 | 1494 |
initVisiblePackages(msym, readable); |
1495 |
for (ExportsDirective d: msym.exports) { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1496 |
if (d.packge != null) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1497 |
d.packge.modle = msym; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1498 |
} |
36526 | 1499 |
} |
1500 |
} |
|
1501 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1502 |
private Set<ModuleSymbol> retrieveRequiresTransitive(ModuleSymbol msym) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1503 |
Set<ModuleSymbol> requiresTransitive = requiresTransitiveCache.get(msym); |
36526 | 1504 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1505 |
if (requiresTransitive == null) { |
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40604
diff
changeset
|
1506 |
//the module graph may contain cycles involving automatic modules or --add-reads edges |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1507 |
requiresTransitive = new HashSet<>(); |
36526 | 1508 |
|
1509 |
Set<ModuleSymbol> seen = new HashSet<>(); |
|
1510 |
List<ModuleSymbol> todo = List.of(msym); |
|
1511 |
||
1512 |
while (todo.nonEmpty()) { |
|
1513 |
ModuleSymbol current = todo.head; |
|
1514 |
todo = todo.tail; |
|
1515 |
if (!seen.add(current)) |
|
1516 |
continue; |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1517 |
requiresTransitive.add(current); |
36526 | 1518 |
current.complete(); |
1519 |
Iterable<? extends RequiresDirective> requires; |
|
1520 |
if (current != syms.unnamedModule) { |
|
1521 |
Assert.checkNonNull(current.requires, () -> current + ".requires == null; " + msym); |
|
1522 |
requires = current.requires; |
|
1523 |
for (RequiresDirective rd : requires) { |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1524 |
if (rd.isTransitive()) |
36526 | 1525 |
todo = todo.prepend(rd.module); |
1526 |
} |
|
1527 |
} else { |
|
1528 |
for (ModuleSymbol mod : allModules()) { |
|
1529 |
todo = todo.prepend(mod); |
|
1530 |
} |
|
1531 |
} |
|
1532 |
} |
|
1533 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1534 |
requiresTransitive.remove(msym); |
36526 | 1535 |
} |
1536 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41999
diff
changeset
|
1537 |
return requiresTransitive; |
36526 | 1538 |
} |
1539 |
||
1540 |
private void initVisiblePackages(ModuleSymbol msym, Collection<ModuleSymbol> readable) { |
|
1541 |
initAddExports(); |
|
1542 |
||
1543 |
msym.visiblePackages = new LinkedHashMap<>(); |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42841
diff
changeset
|
1544 |
msym.readModules = new HashSet<>(readable); |
36526 | 1545 |
|
1546 |
Map<Name, ModuleSymbol> seen = new HashMap<>(); |
|
1547 |
||
1548 |
for (ModuleSymbol rm : readable) { |
|
1549 |
if (rm == syms.unnamedModule) |
|
1550 |
continue; |
|
1551 |
addVisiblePackages(msym, seen, rm, rm.exports); |
|
1552 |
} |
|
1553 |
||
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1554 |
addExports.forEach((exportsFrom, exports) -> { |
51123
d7c4c42ab260
8207032: Compilation succeeds without checking readability when --add-exports used
jlahoda
parents:
50738
diff
changeset
|
1555 |
if (msym.readModules.contains(exportsFrom)) { |
d7c4c42ab260
8207032: Compilation succeeds without checking readability when --add-exports used
jlahoda
parents:
50738
diff
changeset
|
1556 |
addVisiblePackages(msym, seen, exportsFrom, exports); |
d7c4c42ab260
8207032: Compilation succeeds without checking readability when --add-exports used
jlahoda
parents:
50738
diff
changeset
|
1557 |
} |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1558 |
}); |
36526 | 1559 |
} |
1560 |
||
1561 |
private void addVisiblePackages(ModuleSymbol msym, |
|
1562 |
Map<Name, ModuleSymbol> seenPackages, |
|
1563 |
ModuleSymbol exportsFrom, |
|
1564 |
Collection<ExportsDirective> exports) { |
|
1565 |
for (ExportsDirective d : exports) { |
|
1566 |
if (d.modules == null || d.modules.contains(msym)) { |
|
1567 |
Name packageName = d.packge.fullname; |
|
1568 |
ModuleSymbol previousModule = seenPackages.get(packageName); |
|
1569 |
||
1570 |
if (previousModule != null && previousModule != exportsFrom) { |
|
1571 |
Env<AttrContext> env = typeEnvs.get(msym); |
|
1572 |
JavaFileObject origSource = env != null ? log.useSource(env.toplevel.sourcefile) |
|
1573 |
: null; |
|
1574 |
DiagnosticPosition pos = env != null ? env.tree.pos() : null; |
|
1575 |
try { |
|
45682
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45156
diff
changeset
|
1576 |
if (msym.isUnnamed()) { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45156
diff
changeset
|
1577 |
log.error(pos, Errors.PackageClashFromRequiresInUnnamed(packageName, |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45156
diff
changeset
|
1578 |
previousModule, exportsFrom)); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45156
diff
changeset
|
1579 |
} else { |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45156
diff
changeset
|
1580 |
log.error(pos, Errors.PackageClashFromRequires(msym, packageName, |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45156
diff
changeset
|
1581 |
previousModule, exportsFrom)); |
fc3b228b9e2a
8181087: Module system implementation refresh (6/2017)
alanb
parents:
45156
diff
changeset
|
1582 |
} |
36526 | 1583 |
} finally { |
1584 |
if (env != null) |
|
1585 |
log.useSource(origSource); |
|
1586 |
} |
|
1587 |
continue; |
|
1588 |
} |
|
1589 |
||
1590 |
seenPackages.put(packageName, exportsFrom); |
|
1591 |
msym.visiblePackages.put(d.packge.fullname, d.packge); |
|
1592 |
} |
|
1593 |
} |
|
1594 |
} |
|
1595 |
||
1596 |
private void initAddExports() { |
|
1597 |
if (addExports != null) |
|
1598 |
return; |
|
1599 |
||
1600 |
addExports = new LinkedHashMap<>(); |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1601 |
Set<ModuleSymbol> unknownModules = new HashSet<>(); |
36526 | 1602 |
|
1603 |
if (addExportsOpt == null) |
|
1604 |
return; |
|
1605 |
||
1606 |
Pattern ep = Pattern.compile("([^/]+)/([^=]+)=(.*)"); |
|
1607 |
for (String s: addExportsOpt.split("\0+")) { |
|
1608 |
if (s.isEmpty()) |
|
1609 |
continue; |
|
1610 |
Matcher em = ep.matcher(s); |
|
1611 |
if (!em.matches()) { |
|
1612 |
continue; |
|
1613 |
} |
|
1614 |
||
1615 |
// Terminology comes from |
|
40762
f8883aa0053c
8160851: Remove old launcher module-related options
mchung
parents:
40604
diff
changeset
|
1616 |
// --add-exports module/package=target,... |
36526 | 1617 |
// Compare to |
1618 |
// module module { exports package to target, ... } |
|
1619 |
String moduleName = em.group(1); |
|
1620 |
String packageName = em.group(2); |
|
1621 |
String targetNames = em.group(3); |
|
1622 |
||
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1623 |
if (!isValidName(moduleName)) |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1624 |
continue; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1625 |
|
36526 | 1626 |
ModuleSymbol msym = syms.enterModule(names.fromString(moduleName)); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1627 |
if (!isKnownModule(msym, unknownModules)) |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1628 |
continue; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1629 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1630 |
if (!isValidName(packageName)) |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1631 |
continue; |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1632 |
|
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1633 |
if (!allowAccessIntoSystem && (msym.flags() & Flags.SYSTEM_MODULE) != 0) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1634 |
log.error(Errors.AddExportsWithRelease(msym)); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1635 |
continue; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1636 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1637 |
|
36526 | 1638 |
PackageSymbol p = syms.enterPackage(msym, names.fromString(packageName)); |
1639 |
p.modle = msym; // TODO: do we need this? |
|
1640 |
||
1641 |
List<ModuleSymbol> targetModules = List.nil(); |
|
1642 |
for (String toModule : targetNames.split("[ ,]+")) { |
|
1643 |
ModuleSymbol m; |
|
1644 |
if (toModule.equals("ALL-UNNAMED")) { |
|
1645 |
m = syms.unnamedModule; |
|
1646 |
} else { |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1647 |
if (!isValidName(toModule)) |
36526 | 1648 |
continue; |
1649 |
m = syms.enterModule(names.fromString(toModule)); |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1650 |
if (!isKnownModule(m, unknownModules)) |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1651 |
continue; |
36526 | 1652 |
} |
1653 |
targetModules = targetModules.prepend(m); |
|
1654 |
} |
|
1655 |
||
1656 |
Set<ExportsDirective> extra = addExports.computeIfAbsent(msym, _x -> new LinkedHashSet<>()); |
|
1657 |
ExportsDirective d = new ExportsDirective(p, targetModules); |
|
1658 |
extra.add(d); |
|
1659 |
} |
|
1660 |
} |
|
1661 |
||
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1662 |
private boolean isKnownModule(ModuleSymbol msym, Set<ModuleSymbol> unknownModules) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1663 |
if (allModules.contains(msym)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1664 |
return true; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1665 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1666 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1667 |
if (!unknownModules.contains(msym)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1668 |
if (lintOptions) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1669 |
log.warning(LintCategory.OPTIONS, |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1670 |
Warnings.ModuleForOptionNotFound(Option.ADD_EXPORTS, msym)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1671 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1672 |
unknownModules.add(msym); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1673 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1674 |
return false; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1675 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1676 |
|
36526 | 1677 |
private void initAddReads() { |
1678 |
if (addReads != null) |
|
1679 |
return; |
|
1680 |
||
1681 |
addReads = new LinkedHashMap<>(); |
|
1682 |
||
1683 |
if (addReadsOpt == null) |
|
1684 |
return; |
|
1685 |
||
1686 |
Pattern rp = Pattern.compile("([^=]+)=(.*)"); |
|
1687 |
for (String s : addReadsOpt.split("\0+")) { |
|
1688 |
if (s.isEmpty()) |
|
1689 |
continue; |
|
1690 |
Matcher rm = rp.matcher(s); |
|
1691 |
if (!rm.matches()) { |
|
1692 |
continue; |
|
1693 |
} |
|
1694 |
||
1695 |
// Terminology comes from |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1696 |
// --add-reads source-module=target-module,... |
36526 | 1697 |
// Compare to |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1698 |
// module source-module { requires target-module; ... } |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1699 |
String sourceName = rm.group(1); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1700 |
String targetNames = rm.group(2); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1701 |
|
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1702 |
if (!isValidName(sourceName)) |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1703 |
continue; |
36526 | 1704 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1705 |
ModuleSymbol msym = syms.enterModule(names.fromString(sourceName)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1706 |
if (!allModules.contains(msym)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1707 |
if (lintOptions) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1708 |
log.warning(Warnings.ModuleForOptionNotFound(Option.ADD_READS, msym)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1709 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1710 |
continue; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1711 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1712 |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1713 |
if (!allowAccessIntoSystem && (msym.flags() & Flags.SYSTEM_MODULE) != 0) { |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1714 |
log.error(Errors.AddReadsWithRelease(msym)); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1715 |
continue; |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1716 |
} |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
44822
diff
changeset
|
1717 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1718 |
for (String targetName : targetNames.split("[ ,]+", -1)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1719 |
ModuleSymbol targetModule; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1720 |
if (targetName.equals("ALL-UNNAMED")) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1721 |
targetModule = syms.unnamedModule; |
36526 | 1722 |
} else { |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1723 |
if (!isValidName(targetName)) |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1724 |
continue; |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1725 |
targetModule = syms.enterModule(names.fromString(targetName)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1726 |
if (!allModules.contains(targetModule)) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1727 |
if (lintOptions) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1728 |
log.warning(LintCategory.OPTIONS, Warnings.ModuleForOptionNotFound(Option.ADD_READS, targetModule)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1729 |
} |
36526 | 1730 |
continue; |
1731 |
} |
|
1732 |
} |
|
1733 |
addReads.computeIfAbsent(msym, m -> new HashSet<>()) |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1734 |
.add(new RequiresDirective(targetModule, EnumSet.of(RequiresFlag.EXTRA))); |
36526 | 1735 |
} |
1736 |
} |
|
1737 |
} |
|
1738 |
||
1739 |
private void checkCyclicDependencies(JCModuleDecl mod) { |
|
1740 |
for (JCDirective d : mod.directives) { |
|
39915
5d1e0740e709
8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents:
39366
diff
changeset
|
1741 |
JCRequires rd; |
5d1e0740e709
8158224: NullPointerException in com.sun.tools.javac.comp.Modules.checkCyclicDependencies when module missing
sadayapalam
parents:
39366
diff
changeset
|
1742 |
if (!d.hasTag(Tag.REQUIRES) || (rd = (JCRequires) d).directive == null) |
36526 | 1743 |
continue; |
1744 |
Set<ModuleSymbol> nonSyntheticDeps = new HashSet<>(); |
|
1745 |
List<ModuleSymbol> queue = List.of(rd.directive.module); |
|
1746 |
while (queue.nonEmpty()) { |
|
1747 |
ModuleSymbol current = queue.head; |
|
1748 |
queue = queue.tail; |
|
1749 |
if (!nonSyntheticDeps.add(current)) |
|
1750 |
continue; |
|
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1751 |
current.complete(); |
50285
5b6bdc59f8cc
8202832: cycle detection depends on ordering of requires directives
jlahoda
parents:
48427
diff
changeset
|
1752 |
if ((current.flags() & Flags.AUTOMATIC_MODULE) != 0) |
36526 | 1753 |
continue; |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42824
diff
changeset
|
1754 |
Assert.checkNonNull(current.requires, current::toString); |
36526 | 1755 |
for (RequiresDirective dep : current.requires) { |
1756 |
if (!dep.flags.contains(RequiresFlag.EXTRA)) |
|
1757 |
queue = queue.prepend(dep.module); |
|
1758 |
} |
|
1759 |
} |
|
1760 |
if (nonSyntheticDeps.contains(mod.sym)) { |
|
1761 |
log.error(rd.moduleName.pos(), Errors.CyclicRequires(rd.directive.module)); |
|
1762 |
} |
|
1763 |
} |
|
1764 |
} |
|
1765 |
||
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1766 |
private boolean isValidName(CharSequence name) { |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1767 |
return SourceVersion.isName(name, Source.toSourceVersion(source)); |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1768 |
} |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
1769 |
|
36526 | 1770 |
// DEBUG |
1771 |
private String toString(ModuleSymbol msym) { |
|
1772 |
return msym.name + "[" |
|
1773 |
+ "kind:" + msym.kind + ";" |
|
1774 |
+ "locn:" + toString(msym.sourceLocation) + "," + toString(msym.classLocation) + ";" |
|
1775 |
+ "info:" + toString(msym.module_info.sourcefile) + "," |
|
1776 |
+ toString(msym.module_info.classfile) + "," |
|
1777 |
+ msym.module_info.completer |
|
1778 |
+ "]"; |
|
1779 |
} |
|
1780 |
||
1781 |
// DEBUG |
|
1782 |
String toString(Location locn) { |
|
1783 |
return (locn == null) ? "--" : locn.getName(); |
|
1784 |
} |
|
1785 |
||
1786 |
// DEBUG |
|
1787 |
String toString(JavaFileObject fo) { |
|
1788 |
return (fo == null) ? "--" : fo.getName(); |
|
1789 |
} |
|
1790 |
||
1791 |
public void newRound() { |
|
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43588
diff
changeset
|
1792 |
allModules = null; |
39917
c51a8950f278
8154705: invalid use of ALL-MODULE-PATH causes crash
ksrini
parents:
39915
diff
changeset
|
1793 |
rootModules = null; |
43579
0d00f3ea77bc
8172240: javac should not need the transitive closure to compile a module
vromero
parents:
43577
diff
changeset
|
1794 |
warnedMissing.clear(); |
36526 | 1795 |
} |
44290
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1796 |
|
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1797 |
public interface PackageNameFinder { |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1798 |
public Name findPackageNameOf(JavaFileObject jfo); |
202973b2d1ae
8176045: No compile error when a package is not declared
jlahoda
parents:
44289
diff
changeset
|
1799 |
} |
36526 | 1800 |
} |