@NotNull public static List<FilePatch> buildPatch(final Project project, final Collection<Change> changes, final String basePath, final boolean reversePatch, final boolean includeBaseText) throws VcsException { final Collection<BeforeAfter<AirContentRevision>> revisions; if (project != null) { revisions = revisionsConvertor(project, new ArrayList<Change>(changes)); } else { revisions = new ArrayList<BeforeAfter<AirContentRevision>>(changes.size()); for (Change change : changes) { revisions.add(new BeforeAfter<AirContentRevision>(convertRevisionToAir(change.getBeforeRevision()), convertRevisionToAir(change.getAfterRevision()))); } } return TextPatchBuilder.buildPatch(revisions, basePath, reversePatch, SystemInfo.isFileSystemCaseSensitive, new Runnable() { public void run() { ProgressManager.checkCanceled(); } }, includeBaseText); }
private BeforeAfter<Integer> getEditorLines() { final Editor editor = ((DiffPanelImpl) getCurrentPanel()).getEditor1(); Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); final int offset = editor.getScrollingModel().getVerticalScrollOffset(); int leftPixels = offset % editor.getLineHeight(); final Point start = visibleArea.getLocation(); final LogicalPosition startLp = editor.xyToLogicalPosition(start); final Point location = new Point(start.x + visibleArea.width, start.y + visibleArea.height); final LogicalPosition lp = editor.xyToLogicalPosition(location); int curStartLine = startLp.line == editor.getDocument().getLineCount() - 1 ? startLp.line : startLp.line + 1; int cutEndLine = lp.line == 0 ? 0 : lp.line - 1; boolean commonPartOk = leftPixels == 0 || startLp.line == lp.line; return new BeforeAfter<Integer>(commonPartOk && EditorUtil.getSoftWrapCountAfterLineStart(editor, startLp) == 0 ? startLp.line : curStartLine, commonPartOk && EditorUtil.getSoftWrapCountAfterLineStart(editor, lp) == 0 ? lp.line : cutEndLine); }
public PreparedFragmentedContent(final Project project, final FragmentedContent fragmentedContent, final String fileName, final FileType fileType, VcsRevisionNumber beforeNumber, VcsRevisionNumber afterNumber, FilePath path, VirtualFile file) { myFile = file; myProject = project; myFragmentedContent = fragmentedContent; myFileName = fileName; myFileType = fileType; myBeforeNumber = beforeNumber; myAfterNumber = afterNumber; myFilePath = path; oldConvertor = new LineNumberConvertor(); newConvertor = new LineNumberConvertor(); sbOld = new StringBuilder(); sbNew = new StringBuilder(); myBeforeFragments = new ArrayList<TextRange>(fragmentedContent.getSize()); myAfterFragments = new ArrayList<TextRange>(fragmentedContent.getSize()); myLineRanges = new ArrayList<BeforeAfter<Integer>>(); fromFragmentedContent(fragmentedContent); }
private void setHighlighters(final Document oldDocument, final Document document, List<BeforeAfter<TextRange>> ranges, FragmentedContent fragmentedContent) { EditorHighlighter highlighter = createHighlighter(fragmentedContent.getFileTypeBefore(), fragmentedContent.getFileBefore(), fragmentedContent.getFileAfter(), myProject).createHighlighter(); highlighter.setEditor(new LightHighlighterClient(oldDocument, myProject)); highlighter.setText(oldDocument.getText()); HighlighterIterator iterator = highlighter.createIterator(ranges.get(0).getBefore().getStartOffset()); FragmentedEditorHighlighter beforeHighlighter = new FragmentedEditorHighlighter(iterator, getBeforeFragments(), 1, true); setBeforeHighlighter(beforeHighlighter); EditorHighlighter highlighter1 = createHighlighter(fragmentedContent.getFileTypeAfter(), fragmentedContent.getFileAfter(), fragmentedContent.getFileBefore(), myProject).createHighlighter(); highlighter1.setEditor(new LightHighlighterClient(document, myProject)); highlighter1.setText(document.getText()); HighlighterIterator iterator1 = highlighter1.createIterator(ranges.get(0).getAfter().getStartOffset()); FragmentedEditorHighlighter afterHighlighter = new FragmentedEditorHighlighter(iterator1, getAfterFragments(), 1, true); setAfterHighlighter(afterHighlighter); }
public boolean step(final ChangeListsIndexes was, final ChangeListsIndexes became) { List<BaseRevision> wasAffected = was.getAffectedFilesUnderVcs(); if (! myInitialized) { sendPlus(wasAffected); myInitialized = true; return true; //+- } final Set<BaseRevision> toRemove = new HashSet<BaseRevision>(); final Set<BaseRevision> toAdd = new HashSet<BaseRevision>(); final Set<BeforeAfter<BaseRevision>> toModify = new HashSet<BeforeAfter<BaseRevision>>(); was.getDelta(became, toRemove, toAdd, toModify); for (BaseRevision pair : toRemove) { myDeltaListener.minus(pair); } sendPlus(toAdd); for (BeforeAfter<BaseRevision> beforeAfter : toModify) { myDeltaListener.modify(beforeAfter.getBefore(), beforeAfter.getAfter()); } return ! toRemove.isEmpty() || ! toAdd.isEmpty(); }
public PreparedFragmentedContent getRanges(Change change) throws VcsException { FilePath filePath = ChangesUtil.getFilePath(change); final RangesCalculator calculator = new RangesCalculator(); calculator.execute(change, filePath, myRangesCache, LineStatusTrackerManager.getInstance(myProject)); final VcsException exception = calculator.getException(); if (exception != null) { LOG.info(exception); throw exception; } List<BeforeAfter<TextRange>> ranges = calculator.getRanges(); if (ranges == null || ranges.isEmpty()) return null; FragmentedContent fragmentedContent = new FragmentedContent(calculator.getOldDocument(), calculator.getDocument(), ranges, change); VirtualFile file = filePath.getVirtualFile(); if (file == null) { file = LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath.getPath()); } return new PreparedFragmentedContent(myProject, fragmentedContent, filePath.getName(), filePath.getFileType(), change.getBeforeRevision() == null ? null : change.getBeforeRevision().getRevisionNumber(), change.getAfterRevision() == null ? null : change.getAfterRevision().getRevisionNumber(), filePath, file); }
private SplitHunk createWithAllContextCopy(final SplitHunk hunk) { final SplitHunk copy = new SplitHunk(hunk.getStartLineBefore(), new ArrayList<BeforeAfter<List<String>>>(hunk.getPatchSteps()), new ArrayList<String>(), new ArrayList<String>()); final List<BeforeAfter<List<String>>> steps = copy.getPatchSteps(); final BeforeAfter<List<String>> first = steps.get(0); final BeforeAfter<List<String>> last = steps.get(steps.size() - 1); final BeforeAfter<List<String>> firstCopy = copyBeforeAfter(first); steps.set(0, firstCopy); firstCopy.getBefore().addAll(0, hunk.getContextBefore()); firstCopy.getAfter().addAll(0, hunk.getContextBefore()); if (first == last) { firstCopy.getBefore().addAll(hunk.getContextAfter()); firstCopy.getAfter().addAll(hunk.getContextAfter()); } else { final BeforeAfter<List<String>> lastCopy = copyBeforeAfter(last); lastCopy.getBefore().addAll(hunk.getContextAfter()); lastCopy.getAfter().addAll(hunk.getContextAfter()); } return copy; }
private FragmentResult checkFragmented(final int lineInTheMiddle, final int offsetInStep, final BeforeAfter<List<String>> step, final boolean inBefore) { final List<String> lines = inBefore ? step.getBefore() : step.getAfter(); final List<String> start = lines.subList(0, offsetInStep); int startDistance = 0; if (! start.isEmpty()) { if (lineInTheMiddle - 1 < 0) { startDistance = start.size(); } else { startDistance = getDistanceBack(lineInTheMiddle - 1, start); } } final List<String> end = lines.subList(offsetInStep, lines.size()); int endDistance = 0; if (! end.isEmpty()) { endDistance = getDistance(lineInTheMiddle, end); } final FragmentResult fragmentResult = new FragmentResult(lineInTheMiddle - (start.size() - startDistance), lineInTheMiddle + (end.size() - endDistance) - 1, !inBefore); fragmentResult.addDistance(startDistance + endDistance); fragmentResult.setStartAtEdge(startDistance == 0); fragmentResult.setEndAtEdge(endDistance == 0); return fragmentResult; }
public void cutSameTail() { final BeforeAfter<List<String>> lastStep = myPatchSteps.get(myPatchSteps.size() - 1); final List<String> before = lastStep.getBefore(); final List<String> after = lastStep.getAfter(); int cntBefore = before.size() - 1; int cntAfter = after.size() - 1; for (; cntBefore >= 0 && cntAfter > 0; cntBefore--, cntAfter--) { if (! before.get(cntBefore).equals(after.get(cntAfter))) break; } // typically only 1 line int cutSame = before.size() - 1 - cntBefore; for (int i = 0; i < cutSame; i++) { before.remove(before.size() - 1); after.remove(after.size() - 1); } }
public static List<SplitHunk> read(final PatchHunk hunk) { final List<SplitHunk> result = new ArrayList<SplitHunk>(); final List<PatchLine> lines = hunk.getLines(); int i = 0; List<String> contextBefore = new ArrayList<String>(); int newSize = 0; while (i < lines.size()) { final int inheritedContext = contextBefore.size(); final List<String> contextAfter = new ArrayList<String>(); final List<BeforeAfter<List<String>>> steps = new ArrayList<BeforeAfter<List<String>>>(); final int endIdx = readOne(lines, contextBefore, contextAfter, steps, i); result.add(new SplitHunk(hunk.getStartLineBefore() + i - inheritedContext - newSize, steps, contextAfter, contextBefore)); for (BeforeAfter<List<String>> step : steps) { newSize += step.getAfter().size(); } i = endIdx; if (i < lines.size()) { contextBefore = new ArrayList<String>(); contextBefore.addAll(contextAfter); } } return result; }
@Override protected JPanel dataToPresentation(Object o) { final BeforeAfter<BeforeAfter<ConflictSidePresentation>> ba = (BeforeAfter<BeforeAfter<ConflictSidePresentation>>) o; final JPanel wrapper = new JPanel(new BorderLayout()); final JPanel main = new JPanel(new GridBagLayout()); final GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0); final String pathComment = myCommittedRevision == null ? "" : " (current: " + myChange.getBeforeRevision().getRevisionNumber().asString() + ", committed: " + myCommittedRevision.asString() + ")"; final JLabel name = new JLabel(myPath.getName() + pathComment); name.setFont(name.getFont().deriveFont(Font.BOLD)); gb.insets.top = 5; main.add(name, gb); ++ gb.gridy; gb.insets.top = 10; appendDescription(myChange.getBeforeDescription(), main, gb, ba.getBefore(), myPath.isDirectory()); appendDescription(myChange.getAfterDescription(), main, gb, ba.getAfter(), myPath.isDirectory()); wrapper.add(main, BorderLayout.NORTH); return wrapper; }
private void appendDescription(TreeConflictDescription description, JPanel main, GridBagConstraints gb, BeforeAfter<ConflictSidePresentation> ba, boolean directory) { if (description == null) return; JLabel descriptionLbl = new JLabel(description.toPresentableString()); descriptionLbl.setForeground(JBColor.RED); main.add(descriptionLbl, gb); ++ gb.gridy; //buttons gb.insets.top = 0; addResolveButtons(description, main, gb); addSide(main, gb, ba.getBefore(), description.getSourceLeftVersion(), "Left", directory); addSide(main, gb, ba.getAfter(), description.getSourceRightVersion(), "Right", directory); }
public void nextPanel(final BeforeAfter<ShiftedSimpleContent> diff, final DiffPanel diffPanel) { final Editor editor1 = ((DiffPanelImpl)diffPanel).getEditor1(); myLeftModels.add(editor1.getScrollingModel()); final Editor editor2 = ((DiffPanelImpl)diffPanel).getEditor2(); myRightModels.add(editor2.getScrollingModel()); if (myEditor == null) { myEditor = editor1; } myLeftEditors.add(editor1); myRightEditors.add(editor2); ((EditorEx) editor1).setHorizontalScrollbarVisible(false); ((EditorEx) editor1).setVerticalScrollbarVisible(false); ((EditorEx) editor1).getScrollPane().setWheelScrollingEnabled(false); ((EditorEx) editor2).setHorizontalScrollbarVisible(false); ((EditorEx) editor2).setVerticalScrollbarVisible(false); ((EditorEx) editor2).getScrollPane().setWheelScrollingEnabled(false); }
private BeforeAfter<Integer> getEditorLines() { final Editor editor = ((DiffPanelImpl) getCurrentPanel()).getEditor1(); Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); final int offset = editor.getScrollingModel().getVerticalScrollOffset(); int leftPixels = offset % editor.getLineHeight(); final Point start = visibleArea.getLocation(); final LogicalPosition startLp = editor.xyToLogicalPosition(start); final Point location = new Point(start.x + visibleArea.width, start.y + visibleArea.height); final LogicalPosition lp = editor.xyToLogicalPosition(location); int curStartLine = startLp.line == (editor.getDocument().getLineCount() - 1) ? startLp.line : (startLp.line + 1); int cutEndLine = lp.line == 0 ? 0 : lp.line - 1; boolean commonPartOk = leftPixels == 0 || startLp.line == lp.line; return new BeforeAfter<Integer>(commonPartOk && startLp.softWrapLinesOnCurrentLogicalLine == 0 ? startLp.line : curStartLine, commonPartOk && lp.softWrapLinesOnCurrentLogicalLine == 0 ? lp.line : cutEndLine); /*if (leftPixels == 0 || startLp.line == lp.line) { return new BeforeAfter<Integer>(startLp.line, lp.line); } else { return new BeforeAfter<Integer>(curStartLine, cutEndLine); }*/ }
private void setHighlighters(final Document oldDocument, final Document document, List<BeforeAfter<TextRange>> ranges) { EditorHighlighterFactory editorHighlighterFactory = EditorHighlighterFactory.getInstance(); final SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(myFileType, myProject, null); final EditorHighlighter highlighter = editorHighlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme()); highlighter.setEditor(new LightHighlighterClient(oldDocument, myProject)); highlighter.setText(oldDocument.getText()); HighlighterIterator iterator = highlighter.createIterator(ranges.get(0).getBefore().getStartOffset()); FragmentedEditorHighlighter beforeHighlighter = new FragmentedEditorHighlighter(iterator, getBeforeFragments(), 1, true); setBeforeHighlighter(beforeHighlighter); final EditorHighlighter highlighter1 = editorHighlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme()); highlighter1.setEditor(new LightHighlighterClient(document, myProject)); highlighter1.setText(document.getText()); HighlighterIterator iterator1 = highlighter1.createIterator(ranges.get(0).getAfter().getStartOffset()); FragmentedEditorHighlighter afterHighlighter = new FragmentedEditorHighlighter(iterator1, getAfterFragments(), 1, true); setAfterHighlighter(afterHighlighter); }
private void appendDescription(SVNTreeConflictDescription description, JPanel main, GridBagConstraints gb, BeforeAfter<ConflictSidePresentation> ba, boolean directory) { if (description == null) return; JLabel descriptionLbl = new JLabel(SVNTreeConflictUtil.getHumanReadableConflictDescription(description)); descriptionLbl.setForeground(Color.red); main.add(descriptionLbl, gb); ++ gb.gridy; //buttons gb.insets.top = 0; addResolveButtons(description, main, gb); addSide(main, gb, ba.getBefore(), description.getSourceLeftVersion(), "Left", directory); addSide(main, gb, ba.getAfter(), description.getSourceRightVersion(), "Right", directory); }
@Nonnull public static List<FilePatch> buildPatch(final Project project, final Collection<Change> changes, final String basePath, final boolean reversePatch, final boolean includeBaseText) throws VcsException { final Collection<BeforeAfter<AirContentRevision>> revisions; if (project != null) { revisions = revisionsConvertor(project, new ArrayList<Change>(changes)); } else { revisions = new ArrayList<BeforeAfter<AirContentRevision>>(changes.size()); for (Change change : changes) { revisions.add(new BeforeAfter<AirContentRevision>(convertRevisionToAir(change.getBeforeRevision()), convertRevisionToAir(change.getAfterRevision()))); } } return TextPatchBuilder.buildPatch(revisions, basePath, reversePatch, SystemInfo.isFileSystemCaseSensitive, new Runnable() { @Override public void run() { ProgressManager.checkCanceled(); } }, includeBaseText); }
public AppliedSplitPatchHunk(@Nonnull GenericPatchApplier.SplitHunk splitHunk, int startLineApplied, int endLineApplied, @Nonnull HunkStatus status) { myStatus = status; myAppliedToLinesStart = startLineApplied; myAppliedToLinesEnd = endLineApplied; myStartLineBefore = splitHunk.getStartLineBefore(); myStartLineAfter = splitHunk.getStartLineAfter(); myContextBefore = splitHunk.getContextBefore(); myContextAfter = splitHunk.getContextAfter(); myDeletedLines = new ArrayList<>(); myInsertedLines = new ArrayList<>(); for (BeforeAfter<List<String>> step : splitHunk.getPatchSteps()) { myDeletedLines.addAll(step.getBefore()); myInsertedLines.addAll(step.getAfter()); } }
public boolean step(final ChangeListsIndexes was, final ChangeListsIndexes became) { List<BaseRevision> wasAffected = was.getAffectedFilesUnderVcs(); if (! myInitialized) { sendPlus(wasAffected); myInitialized = true; return true; //+- } final Set<BaseRevision> toRemove = new HashSet<>(); final Set<BaseRevision> toAdd = new HashSet<>(); final Set<BeforeAfter<BaseRevision>> toModify = new HashSet<>(); was.getDelta(became, toRemove, toAdd, toModify); for (BaseRevision pair : toRemove) { myDeltaListener.minus(pair); } sendPlus(toAdd); for (BeforeAfter<BaseRevision> beforeAfter : toModify) { myDeltaListener.modify(beforeAfter.getBefore(), beforeAfter.getAfter()); } return ! toRemove.isEmpty() || ! toAdd.isEmpty(); }
public void setRanges(List<BeforeAfter<Integer>> ranges) { myRanges = new ArrayList<BeforeAfter<Integer>>(); if (!ranges.isEmpty()) { if (ranges.get(0).getAfter() != 0 && ranges.get(0).getBefore() != 0) { myRanges.add(new BeforeAfter<Integer>(0, 0)); } } myRanges.addAll(ranges); }
@NotNull @Override public DiffFragment[] buildFragments(@NotNull DiffString text1, @NotNull DiffString text2) throws FilesTooBigForDiffException { final List<DiffFragment> fragments = new ArrayList<DiffFragment>(); for (int i = 0; i < myRanges.size(); i++) { final BeforeAfter<TextRange> range = myRanges.get(i); fragments.addAll(Arrays.asList(myDelegate.buildFragments( text1.substring(range.getBefore().getStartOffset(), range.getBefore().getEndOffset()).copy(), text2.substring(range.getAfter().getStartOffset(), range.getAfter().getEndOffset()).copy()))); } return fragments.toArray(new DiffFragment[fragments.size()]); }
public static List<FilePatch> buildPatch(final Collection<BeforeAfter<AirContentRevision>> changes, final String basePath, final boolean reversePatch, final boolean isCaseSensitive, @Nullable final Runnable cancelChecker, final boolean includeBaseText) throws VcsException { final TextPatchBuilder builder = new TextPatchBuilder(basePath, reversePatch, isCaseSensitive, cancelChecker, includeBaseText); return builder.build(changes); }
public static List<BeforeAfter<AirContentRevision>> revisionsConvertor(final Project project, final List<Change> changes) throws VcsException { final List<BeforeAfter<AirContentRevision>> result = new ArrayList<BeforeAfter<AirContentRevision>>(changes.size()); final Convertor<Change, FilePath> beforePrefferingConvertor = new Convertor<Change, FilePath>() { public FilePath convert(Change o) { final FilePath before = ChangesUtil.getBeforePath(o); return before == null ? ChangesUtil.getAfterPath(o) : before; } }; final MultiMap<VcsRoot,Change> byRoots = new SortByVcsRoots<Change>(project, beforePrefferingConvertor).sort(changes); for (VcsRoot root : byRoots.keySet()) { final Collection<Change> rootChanges = byRoots.get(root); if (root.getVcs() == null || root.getVcs().getOutgoingChangesProvider() == null) { addConvertChanges(rootChanges, result); continue; } final VcsOutgoingChangesProvider<?> provider = root.getVcs().getOutgoingChangesProvider(); final Collection<Change> basedOnLocal = provider.filterLocalChangesBasedOnLocalCommits(rootChanges, root.getPath()); rootChanges.removeAll(basedOnLocal); addConvertChanges(rootChanges, result); for (Change change : basedOnLocal) { // dates are here instead of numbers result.add(new BeforeAfter<AirContentRevision>(convertRevision(change.getBeforeRevision(), provider), convertRevision(change.getAfterRevision(), provider))); } } return result; }
public static BeforeAfter<DiffContent> createBinaryDiffContents(final Project project, final Change change) throws VcsException { final FilePath filePath = ChangesUtil.getFilePath(change); try { return new BeforeAfter<DiffContent>(createBinaryFileContent(project, change.getBeforeRevision(), filePath.getName()), createBinaryFileContent(project, change.getAfterRevision(), filePath.getName())); } catch (IOException e) { throw new VcsException(e); } }
@Override protected ValueWithVcsException<List<BeforeAfter<DiffContent>>> loadImpl() throws VcsException { myChange = myChangeListManager.getChange(myFilePath); if (myChange == null) { return null; } return new ValueWithVcsException<List<BeforeAfter<DiffContent>>>() { @Override protected List<BeforeAfter<DiffContent>> computeImpl() throws VcsException { return myRequestFromChange.createRequestForChange(myChange, 0); } }; }
@Override protected JPanel dataToPresentation(ValueWithVcsException<List<BeforeAfter<DiffContent>>> value) { if (value == null) return noDifferences(); final List<BeforeAfter<DiffContent>> contents; try { contents = value.get(); if (contents == null) throw new VcsException("Can not load content"); if (isUnknownType(contents)) { return UIVcsUtil.errorPanel(DiffBundle.message("diff.can.not.show.unknown"), false); } if (isEmpty(contents)) throw new VcsException("Can not load content"); } catch (VcsException e) { return UIVcsUtil.errorPanel(e.getMessage(), true); } if (contents.isEmpty()) return noDifferences(); assert contents.size() == 1; myPanel.setContents(contents.get(0).getBefore(), contents.get(0).getAfter()); ((DiffPanelImpl)myPanel).getOptions().setRequestFocusOnNewContent(false); final JPanel wholeWrapper = new JPanel(new BorderLayout()); final JPanel topPanel = new JPanel(new BorderLayout()); final JPanel wrapper = new JPanel(); final BoxLayout boxLayout = new BoxLayout(wrapper, BoxLayout.X_AXIS); wrapper.setLayout(boxLayout); final JLabel label = new JLabel(changeDescription(myChange)); label.setBorder(BorderFactory.createEmptyBorder(1,2,0,0)); wrapper.add(label); topPanel.add(wrapper, BorderLayout.CENTER); wholeWrapper.add(topPanel, BorderLayout.NORTH); //wholeWrapper.add(new JBScrollPane(panel.getComponent()), BorderLayout.CENTER); wholeWrapper.add(myPanel.getComponent(), BorderLayout.CENTER); return wholeWrapper; }
private static boolean isUnknownType(List<BeforeAfter<DiffContent>> contents) { for (BeforeAfter<DiffContent> content : contents) { if (DiffUtil.oneIsUnknown(content.getBefore(), content.getAfter())) { return true; } } return false; }
public void recalculate() { oldConvertor = new LineNumberConvertor(); newConvertor = new LineNumberConvertor(); sbOld = new StringBuilder(); sbNew = new StringBuilder(); myBeforeFragments = new ArrayList<TextRange>(myFragmentedContent.getSize()); myAfterFragments = new ArrayList<TextRange>(myFragmentedContent.getSize()); myLineRanges = new ArrayList<BeforeAfter<Integer>>(); checkFileOutdated(); fromFragmentedContent(myFragmentedContent); }
public FragmentedContent(Document before, Document after, List<BeforeAfter<TextRange>> ranges, Change change) { myBefore = before; myAfter = after; myRanges = ranges; final FileStatus fs = change.getFileStatus(); myIsAddition = FileStatus.ADDED.equals(fs); myOneSide = FileStatus.ADDED.equals(fs) || FileStatus.DELETED.equals(fs); if (change.getBeforeRevision() != null) { myFileBefore = change.getBeforeRevision().getFile().getVirtualFile(); myFileTypeBefore = change.getBeforeRevision().getFile().getFileType(); } else { myFileBefore = null; myFileTypeBefore = null; } if (change.getAfterRevision() != null) { myFileAfter = change.getAfterRevision().getFile().getVirtualFile(); myFileTypeAfter = change.getAfterRevision().getFile().getFileType(); } else { myFileAfter = null; myFileTypeAfter = null; } }
@Nullable public List<BeforeAfter<TextRange>> execute() { final List<BeforeAfter<TextRange>> result = new ArrayList<BeforeAfter<TextRange>>(); if (myRanges == null || myRanges.isEmpty()) return Collections.emptyList(); for (Range range : myRanges) { final TextRange before = new TextRange(range.getVcsLine1(), range.getVcsLine2()); final TextRange after = new TextRange(range.getLine1(), range.getLine2()); result.add(new BeforeAfter<TextRange>(before, after)); } return result; }