Example #1
0
 @NotNull
 public static TextDiffType create(@Nullable final TextDiffTypeEnum type) {
   if (TextDiffTypeEnum.INSERT.equals(type)) {
     return INSERT;
   } else if (TextDiffTypeEnum.CHANGED.equals(type)) {
     return CHANGED;
   } else if (TextDiffTypeEnum.DELETED.equals(type)) {
     return DELETED;
   } else if (TextDiffTypeEnum.CONFLICT.equals(type)) {
     return CONFLICT;
   } else {
     return NONE;
   }
 }
    @Override
    public Pair<Integer, String> next() {
      if (!myBuffer.isEmpty()) {
        return myBuffer.remove(0);
      }

      Fragment fragment = null;
      while (myFragmentsIterator.hasNext()) {
        fragment = myFragmentsIterator.next();
        final TextDiffTypeEnum type = fragment.getType();
        if (!myIgnoreFragmentsType
            && (type == null
                || TextDiffTypeEnum.DELETED.equals(type)
                || TextDiffTypeEnum.NONE.equals(type))) continue;
        break;
      }
      if (fragment == null) return null;

      final TextRange textRange = fragment.getRange(FragmentSide.SIDE2);
      ApplicationManager.getApplication()
          .runReadAction(
              new Runnable() {
                @Override
                public void run() {
                  final int startLine = myDocument.getLineNumber(textRange.getStartOffset());
                  final int endFragmentOffset = textRange.getEndOffset();
                  final int endLine = myDocument.getLineNumber(endFragmentOffset);
                  for (int i = startLine; i <= endLine; i++) {
                    int lineEndOffset = myDocument.getLineEndOffset(i);
                    final int lineStartOffset = myDocument.getLineStartOffset(i);
                    if (lineEndOffset > endFragmentOffset && endFragmentOffset == lineStartOffset) {
                      lineEndOffset = endFragmentOffset;
                    }
                    if (lineStartOffset > lineEndOffset) continue;
                    String text = myDocument.getText().substring(lineStartOffset, lineEndOffset);
                    myBuffer.add(new Pair<Integer, String>(i, text));
                  }
                }
              });
      if (myBuffer.isEmpty()) return null;
      return myBuffer.remove(0);
    }