Ejemplo n.º 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
    }
  }
Ejemplo n.º 2
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;
    }
  }