Beispiel #1
0
  @Override
  public void fileRemoved(IFileSpecification removedFile) {
    // paths passed into this function need to have been normalized
    assert (removedFile.getPath().equals(FilenameNormalization.normalize(removedFile.getPath())))
        : "Path not normalized";
    final String path = removedFile.getPath();
    final Set<ASProject> affectedProjects = new HashSet<ASProject>();
    Map<ICompilerProject, Set<ICompilationUnit>> cusToUpdate =
        new HashMap<ICompilerProject, Set<ICompilationUnit>>();
    Collection<ICompilationUnit> relatedCompilationUnits = Collections.emptyList();

    startIdleState();
    try {
      relatedCompilationUnits = collectAssociatedCompilationUnits(removedFile);
      // collect the affected projects before invalidating the relatedCompilationUnits, as removed
      // compilation units will have their projects null'd out during invalidate, causing an NPE.
      for (ICompilationUnit compilationUnit : relatedCompilationUnits) {
        if (compilationUnit == null) continue;

        ICompilerProject containingProject = compilationUnit.getProject();
        assert (containingProject instanceof ASProject);
        affectedProjects.add((ASProject) containingProject);
      }

      invalidate(removedFile, relatedCompilationUnits, cusToUpdate);
    } finally {
      File f = new File(path);
      for (ASProject project : affectedProjects) {
        project.removeSourceFile(f);
      }

      // update the pathToCompilationUnitMapping CU by CU, rather than
      // just taking the whole path away, as we don't want to loose mappings
      // between SWC compilation units and the SWC path
      for (ICompilationUnit cu : relatedCompilationUnits) {
        if (cu.getCompilationUnitType() != UnitType.SWC_UNIT) {
          pathToCompilationUnitMapping.remove(path, cu);
          includeFilesToIncludingCompilationUnitMapping.remove(path, cu);
        }
      }

      pathToFileSpecMap.remove(path);

      endIdleState(cusToUpdate);
    }
  }
Beispiel #2
0
  /**
   * Remove a compilation unit from the filename to compilation unit map
   *
   * @param compilationUnit The compilation unit to be removed.
   */
  public void removeCompilationUnit(ICompilationUnit compilationUnit) {
    String path = compilationUnit.getAbsoluteFilename();
    // paths passed into this function need to have been normalized
    assert (path.equals(FilenameNormalization.normalize(path))) : "Path not normalized";

    pathToCompilationUnitMapping.remove(path, compilationUnit);
    ((CompilationUnitBase) compilationUnit).clearIncludedFilesFromWorkspace();

    // only remove the file spec if there are no more remaining CUs tied
    // to that path
    if (pathToCompilationUnitMapping.get(path).isEmpty()
        && includeFilesToIncludingCompilationUnitMapping.get(path).isEmpty()) {
      pathToFileSpecMap.remove(path);
    }
  }
Beispiel #3
0
 /**
  * Remove any references to the compilation unit to the collection of include files it includes.
  *
  * @param includingCompilationUnit {@link ICompilationUnit} that contains include statements that
  *     reference the specified list of files.
  * @param includedFiles The included files.
  */
 public void removeIncludedFilesToCompilationUnit(
     ICompilationUnit includingCompilationUnit, Collection<String> includedFiles) {
   for (String includedFile : includedFiles) {
     includeFilesToIncludingCompilationUnitMapping.remove(includedFile, includingCompilationUnit);
   }
 }