LineFragment (@NotNull List<? extends LineFragment> oldFragments) { assert !oldFragments.isEmpty(); if (oldFragments.size() == 1) return oldFragments.get(0); LineFragment firstFragment = oldFragments.get(0); LineFragment lastFragment = oldFragments.get(oldFragments.size() - 1); List<DiffFragment> newInnerFragments = new ArrayList<>(); for (LineFragment fragment : oldFragments) { for (DiffFragment innerFragment : extractInnerFragments(fragment)) { int shift1 = fragment.getStartOffset1() - firstFragment.getStartOffset1(); int shift2 = fragment.getStartOffset2() - firstFragment.getStartOffset2(); DiffFragment previousFragment = ContainerUtil.getLastItem(newInnerFragments); if (previousFragment == null || !isAdjoiningInner(previousFragment, innerFragment, shift1, shift2)) { newInnerFragments.add(new DiffFragmentImpl(innerFragment.getStartOffset1() + shift1, innerFragment.getEndOffset1() + shift1, innerFragment.getStartOffset2() + shift2, innerFragment.getEndOffset2() + shift2)); } else { newInnerFragments.remove(newInnerFragments.size() - 1); newInnerFragments.add(new DiffFragmentImpl(previousFragment.getStartOffset1(), innerFragment.getEndOffset1() + shift1, previousFragment.getStartOffset2(), innerFragment.getEndOffset2() + shift2)); } } } return new LineFragmentImpl(firstFragment.getStartLine1(), lastFragment.getEndLine1(), firstFragment.getStartLine2(), lastFragment.getEndLine2(), firstFragment.getStartOffset1(), lastFragment.getEndOffset1(), firstFragment.getStartOffset2(), lastFragment.getEndOffset2(), newInnerFragments); }