use of com.intellij.diff.util.IntPair in project intellij-community by JetBrains.
the class VcsSelectionHistoryDialog method getSelectedRevisionsRange.
@NotNull
private IntPair getSelectedRevisionsRange() {
List<VcsFileRevision> selection = myList.getSelectedObjects();
if (selection.isEmpty())
return new IntPair(0, 0);
int startIndex = myRevisions.indexOf(ContainerUtil.getFirstItem(selection));
int endIndex = myRevisions.indexOf(ContainerUtil.getLastItem(selection));
return new IntPair(startIndex, endIndex + 1);
}
use of com.intellij.diff.util.IntPair in project intellij-community by JetBrains.
the class VcsSelectionHistoryDialog method updateDiff.
private void updateDiff() {
if (myIsDisposed || myIsDuringUpdate)
return;
if (myList.getSelectedRowCount() == 0) {
myDiffPanel.setRequest(NoDiffRequest.INSTANCE);
return;
}
int count = myRevisions.size();
IntPair range = getSelectedRevisionsRange();
int revIndex1 = range.val2;
int revIndex2 = range.val1;
if (revIndex1 == count && revIndex2 == count) {
myDiffPanel.setRequest(NoDiffRequest.INSTANCE);
return;
}
BlockData blockData = myBlockLoader.getLoadedData();
DiffContent content1 = createDiffContent(revIndex1, blockData);
DiffContent content2 = createDiffContent(revIndex2, blockData);
String title1 = createDiffContentTitle(revIndex1);
String title2 = createDiffContentTitle(revIndex2);
if (content1 != null && content2 != null) {
myDiffPanel.setRequest(new SimpleDiffRequest(null, content1, content2, title1, title2), new IntPair(revIndex1, revIndex2));
return;
}
if (blockData.isLoading()) {
myDiffPanel.setRequest(new LoadingDiffRequest());
} else {
myDiffPanel.setRequest(new MessageDiffRequest(canNoLoadMessage(blockData.getException())));
}
}
use of com.intellij.diff.util.IntPair in project intellij-community by JetBrains.
the class VcsSelectionHistoryDialog method updateRevisionsList.
private void updateRevisionsList() {
if (myIsDuringUpdate)
return;
try {
myIsDuringUpdate = true;
List<VcsFileRevision> newItems;
if (myChangesOnlyCheckBox.isSelected()) {
newItems = filteredRevisions();
} else {
newItems = myRevisions;
}
IntPair range = getSelectedRevisionsRange();
List<VcsFileRevision> oldSelection = myRevisions.subList(range.val1, range.val2);
myListModel.setItems(newItems);
myList.setSelection(oldSelection);
if (myList.getSelectedRowCount() == 0) {
int index = getNearestVisibleRevision(ContainerUtil.getFirstItem(oldSelection));
myList.getSelectionModel().setSelectionInterval(index, index);
}
} finally {
myIsDuringUpdate = false;
}
updateDiff();
}
use of com.intellij.diff.util.IntPair in project intellij-community by JetBrains.
the class GenericPatchApplier method testForExactMatch.
private boolean testForExactMatch(final SplitHunk splitHunk, final SplitHunk originalHunk) {
final int offset = splitHunk.getContextBefore().size();
final List<BeforeAfter<List<String>>> steps = splitHunk.getPatchSteps();
if (splitHunk.isInsertion()) {
final boolean emptyFile = myLines.isEmpty() || myLines.size() == 1 && myLines.get(0).trim().length() == 0;
if (emptyFile) {
myNotBound.add(splitHunk);
}
return emptyFile;
}
int idx = splitHunk.getStartLineBefore() + offset;
int cnt = 0;
boolean hadAlreadyApplied = false;
for (BeforeAfter<List<String>> step : steps) {
if (myLines.size() <= idx)
return false;
// can occur only in the end
if (step.getBefore().isEmpty())
continue;
final Pair<Integer, Boolean> distance = new FragmentMatcher(idx + cnt, step).find(false);
if (distance.getFirst() > 0) {
return false;
}
// fits!
int length;
if (distance.getSecond()) {
length = step.getBefore().size();
} else {
length = step.getAfter().size();
hadAlreadyApplied = true;
}
cnt += length;
//idx += length - 1;
}
putCutIntoTransformations(new TextRange(idx, idx + cnt - 1), originalHunk, new MyAppliedData(splitHunk.getAfterAll(), hadAlreadyApplied, true, true, ChangeType.REPLACE), new IntPair(originalHunk.getContextBefore().size() - splitHunk.getContextBefore().size(), originalHunk.getContextAfter().size() - splitHunk.getContextAfter().size()));
return true;
}
use of com.intellij.diff.util.IntPair in project intellij-community by JetBrains.
the class GenericPatchApplier method testForPartialContextMatch.
private boolean testForPartialContextMatch(final SplitHunk splitHunkWithExtendedContext, final MismatchSolver mismatchSolver, final int maxWalkFromBinding, @Nullable final SplitHunk originalSplitHunk) {
final List<BeforeAfter<List<String>>> steps = splitHunkWithExtendedContext.getPatchSteps();
final BetterPoint betterPoint = new BetterPoint();
if (splitHunkWithExtendedContext.isInsertion())
return false;
// if it is not just insertion, then in first step will be both parts
final Iterator<FirstLineDescriptor> iterator = mismatchSolver.getStartLineVariationsIterator();
while (iterator.hasNext() && (betterPoint.getPoint() == null || !betterPoint.getPoint().idealFound())) {
final FirstLineDescriptor descriptor = iterator.next();
final Iterator<Integer> matchingIterator = getMatchingIterator(descriptor.getLine(), splitHunkWithExtendedContext.getStartLineBefore() + descriptor.getOffset(), maxWalkFromBinding);
while (matchingIterator.hasNext() && (betterPoint.getPoint() == null || !betterPoint.getPoint().idealFound())) {
final Integer lineNumber = matchingIterator.next();
// go back and forward from point
final List<BeforeAfter<List<String>>> patchSteps = splitHunkWithExtendedContext.getPatchSteps();
final BeforeAfter<List<String>> step = patchSteps.get(descriptor.getStepNumber());
final FragmentResult fragmentResult = checkFragmented(lineNumber, descriptor.getOffsetInStep(), step, descriptor.isIsInBefore());
// we go back - if middle fragment ok
if (descriptor.getStepNumber() > 0 && fragmentResult.isStartAtEdge()) {
// not including step number here
final List<BeforeAfter<List<String>>> list = Collections.unmodifiableList(patchSteps.subList(0, descriptor.getStepNumber()));
int offsetForStart = -descriptor.getOffsetInStep() - 1;
final SequentialStepsChecker backChecker = new SequentialStepsChecker(lineNumber + offsetForStart, false);
backChecker.go(list);
fragmentResult.setContainAlreadyApplied(fragmentResult.isContainAlreadyApplied() || backChecker.isUsesAlreadyApplied());
fragmentResult.setStart(fragmentResult.getStart() - backChecker.getSizeOfFragmentToBeReplaced());
fragmentResult.addDistance(backChecker.getDistance());
fragmentResult.setStartAtEdge(backChecker.getDistance() == 0);
}
if (steps.size() > descriptor.getStepNumber() + 1 && fragmentResult.isEndAtEdge()) {
// forward
final List<BeforeAfter<List<String>>> list = Collections.unmodifiableList(patchSteps.subList(descriptor.getStepNumber() + 1, patchSteps.size()));
if (!list.isEmpty()) {
final SequentialStepsChecker checker = new SequentialStepsChecker(fragmentResult.getEnd() + 1, true);
checker.go(list);
fragmentResult.setContainAlreadyApplied(fragmentResult.isContainAlreadyApplied() || checker.isUsesAlreadyApplied());
fragmentResult.setEnd(fragmentResult.getEnd() + checker.getSizeOfFragmentToBeReplaced());
fragmentResult.addDistance(checker.getDistance());
fragmentResult.setEndAtEdge(checker.getDistance() == 0);
}
}
final TextRange textRangeInOldDocument = new UnfairTextRange(fragmentResult.getStart(), fragmentResult.getEnd());
//if (pointCanBeUsed(textRangeInOldDocument) && (! mismatchSolver.isAllowMismatch() || fragmentResult.getEnd() - fragmentResult.getStart() > 1)) {
if (pointCanBeUsed(textRangeInOldDocument)) {
final int distance = fragmentResult.myDistance;
final int commonPart = fragmentResult.getEnd() - fragmentResult.getStart() + 1;
int contextDistance = 0;
if (distance == 0 || commonPart < 2) {
final int distanceBack = getDistanceBack(fragmentResult.getStart() - 1, splitHunkWithExtendedContext.getContextBefore());
final int distanceInContextAfter = getDistance(fragmentResult.getEnd() + 1, splitHunkWithExtendedContext.getContextAfter());
contextDistance = distanceBack + distanceInContextAfter;
}
betterPoint.feed(new Point(distance, textRangeInOldDocument, fragmentResult.isContainAlreadyApplied(), contextDistance, commonPart));
}
}
}
final Point pointPoint = betterPoint.getPoint();
if (pointPoint == null)
return false;
if (!mismatchSolver.isAllowMismatch()) {
if (pointPoint.getDistance() > 0)
return false;
if (pointPoint.myCommon < 2) {
final int contextCommon = splitHunkWithExtendedContext.getContextBefore().size() + splitHunkWithExtendedContext.getContextAfter().size() - pointPoint.myContextDistance;
if (contextCommon == 0)
return false;
}
}
putCutIntoTransformations(pointPoint.getInOldDocument(), originalSplitHunk, new MyAppliedData(splitHunkWithExtendedContext.getAfterAll(), pointPoint.myUsesAlreadyApplied, false, pointPoint.getDistance() == 0, ChangeType.REPLACE), originalSplitHunk == null ? EMPTY_OFFSET : new IntPair(originalSplitHunk.getContextBefore().size() - splitHunkWithExtendedContext.getContextBefore().size(), originalSplitHunk.getContextAfter().size() - splitHunkWithExtendedContext.getContextAfter().size()));
return true;
}
Aggregations