private void loadModuleFromSource(
      Package pkg, Modules modules, LinkedList<JCCompilationUnit> moduleTrees) {
    // skip it if we already resolved the package
    if (pkg.getModule() != null) return;
    String pkgName = pkg.getQualifiedNameString();
    Module module = null;
    // do we have a module for this package?
    // FIXME: is this true? what if we have a module.ceylon at toplevel?
    if (pkgName.isEmpty()) module = modules.getDefaultModule();
    else {
      for (Module m : modules.getListOfModules()) {
        if (pkgName.startsWith(m.getNameAsString())) {
          module = m;
          break;
        }
      }
      if (module == null) {
        module = loadModuleFromSource(pkgName, moduleTrees);
      } else if (!module.isAvailable()) {
        loadModuleFromSource(pkgName, moduleTrees);
      }

      if (module == null) {
        // no declaration for it, must be the default module
        module = modules.getDefaultModule();
      }
    }
    // bind module and package together
    pkg.setModule(module);
    module.getPackages().add(pkg);
    // automatically add this module's jar to the classpath if it exists
    ceylonEnter.addModuleToClassPath(module, false);
  }
Exemplo n.º 2
0
  private void loadModuleFromSource(
      Package pkg,
      Modules modules,
      LinkedList<JCCompilationUnit> moduleTrees,
      List<JCCompilationUnit> parsedTrees) {
    // skip it if we already resolved the package
    if (pkg.getModule() != null) {
      // make sure the default module is always added to the classpath, it will be the only one to
      // have a module
      if (!addedDefaultModuleToClassPath && pkg.getModule().isDefault()) {
        addedDefaultModuleToClassPath = true;
        ceylonEnter.addOutputModuleToClassPath(pkg.getModule());
      }
      return;
    }
    String pkgName = pkg.getQualifiedNameString();
    Module module = null;
    // do we have a module for this package?
    // FIXME: is this true? what if we have a module.ceylon at toplevel?
    if (pkgName.isEmpty()) module = modules.getDefaultModule();
    else {
      for (Module m : modulesLoadedFromSource) {
        if (Util.isSubPackage(m.getNameAsString(), pkgName)) {
          module = m;
          break;
        }
      }
      if (module == null) {
        module = loadModuleFromSource(pkgName, moduleTrees, parsedTrees);
      } else if (!module.isAvailable()) {
        loadModuleFromSource(pkgName, moduleTrees, parsedTrees);
      }

      if (module == null) {
        // no declaration for it, must be the default module, unless we're bootstrapping the
        // language module,
        // because we have some com.redhat.ceylon packages that must go in the language module
        if (isBootstrap) module = modules.getLanguageModule();
        else module = modules.getDefaultModule();
      }
    }
    // bind module and package together
    pkg.setModule(module);
    module.getPackages().add(pkg);
    // automatically add this module's jar to the classpath if it exists
    ceylonEnter.addOutputModuleToClassPath(module);
  }