72 /** The context key for the module finder. */
73 protected static final Context.Key<ModuleFinder> moduleFinderKey = new Context.Key<>();
74
75 /** The log to use for verbose output. */
76 private final Log log;
77
78 /** The symbol table. */
79 private final Symtab syms;
80
81 /** The name table. */
82 private final Names names;
83
84 private final ClassFinder classFinder;
85
86 /** Access to files
87 */
88 private final JavaFileManager fileManager;
89
90 private final JCDiagnostic.Factory diags;
91
92 private ModuleNameReader moduleNameReader;
93
94 public ModuleNameFromSourceReader moduleNameFromSourceReader;
95
96 /** Get the ModuleFinder instance for this invocation. */
97 public static ModuleFinder instance(Context context) {
98 ModuleFinder instance = context.get(moduleFinderKey);
99 if (instance == null)
100 instance = new ModuleFinder(context);
101 return instance;
102 }
103
104 /** Construct a new module finder. */
105 protected ModuleFinder(Context context) {
106 context.put(moduleFinderKey, this);
107 names = Names.instance(context);
108 syms = Symtab.instance(context);
109 fileManager = context.get(JavaFileManager.class);
110 log = Log.instance(context);
111 classFinder = ClassFinder.instance(context);
112
113 diags = JCDiagnostic.Factory.instance(context);
114 }
115
116 class ModuleLocationIterator implements Iterator<Set<Location>> {
117 StandardLocation outer;
118 Set<Location> next = null;
119
120 Iterator<StandardLocation> outerIter = Arrays.asList(
121 StandardLocation.MODULE_SOURCE_PATH,
122 StandardLocation.UPGRADE_MODULE_PATH,
123 StandardLocation.SYSTEM_MODULES,
124 StandardLocation.MODULE_PATH
125 ).iterator();
126 Iterator<Set<Location>> innerIter = null;
127
128 @Override
129 public boolean hasNext() {
130 while (next == null) {
131 while (innerIter == null || !innerIter.hasNext()) {
132 if (outerIter.hasNext()) {
133 outer = outerIter.next();
210 msym.classLocation = StandardLocation.CLASS_OUTPUT;
211 } else {
212 msym.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
213 }
214 return msym;
215
216 } catch (IOException e) {
217 throw new Error(e); // FIXME
218 }
219 }
220
221 private ModuleSymbol readModule(JavaFileObject fo) throws IOException {
222 Name name;
223 switch (fo.getKind()) {
224 case SOURCE:
225 name = moduleNameFromSourceReader.readModuleName(fo);
226 if (name == null) {
227 JCDiagnostic diag =
228 diags.fragment(Fragments.FileDoesNotContainModule);
229 ClassSymbol errModuleInfo = syms.defineClass(names.module_info, syms.errModule);
230 throw new ClassFinder.BadClassFile(errModuleInfo, fo, diag, diags);
231 }
232 break;
233 case CLASS:
234 try {
235 name = names.fromString(readModuleName(fo));
236 } catch (BadClassFile | IOException ex) {
237 //fillIn will report proper errors:
238 name = names.error;
239 }
240 break;
241 default:
242 Assert.error();
243 name = names.error;
244 break;
245 }
246
247 ModuleSymbol msym = syms.enterModule(name);
248 msym.module_info.classfile = fo;
249 if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) && name != names.error) {
250 msym.patchLocation = fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, name.toString());
|
72 /** The context key for the module finder. */
73 protected static final Context.Key<ModuleFinder> moduleFinderKey = new Context.Key<>();
74
75 /** The log to use for verbose output. */
76 private final Log log;
77
78 /** The symbol table. */
79 private final Symtab syms;
80
81 /** The name table. */
82 private final Names names;
83
84 private final ClassFinder classFinder;
85
86 /** Access to files
87 */
88 private final JavaFileManager fileManager;
89
90 private final JCDiagnostic.Factory diags;
91
92 private final DeferredCompletionFailureHandler dcfh;
93
94 private ModuleNameReader moduleNameReader;
95
96 public ModuleNameFromSourceReader moduleNameFromSourceReader;
97
98 /** Get the ModuleFinder instance for this invocation. */
99 public static ModuleFinder instance(Context context) {
100 ModuleFinder instance = context.get(moduleFinderKey);
101 if (instance == null)
102 instance = new ModuleFinder(context);
103 return instance;
104 }
105
106 /** Construct a new module finder. */
107 protected ModuleFinder(Context context) {
108 context.put(moduleFinderKey, this);
109 names = Names.instance(context);
110 syms = Symtab.instance(context);
111 fileManager = context.get(JavaFileManager.class);
112 log = Log.instance(context);
113 classFinder = ClassFinder.instance(context);
114
115 diags = JCDiagnostic.Factory.instance(context);
116 dcfh = DeferredCompletionFailureHandler.instance(context);
117 }
118
119 class ModuleLocationIterator implements Iterator<Set<Location>> {
120 StandardLocation outer;
121 Set<Location> next = null;
122
123 Iterator<StandardLocation> outerIter = Arrays.asList(
124 StandardLocation.MODULE_SOURCE_PATH,
125 StandardLocation.UPGRADE_MODULE_PATH,
126 StandardLocation.SYSTEM_MODULES,
127 StandardLocation.MODULE_PATH
128 ).iterator();
129 Iterator<Set<Location>> innerIter = null;
130
131 @Override
132 public boolean hasNext() {
133 while (next == null) {
134 while (innerIter == null || !innerIter.hasNext()) {
135 if (outerIter.hasNext()) {
136 outer = outerIter.next();
213 msym.classLocation = StandardLocation.CLASS_OUTPUT;
214 } else {
215 msym.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
216 }
217 return msym;
218
219 } catch (IOException e) {
220 throw new Error(e); // FIXME
221 }
222 }
223
224 private ModuleSymbol readModule(JavaFileObject fo) throws IOException {
225 Name name;
226 switch (fo.getKind()) {
227 case SOURCE:
228 name = moduleNameFromSourceReader.readModuleName(fo);
229 if (name == null) {
230 JCDiagnostic diag =
231 diags.fragment(Fragments.FileDoesNotContainModule);
232 ClassSymbol errModuleInfo = syms.defineClass(names.module_info, syms.errModule);
233 throw new ClassFinder.BadClassFile(errModuleInfo, fo, diag, diags, dcfh);
234 }
235 break;
236 case CLASS:
237 try {
238 name = names.fromString(readModuleName(fo));
239 } catch (BadClassFile | IOException ex) {
240 //fillIn will report proper errors:
241 name = names.error;
242 }
243 break;
244 default:
245 Assert.error();
246 name = names.error;
247 break;
248 }
249
250 ModuleSymbol msym = syms.enterModule(name);
251 msym.module_info.classfile = fo;
252 if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) && name != names.error) {
253 msym.patchLocation = fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, name.toString());
|