private void loadCompiledModules(
     List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
   compilerDelegate.visitModules(phasedUnits);
   Modules modules = ceylonContext.getModules();
   // now make sure the phase units have their modules and packages set correctly
   for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
     Package pkg = pu.getPackage();
     loadModuleFromSource(pkg, modules, moduleTrees, trees);
   }
   // also make sure we have packages and modules set up for every Java file we compile
   for (JCCompilationUnit cu : trees) {
     // skip Ceylon CUs
     if (cu instanceof CeylonCompilationUnit) continue;
     String packageName = "";
     if (cu.pid != null) packageName = TreeInfo.fullName(cu.pid).toString();
     /*
      * Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
      */
     Package pkg = modelLoader.findOrCreateModulelessPackage(packageName);
     loadModuleFromSource(pkg, modules, moduleTrees, trees);
   }
   for (PhasedUnit phasedUnit : phasedUnits.getPhasedUnits()) {
     for (Tree.ModuleDescriptor modDescr :
         phasedUnit.getCompilationUnit().getModuleDescriptors()) {
       String name = phasedUnit.getPackage().getNameAsString();
       CeylonPhasedUnit cpu = (CeylonPhasedUnit) phasedUnit;
       CeylonFileObject cfo = (CeylonFileObject) cpu.getFileObject();
       moduleNamesToFileObjects.put(name, cfo);
     }
   }
 }
Beispiel #2
0
 @Override
 public void initRound(JavaCompiler prev) {
   super.initRound(prev);
   // round compilers don't add module trees, it's already done by the first one
   addModuleTrees = false;
   PhasedUnits oldPUs = ((LanguageCompiler) prev).phasedUnits;
   ModuleManager moduleManager = phasedUnits.getModuleManager();
   ModuleSourceMapper moduleSourceMapper = phasedUnits.getModuleSourceMapper();
   for (PhasedUnit pu : oldPUs.getPhasedUnits()) {
     if (pu instanceof CeylonPhasedUnit) {
       CeylonPhasedUnit cpu = (CeylonPhasedUnit) pu;
       // FIXME: this is bad in many ways
       String pkgName;
       try {
         pkgName = getPackage(((CeylonPhasedUnit) pu).getFileObject());
       } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         continue;
       }
       // make a Package with no module yet, we will resolve them later
       /*
        * Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
        */
       com.redhat.ceylon.model.typechecker.model.Package p =
           modelLoader.findOrCreateModulelessPackage(pkgName == null ? "" : pkgName);
       CeylonPhasedUnit newPu =
           new CeylonPhasedUnit(
               pu.getUnitFile(),
               pu.getSrcDir(),
               pu.getCompilationUnit(),
               p,
               moduleManager,
               moduleSourceMapper,
               ceylonContext,
               cpu.getFileObject(),
               cpu.getLineMap());
       phasedUnits.addPhasedUnit(pu.getUnitFile(), newPu);
     } else {
       phasedUnits.addPhasedUnit(pu.getUnitFile(), pu);
     }
   }
 }