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);
  }
  @Override
  protected void setPhasedUnitIfNecessary() {
    if (phasedUnitRef == null) {
      // Look into the mapping.txt of the module archive, and get the name of the source unit
      // Then get the PhasedUnits related to this module, and search for the relative path in it.
      // Then set it into the WeakRef with createPhasedUnit

      String[] splittedPath = getFullPath().split("!");
      if (splittedPath.length == 2) {
        String carPath = splittedPath[0];
        try {
          Properties mapping = CarUtils.retrieveMappingFile(new File(carPath));
          String sourceFileRelativePath = mapping.getProperty(splittedPath[1]);
          Package pkg = getPackage();
          if (pkg != null) {
            Module module = pkg.getModule();
            // TODO : retrieve the PhasedUnits object related to this module
            // get the PhasedUnit object through its src-relative path
            IdePhasedUnit pu = null; // replace by the right value
            createPhasedUnitRef(pu);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
Пример #3
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);
  }
Пример #4
0
 private JavaFileObject genCodeUnlessError(Env<AttrContext> env, JCClassDecl cdef)
     throws IOException {
   CeylonFileObject sourcefile = (CeylonFileObject) env.toplevel.sourcefile;
   try {
     // do not look at the global number of errors but only those for this file
     if (super.gen.genClass(env, cdef) && !sourcefile.hasError(cdef.pos)) {
       String packageName = cdef.sym.packge().getQualifiedName().toString();
       Package pkg = modelLoader.findPackage(packageName);
       if (pkg == null) throw new RuntimeException("Failed to find package: " + packageName);
       Module module = pkg.getModule();
       if (!module.isDefault()) {
         String moduleName = module.getNameAsString();
         CeylonFileObject moduleFileObject = moduleNamesToFileObjects.get(moduleName);
         // if there's no module source file object it means the module descriptor had parse errors
         if (moduleFileObject == null || moduleFileObject.hasError()) {
           // we do not produce any class files for modules with errors
           if (options.get(OptionName.VERBOSE) != null) {
             Log.printLines(
                 log.noticeWriter,
                 "[Not writing class "
                     + cdef.sym.className()
                     + " because its module has errors: "
                     + moduleName
                     + "]");
           }
           return null;
         }
       }
       return writer.writeClass(cdef.sym);
     }
   } catch (ClassWriter.PoolOverflow ex) {
     log.error(cdef.pos(), "limit.pool");
   } catch (ClassWriter.StringOverflow ex) {
     log.error(cdef.pos(), "limit.string.overflow", ex.value.substring(0, 20));
   } catch (CompletionFailure ex) {
     chk.completionError(cdef.pos(), ex);
   } catch (AssertionError e) {
     throw new RuntimeException("Error generating bytecode for " + sourcefile.getName(), e);
   }
   return null;
 }