Exemple #1
0
  public ModuleSymbol findSingleModule() {
    try {
      JavaFileObject src_fo = getModuleInfoFromLocation(StandardLocation.SOURCE_PATH, Kind.SOURCE);
      JavaFileObject class_fo =
          getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
      JavaFileObject fo =
          (src_fo == null)
              ? class_fo
              : (class_fo == null) ? src_fo : classFinder.preferredFileObject(src_fo, class_fo);

      ModuleSymbol msym;
      if (fo == null) {
        msym = syms.unnamedModule;
      } else {
        switch (fo.getKind()) {
          case SOURCE:
            if (!inFindSingleModule) {
              try {
                inFindSingleModule = true;
                // Note: the following will trigger a re-entrant call to Modules.enter
                msym = sourceFileCompleter.complete(fo);
                msym.module_info.classfile = fo;
              } finally {
                inFindSingleModule = false;
              }
            } else {
              // the module-info.java does not contain a module declaration,
              // avoid infinite recursion:
              msym = syms.unnamedModule;
            }
            break;
          case CLASS:
            Name name;
            try {
              name = names.fromString(readModuleName(fo));
            } catch (BadClassFile | IOException ex) {
              // fillIn will report proper errors:
              name = names.error;
            }
            msym = syms.enterModule(name);
            msym.module_info.classfile = fo;
            msym.completer = Completer.NULL_COMPLETER;
            classFinder.fillIn(msym.module_info);
            break;
          default:
            Assert.error();
            msym = syms.unnamedModule;
            break;
        }
      }

      msym.classLocation = StandardLocation.CLASS_OUTPUT;
      return msym;

    } catch (IOException e) {
      throw new Error(e); // FIXME
    }
  }
Exemple #2
0
  /** Construct a new module finder. */
  protected ModuleFinder(Context context) {
    context.put(moduleFinderKey, this);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    fileManager = context.get(JavaFileManager.class);
    log = Log.instance(context);
    classFinder = ClassFinder.instance(context);

    diags = JCDiagnostic.Factory.instance(context);
  }
Exemple #3
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();
  }
Exemple #4
0
 public ModuleSymbol findModule(Name name) {
   return findModule(syms.enterModule(name));
 }