Beispiel #1
0
  /**
   * Maintain a mapping between filenames and compilation units. Needed for incremental compilation.
   */
  public void addCompilationUnit(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.add(path, compilationUnit);
  }
Beispiel #2
0
  /**
   * Gets the {@link IFileSpecification} for the root source file of the specified {@link
   * ICompilationUnit}.
   *
   * @param compilationUnit A compilation unit.
   * @return Tthe {@link IFileSpecification} for the root source file of the specified {@link
   *     ICompilationUnit}
   */
  public IFileSpecification getFileSpecificationForCompilationUnit(
      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";

    // Make sure that we seen this path associated with a compilation unit before.
    assert pathToCompilationUnitMapping.get(path) != null;

    return getFileSpecification(path);
  }
Beispiel #3
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 #4
0
  private void notifyInvalidationListener(Collection<ICompilationUnit> unitsToClean) {
    if (invalidationListeners.isEmpty()) return;

    Map<ICompilerProject, Collection<InvalidatedDefinition>> invalidationMap =
        new HashMap<ICompilerProject, Collection<InvalidatedDefinition>>();

    for (ICompilationUnit compilationUnit : unitsToClean) {
      // Collect all definitions associated with the compilation unit
      Collection<IDefinition> definitions = compilationUnit.getDefinitionPromises();
      if (definitions.size() == 0) {
        // no definition promises, so getting the file scope should be cheap.
        try {
          IFileScopeRequestResult fsr = compilationUnit.getFileScopeRequest().get();
          definitions = fsr.getExternallyVisibleDefinitions();
        } catch (InterruptedException e1) {
          assert false : "Since this is a single threaded method, we should never be interrupted";
        }
      }

      // for all the found definition, build up a map of projects to a list of
      // InvalidatedDefinitions
      // and pass this map onto the registered invalidation listener to do with what it will
      if (definitions.size() > 0) {
        Collection<InvalidatedDefinition> invalidatedDefinitions =
            invalidationMap.get(compilationUnit.getProject());
        if (invalidatedDefinitions == null) {
          invalidatedDefinitions = new LinkedList<InvalidatedDefinition>();
          invalidationMap.put(compilationUnit.getProject(), invalidatedDefinitions);
        }

        String filename = compilationUnit.getAbsoluteFilename();
        for (IDefinition definition : definitions) {
          String qName = definition.getQualifiedName();
          InvalidatedDefinition invalidatedDefinition = new InvalidatedDefinition(qName, filename);
          invalidatedDefinitions.add(invalidatedDefinition);
        }
      }
    }
    for (IInvalidationListener listener : invalidationListeners)
      listener.definitionsChanged(invalidationMap);
  }