Exemple #1
0
 /**
  * Split a path into its elements. If emptyPathDefault is not null, all empty elements in the
  * path, including empty elements at either end of the path, will be replaced with the value of
  * emptyPathDefault.
  *
  * @param path The path to be split
  * @param emptyPathDefault The value to substitute for empty path elements, or null, to ignore
  *     empty path elements
  * @return The elements of the path
  */
 private static Iterable<File> getPathEntries(String path, File emptyPathDefault) {
   ListBuffer<File> entries = new ListBuffer<File>();
   int start = 0;
   while (start <= path.length()) {
     int sep = path.indexOf(File.pathSeparatorChar, start);
     if (sep == -1) sep = path.length();
     if (start < sep) entries.add(new File(path.substring(start, sep)));
     else if (emptyPathDefault != null) entries.add(emptyPathDefault);
     start = sep + 1;
   }
   return entries;
 }
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();
  }