protected void updateRefsToMovedCeylonFile(
      final IProject project,
      final String newName,
      final String oldName,
      final List<Change> changes,
      PhasedUnit movedPhasedUnit,
      final List<Declaration> declarations) {
    if (!getArguments().getUpdateReferences()) return;
    TypeChecker tc = getProjectTypeChecker(project);
    if (tc == null) return;
    for (PhasedUnit phasedUnit : tc.getPhasedUnits().getPhasedUnits()) {
      if (phasedUnit == movedPhasedUnit
          || phasedUnit.getUnit() instanceof ProjectSourceFile
              && movingFiles.contains(
                  ((ProjectSourceFile) phasedUnit.getUnit()).getFileResource())) {
        continue;
      }
      final Map<Declaration, String> imports = new HashMap<Declaration, String>();
      phasedUnit
          .getCompilationUnit()
          .visit(
              new Visitor() {
                @Override
                public void visit(ImportMemberOrType that) {
                  super.visit(that);
                  visitIt(that.getIdentifier(), that.getDeclarationModel());
                }
                //                    @Override
                //                    public void visit(QualifiedMemberOrTypeExpression that) {
                //                        super.visit(that);
                //                        visitIt(that.getIdentifier(), that.getDeclaration());
                //                    }
                @Override
                public void visit(BaseMemberOrTypeExpression that) {
                  super.visit(that);
                  visitIt(that.getIdentifier(), that.getDeclaration());
                }

                @Override
                public void visit(BaseType that) {
                  super.visit(that);
                  visitIt(that.getIdentifier(), that.getDeclarationModel());
                }
                //                    @Override
                //                    public void visit(QualifiedType that) {
                //                        super.visit(that);
                //                        visitIt(that.getIdentifier(), that.getDeclarationModel());
                //                    }
                protected void visitIt(Tree.Identifier id, Declaration dec) {
                  if (dec != null && declarations.contains(dec)) {
                    imports.put(dec, id.getText());
                  }
                }
                // TODO: DocLinks!!
              });
      collectEdits(newName, oldName, changes, phasedUnit, imports);
    }
  }
 static void addCreateToplevelProposals(
     Collection<ICompletionProposal> proposals, IProject project, DefinitionGenerator dg) {
   Tree.Statement statement = findToplevelStatement(dg.getRootNode(), dg.getNode());
   if (statement != null) {
     for (PhasedUnit unit : getUnits(project)) {
       if (unit.getUnit().equals(dg.getRootNode().getUnit())) {
         addCreateProposal(proposals, false, dg, unit, statement);
         break;
       }
     }
   }
 }
 static Tree.CompilationUnit getRootNode(PhasedUnit unit) {
   IEditorPart ce = getCurrentEditor();
   if (ce instanceof CeylonEditor) {
     CeylonEditor editor = (CeylonEditor) ce;
     CeylonParseController cpc = editor.getParseController();
     if (cpc != null) {
       Tree.CompilationUnit rn = cpc.getTypecheckedRootNode();
       if (rn != null) {
         Unit u = rn.getUnit();
         if (u.equals(unit.getUnit())) {
           return rn;
         }
       }
     }
   }
   return unit.getCompilationUnit();
 }
 static void addCreateMemberProposals(
     Collection<ICompletionProposal> proposals,
     IProject project,
     DefinitionGenerator dg,
     Declaration typeDec,
     Tree.Statement statement) {
   if (typeDec != null
       && (typeDec instanceof Class || (typeDec instanceof Interface && dg.isFormalSupported()))) {
     for (PhasedUnit unit : getUnits(project)) {
       if (typeDec.getUnit().equals(unit.getUnit())) {
         // TODO: "object" declarations?
         FindDeclarationNodeVisitor fdv = new FindDeclarationNodeVisitor(typeDec);
         getRootNode(unit).visit(fdv);
         Tree.Declaration decNode = (Tree.Declaration) fdv.getDeclarationNode();
         Tree.Body body = getClassOrInterfaceBody(decNode);
         if (body != null) {
           addCreateMemberProposal(proposals, dg, typeDec, unit, decNode, body, statement);
           break;
         }
       }
     }
   }
 }
Esempio n. 5
0
 private Module loadModuleFromSource(
     String pkgName,
     LinkedList<JCCompilationUnit> moduleTrees,
     List<JCCompilationUnit> parsedTrees) {
   if (pkgName.isEmpty()) return null;
   String moduleClassName = pkgName + ".module";
   JavaFileObject fileObject;
   try {
     if (options.get(Option.VERBOSE) != null) {
       log.printRawLines(
           WriterKind.NOTICE, "[Trying to load source for module " + moduleClassName + "]");
     }
     fileObject =
         fileManager.getJavaFileForInput(
             StandardLocation.SOURCE_PATH, moduleClassName, Kind.SOURCE);
     if (options.get(Option.VERBOSE) != null) {
       log.printRawLines(WriterKind.NOTICE, "[Got file object: " + fileObject + "]");
     }
   } catch (IOException e) {
     e.printStackTrace();
     return loadModuleFromSource(getParentPackage(pkgName), moduleTrees, parsedTrees);
   }
   if (fileObject != null) {
     // first make sure we're not already compiling it: this can happen if we have several versions
     // of the
     // same module already loaded: we will get one which isn't the one we compile, but that's not
     // the one
     // we really want to compile.
     for (JCCompilationUnit parsedTree : parsedTrees) {
       if (parsedTree.sourcefile.equals(fileObject)
           && parsedTree instanceof CeylonCompilationUnit) {
         // same file! we already parsed it, let's return this one's module
         PhasedUnit phasedUnit = ((CeylonCompilationUnit) parsedTree).phasedUnit;
         // the module visitor does load the module but does not set the unit's package module
         if (phasedUnit.getPackage().getModule() == null) {
           // so find the module it created
           for (Module mod : ceylonContext.getModules().getListOfModules()) {
             // we recognise it with the unit
             if (mod.getUnit() == phasedUnit.getUnit()) {
               // set the package's module
               Package pkg = phasedUnit.getPackage();
               pkg.setModule(mod);
               mod.getPackages().add(pkg);
               modulesLoadedFromSource.add(mod);
               break;
             }
           }
         }
         // now return it
         return phasedUnit.getPackage().getModule();
       }
     }
     JCCompilationUnit javaCompilationUnit = parse(fileObject);
     Module module;
     if (javaCompilationUnit instanceof CeylonCompilationUnit) {
       CeylonCompilationUnit ceylonCompilationUnit = (CeylonCompilationUnit) javaCompilationUnit;
       moduleTrees.add(ceylonCompilationUnit);
       // parse the module info from there
       module = ceylonCompilationUnit.phasedUnit.visitSrcModulePhase();
       ceylonCompilationUnit.phasedUnit.visitRemainingModulePhase();
       // now set the module
       if (module != null) {
         ceylonCompilationUnit.phasedUnit.getPackage().setModule(module);
       }
     } else {
       // there was a syntax error in the module descriptor, make a pretend module so that we can
       // correctly mark all declarations as part of that module, but we won't generate any code
       // for it
       ModuleManager moduleManager = phasedUnits.getModuleManager();
       module = moduleManager.getOrCreateModule(Arrays.asList(pkgName.split("\\.")), "bogus");
     }
     // now remember it
     if (module != null) {
       modulesLoadedFromSource.add(module);
       return module;
     }
   }
   return loadModuleFromSource(getParentPackage(pkgName), moduleTrees, parsedTrees);
 }