コード例 #1
0
  /**
   * Uses the specified location converter to update each internal representation of a file
   * location. The file index is rebuilt with the new representations. Individual PDOMFile records
   * are unmoved so as to maintain referential integrity with other PDOM records.
   *
   * <p><b>A write-lock must be obtained before calling this method</b>
   *
   * @param newConverter the converter to use to update internal file representations
   * @throws CoreException
   */
  public void rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException {
    final List<PDOMFile> pdomfiles = new ArrayList<PDOMFile>();
    getFileIndex()
        .accept(
            new IBTreeVisitor() {
              @Override
              public int compare(long record) throws CoreException {
                return 0;
              }

              @Override
              public boolean visit(long record) throws CoreException {
                PDOMFile file = PDOMFile.recreateFile(WritablePDOM.this, record);
                pdomfiles.add(file);
                return true;
              }
            });

    clearFileIndex();
    final List<PDOMFile> notConverted = new ArrayList<PDOMFile>();
    for (PDOMFile file : pdomfiles) {
      String internalFormat = newConverter.toInternalFormat(file.getLocation());
      if (internalFormat != null) {
        file.setInternalLocation(internalFormat);
        getFileIndex().insert(file.getRecord());
      } else {
        notConverted.add(file);
      }
    }

    // remove content where converter returns null
    for (PDOMFile file : notConverted) {
      file.convertIncludersToUnresolved();
      file.clear();
    }
  }