Exemple #1
0
  private void findModuleInfo(ModuleSymbol msym) {
    try {
      JavaFileObject src_fo =
          (msym.sourceLocation == null)
              ? null
              : fileManager.getJavaFileForInput(
                  msym.sourceLocation, names.module_info.toString(), Kind.SOURCE);

      JavaFileObject class_fo =
          (msym.classLocation == null)
              ? null
              : fileManager.getJavaFileForInput(
                  msym.classLocation, names.module_info.toString(), Kind.CLASS);

      JavaFileObject fo =
          (src_fo == null)
              ? class_fo
              : (class_fo == null) ? src_fo : classFinder.preferredFileObject(src_fo, class_fo);

      if (fo == null) {
        String moduleName =
            msym.sourceLocation == null && msym.classLocation != null
                ? fileManager.inferModuleName(msym.classLocation)
                : null;
        if (moduleName != null) {
          msym.module_info.classfile = null;
          msym.flags_field |= Flags.AUTOMATIC_MODULE;
        } else {
          msym.kind = ERR;
        }
      } else {
        msym.module_info.classfile = fo;
        msym.module_info.completer =
            new Symbol.Completer() {
              @Override
              public void complete(Symbol sym) throws CompletionFailure {
                classFinder.fillIn(msym.module_info);
              }

              @Override
              public String toString() {
                return "ModuleInfoCompleter";
              }
            };
      }
    } catch (IOException e) {
      msym.kind = ERR;
    }
  }
Exemple #2
0
  private List<ModuleSymbol> scanModulePath(ModuleSymbol toFind) {
    ListBuffer<ModuleSymbol> results = new ListBuffer<>();
    Map<Name, Location> namesInSet = new HashMap<>();
    while (moduleLocationIterator.hasNext()) {
      Set<Location> locns = (moduleLocationIterator.next());
      namesInSet.clear();
      for (Location l : locns) {
        try {
          Name n = names.fromString(fileManager.inferModuleName(l));
          if (namesInSet.put(n, l) == null) {
            ModuleSymbol msym = syms.enterModule(n);
            if (msym.sourceLocation != null || msym.classLocation != null) {
              // module has already been found, so ignore this instance
              continue;
            }
            if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) {
              msym.sourceLocation = l;
              if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) {
                msym.classLocation =
                    fileManager.getLocationForModule(
                        StandardLocation.CLASS_OUTPUT, msym.name.toString());
              }
            } else {
              msym.classLocation = l;
            }
            if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES
                || moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) {
              msym.flags_field |= Flags.SYSTEM_MODULE;
            }
            if (toFind == msym || toFind == null) {
              // Note: cannot return msym directly, because we must finish
              // processing this set first
              results.add(msym);
            }
          } else {
            log.error(
                Errors.DuplicateModuleOnPath(getDescription(moduleLocationIterator.outer), n));
          }
        } catch (IOException e) {
          // skip location for now?  log error?
        }
      }
      if (toFind != null && results.nonEmpty()) return results.toList();
    }

    return results.toList();
  }