Package com.intellij.openapi.diff.ex

Examples of com.intellij.openapi.diff.ex.DiffFragment


    if (!fragment1.isOneSide()) {
      String unitedText1 = fragment1.getText1() + fragment2.getText1();
      String unitedText2 = fragment1.getText2() + fragment2.getText2();
      LOG.assertTrue(fragment1.isEqual() == fragment2.isEqual());
      return fragment1.isEqual() ? DiffFragment.unchanged(unitedText1, unitedText2) :
          new DiffFragment(unitedText1, unitedText2);
    }
    FragmentSide side = FragmentSide.chooseSide(fragment1);
    return side.createFragment(side.getText(fragment1) + side.getText(fragment2), null, fragment1.isModified());
  }
View Full Code Here


  }

  public static String getText(DiffFragment[] fragments, FragmentSide side) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < fragments.length; i++) {
      DiffFragment fragment = fragments[i];
      String text = side.getText(fragment);
      if (text != null) buffer.append(text);
    }
    return buffer.toString();
  }
View Full Code Here

  public static DiffFragment concatenate(DiffFragment[] line, int from, int to) {
    StringBuffer buffer1 = new StringBuffer();
    StringBuffer buffer2 = new StringBuffer();
    boolean isEqual = true;
    for (int j = from; j < to; j++) {
      DiffFragment fragment = line[j];
      isEqual &= fragment.isEqual();
      String text1 = fragment.getText1();
      String text2 = fragment.getText2();
      if (text1 != null) buffer1.append(text1);
      if (text2 != null) buffer2.append(text2);
    }
    String text1 = notEmptyContent(buffer1);
    String text2 = notEmptyContent(buffer2);
    return isEqual ? DiffFragment.unchanged(text1, text2) : new DiffFragment(text1, text2);
  }
View Full Code Here

    return result.toArray();
  }

  private static boolean areEqualOrFormatting(DiffFragment[] fragments) {
    for (int i = 0; i < fragments.length; i++) {
      DiffFragment fragment = fragments[i];
      if (fragment.isEqual()) continue;
      for (int side = 0;  side < 2; side++) {
        String text = FragmentSide.fromIndex(side).getText(fragment);
        if (text == null || text.trim().length() == 0) continue;
        return false;
      }
View Full Code Here

    return true;
  }

  private static boolean areEqual(DiffFragment[] fragments) {
    for (int i = 0; i < fragments.length; i++) {
      DiffFragment fragment = fragments[i];
      if (!fragment.isEqual()) return false;
    }
    return true;
  }
View Full Code Here

    int nullCount = 0;
    for (int sideIndex = 0; sideIndex < 2; sideIndex++) {
      FragmentSide side = FragmentSide.fromIndex(sideIndex);
      for (int i = 0; i < fragments.length; i++) {
        DiffFragment fragment = fragments[i];
        if (fragment == null) continue;
        String text = side.getText(fragment);
        if (text == null || text.length() == 0) continue;
        text = text.length() > 1 ? text.substring(1) : null;
        String otherText = side.getOtherText(fragment);
        if (otherText == null && text == null) {
          fragments[i] = null;
          nullCount++;
        } else fragments[i] = side.createFragment(text, otherText, fragment.isModified());
        break;
      }
    }
    if (nullCount == 0) return fragments;
    DiffFragment[] result = new DiffFragment[fragments.length - nullCount];
    int dstIndex = 0;
    for (int i = 0; i < fragments.length; i++) {
      DiffFragment fragment = fragments[i];
      if (fragment == null) continue;
      result[dstIndex] = fragment;
      dstIndex++;
    }
    return result;
View Full Code Here

  }

  private static DiffFragment[] transformHeadInsert(DiffFragment[] fragments, FragmentSide side) {
    // transforms {abc}abcd into a{bca}bcd
    if (fragments.length >= 2) {
      DiffFragment first = fragments[0];
      DiffFragment second = fragments[1];
      if (first == null || second == null) {
        return fragments;
      }
      if (side.getText(first) != null) {
        return fragments;
      }
      String rightText = side.getOtherText(first);
      String secondText = side.getText(second);
      if (!Comparing.equal(side.getOtherText(second), secondText)) {
        return fragments;
      }
      if (secondText.charAt(0) == rightText.charAt(0)) {
        List<DiffFragment> result = new ArrayList<DiffFragment>();
        result.add(side.createFragment(rightText.substring(0, 1), rightText.substring(0, 1), false));
        result.add(side.createFragment(null, rightText.substring(1) + secondText.substring(0, 1), true));
        result.add(side.createFragment(secondText.substring(1), secondText.substring(1), second.isModified()));
        result.addAll(Arrays.asList(fragments).subList(2, fragments.length));
        return result.toArray(new DiffFragment[result.size()]);
      }
    }
    return fragments;
View Full Code Here

        }
        if (StringUtil.startsWithChar(text2, '\n')) {
          newLine2 = "\n";
          text2 = text2.substring(1);
        }
        collector.add(new DiffFragment(newLine1, newLine2));
      }
      String spaces1 = leadingSpaces(text1);
      String spaces2 = leadingSpaces(text2);
      if (spaces1.length() == 0 && spaces2.length() == 0) {
        DiffFragment trailing = myComparisonPolicy.createFragment(text1, text2);
        collector.add(trailing);
        return;
      }
      collector.addAll(myDiffPolicy.buildFragments(spaces1, spaces2));
      DiffFragment textFragment = myComparisonPolicy.createFragment(text1.substring(spaces1.length(), text1.length()),
                                                          text2.substring(spaces2.length(), text2.length()));
      collector.add(textFragment);
    }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.diff.ex.DiffFragment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.