Пример #1
0
 @NotNull
 public DiffFragment[] buildDiffFragmentsFromLines(
     @NotNull DiffString[] lines1, @NotNull DiffString[] lines2)
     throws FilesTooBigForDiffException {
   DiffFragmentBuilder builder = new DiffFragmentBuilder(lines1, lines2);
   Object[] wrappers1 = getLineWrappers(lines1);
   Object[] wrappers2 = getLineWrappers(lines2);
   Diff.Change change = Diff.buildChanges(wrappers1, wrappers2);
   return builder.buildFragments(change);
 }
Пример #2
0
 @NotNull
 public DiffFragment[] buildFragments(
     @NotNull DiffString[] strings1, @NotNull DiffString[] strings2)
     throws FilesTooBigForDiffException {
   DiffFragmentBuilder builder = new DiffFragmentBuilder(strings1, strings2);
   Object[] wrappers1 = getWrappers(strings1);
   Object[] wrappers2 = getWrappers(strings2);
   Diff.Change change = Diff.buildChanges(wrappers1, wrappers2);
   return builder.buildFragments(Util.concatEquals(change, wrappers1, wrappers2));
 }
  /*
   * Compare two arrays, basing on equals() and hashCode() of it's elements
   */
  @NotNull
  public static <T> FairDiffIterable diff(
      @NotNull T[] data1, @NotNull T[] data2, @NotNull ProgressIndicator indicator) {
    indicator.checkCanceled();

    try {
      // TODO: use ProgressIndicator inside
      Diff.Change change = Diff.buildChanges(data1, data2);
      return fair(create(change, data1.length, data2.length));
    } catch (FilesTooBigForDiffException e) {
      throw new DiffTooBigException();
    }
  }
  @Nullable
  private SoftReference<TIntIntHashMap> doGetLineMapping(final long date, boolean oldToNew) {
    final VirtualFile f = getVirtualFile();
    final byte[] oldContent;
    synchronized (LOCK) {
      if (myOldContent == null) {
        if (ApplicationManager.getApplication().isDispatchThread()) return null;
        final LocalHistory localHistory = LocalHistory.getInstance();
        byte[] byteContent =
            localHistory.getByteContent(
                f,
                new FileRevisionTimestampComparator() {
                  public boolean isSuitable(long revisionTimestamp) {
                    return revisionTimestamp < date;
                  }
                });

        if (byteContent == null && f.getTimeStamp() > date) {
          byteContent = loadFromVersionControl(date, f);
        }
        myOldContent = new SoftReference<byte[]>(byteContent);
      }
      oldContent = myOldContent.get();
    }

    if (oldContent == null) return null;
    String[] coveredLines = getCoveredLines(oldContent, f);
    final Document document = myDocument;
    if (document == null) return null;
    String[] currentLines = getUpToDateLines(document);

    String[] oldLines = oldToNew ? coveredLines : currentLines;
    String[] newLines = oldToNew ? currentLines : coveredLines;

    Diff.Change change;
    try {
      change = Diff.buildChanges(oldLines, newLines);
    } catch (FilesTooBigForDiffException e) {
      LOG.info(e);
      return null;
    }
    return new SoftReference<TIntIntHashMap>(
        getCoverageVersionToCurrentLineMapping(change, oldLines.length));
  }
 private void buildDiff() throws FilesTooBigForDiffException {
   // Diff diff = new Diff(strings1, strings2);
   // myChange = diff.diff_2(false);
   myChange = Diff.buildChanges(myOldString, myNewString);
 }
 public int translateLineViaDiffStrict(int line) throws FilesTooBigForDiffException {
   if (myChange == null) buildDiff();
   Diff.Change change = myChange;
   if (change == null) return line;
   return Diff.translateLine(change, line);
 }