langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java
changeset 45685 95526afc4e20
parent 45682 fc3b228b9e2a
child 45744 db6aedca2c8c
equal deleted inserted replaced
45684:2c5f2779c3d1 45685:95526afc4e20
   144     private final boolean allowModules;
   144     private final boolean allowModules;
   145     private final boolean allowAccessIntoSystem;
   145     private final boolean allowAccessIntoSystem;
   146 
   146 
   147     public final boolean multiModuleMode;
   147     public final boolean multiModuleMode;
   148 
   148 
   149     private final String legacyModuleOverride;
       
   150 
       
   151     private final Name java_se;
   149     private final Name java_se;
   152     private final Name java_;
   150     private final Name java_;
   153 
   151 
   154     ModuleSymbol defaultModule;
   152     ModuleSymbol defaultModule;
   155 
   153 
   193         allowModules = source.allowModules();
   191         allowModules = source.allowModules();
   194         Options options = Options.instance(context);
   192         Options options = Options.instance(context);
   195 
   193 
   196         allowAccessIntoSystem = options.isUnset(Option.RELEASE);
   194         allowAccessIntoSystem = options.isUnset(Option.RELEASE);
   197         lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
   195         lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
   198 
       
   199         Collection<String> xmodules = options.keySet()
       
   200                                              .stream()
       
   201                                              .filter(opt -> opt.startsWith(XMODULES_PREFIX))
       
   202                                              .map(opt -> opt.substring(XMODULES_PREFIX.length()))
       
   203                                              .collect(Collectors.toList());
       
   204 
       
   205         legacyModuleOverride = xmodules.size() == 1 ? xmodules.iterator().next() : null;
       
   206 
   196 
   207         multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
   197         multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH);
   208         ClassWriter classWriter = ClassWriter.instance(context);
   198         ClassWriter classWriter = ClassWriter.instance(context);
   209         classWriter.multiModuleMode = multiModuleMode;
   199         classWriter.multiModuleMode = multiModuleMode;
   210         JNIWriter jniWriter = JNIWriter.instance(context);
   200         JNIWriter jniWriter = JNIWriter.instance(context);
   467                         defaultModule = moduleFinder.findSingleModule();
   457                         defaultModule = moduleFinder.findSingleModule();
   468                         if (defaultModule == syms.unnamedModule) {
   458                         if (defaultModule == syms.unnamedModule) {
   469                             if (moduleOverride != null) {
   459                             if (moduleOverride != null) {
   470                                 checkNoAllModulePath();
   460                                 checkNoAllModulePath();
   471                                 defaultModule = moduleFinder.findModule(names.fromString(moduleOverride));
   461                                 defaultModule = moduleFinder.findModule(names.fromString(moduleOverride));
   472                                 if (legacyModuleOverride != null) {
       
   473                                     defaultModule.sourceLocation = StandardLocation.SOURCE_PATH;
       
   474                                 }
       
   475                                 defaultModule.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
   462                                 defaultModule.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
   476                             } else {
   463                             } else {
   477                                 // Question: why not do findAllModules and initVisiblePackages here?
   464                                 // Question: why not do findAllModules and initVisiblePackages here?
   478                                 // i.e. body of unnamedModuleCompleter
   465                                 // i.e. body of unnamedModuleCompleter
   479                                 defaultModule.completer = getUnnamedModuleCompleter();
   466                                 defaultModule.completer = getUnnamedModuleCompleter();
   544             }
   531             }
   545         }
   532         }
   546     }
   533     }
   547 
   534 
   548     private void checkSourceLocation(JCCompilationUnit tree, ModuleSymbol msym) {
   535     private void checkSourceLocation(JCCompilationUnit tree, ModuleSymbol msym) {
   549         // skip check if legacy module override still in use
       
   550         if (legacyModuleOverride != null) {
       
   551             return;
       
   552         }
       
   553 
       
   554         try {
   536         try {
   555             JavaFileObject fo = tree.sourcefile;
   537             JavaFileObject fo = tree.sourcefile;
   556             if (fileManager.contains(msym.sourceLocation, fo)) {
   538             if (fileManager.contains(msym.sourceLocation, fo)) {
   557                 return;
   539                 return;
   558             }
   540             }
   580         }
   562         }
   581     }
   563     }
   582 
   564 
   583     private String singleModuleOverride(List<JCCompilationUnit> trees) {
   565     private String singleModuleOverride(List<JCCompilationUnit> trees) {
   584         if (!fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) {
   566         if (!fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) {
   585             return legacyModuleOverride;
   567             return null;
   586         }
   568         }
   587 
   569 
   588         Set<String> override = new LinkedHashSet<>();
   570         Set<String> override = new LinkedHashSet<>();
   589         for (JCCompilationUnit tree : trees) {
   571         for (JCCompilationUnit tree : trees) {
   590             JavaFileObject fo = tree.sourcefile;
   572             JavaFileObject fo = tree.sourcefile;
   600                 throw new Error(ex);
   582                 throw new Error(ex);
   601             }
   583             }
   602         }
   584         }
   603 
   585 
   604         switch (override.size()) {
   586         switch (override.size()) {
   605             case 0: return legacyModuleOverride;
   587             case 0: return null;
   606             case 1: return override.iterator().next();
   588             case 1: return override.iterator().next();
   607             default:
   589             default:
   608                 log.error(Errors.TooManyPatchedModules(override));
   590                 log.error(Errors.TooManyPatchedModules(override));
   609                 return null;
   591                 return null;
   610         }
   592         }