本文整理汇总了Java中com.intellij.openapi.diff.ex.DiffFragment类的典型用法代码示例。如果您正苦于以下问题:Java DiffFragment类的具体用法?Java DiffFragment怎么用?Java DiffFragment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiffFragment类属于com.intellij.openapi.diff.ex包,在下文中一共展示了DiffFragment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildChanges
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
private ArrayList<Change> buildChanges() throws FilesTooBigForDiffException {
Document base = getDocument(FragmentSide.SIDE1);
DiffString[] baseLines = DiffUtil.convertToLines(base.getText());
Document version = getDocument(FragmentSide.SIDE2);
DiffString[] versionLines = DiffUtil.convertToLines(version.getText());
DiffFragment[] fragments = ComparisonPolicy.DEFAULT.buildDiffFragmentsFromLines(baseLines, versionLines);
final ArrayList<Change> result = new ArrayList<Change>();
new DiffFragmentsEnumerator(fragments) {
@Override
protected void process(DiffFragment fragment) {
if (fragment.isEqual()) return;
Context context = getContext();
TextRange range1 = context.createRange(FragmentSide.SIDE1);
TextRange range2 = context.createRange(FragmentSide.SIDE2);
result.add(new SimpleChange(ChangeType.fromDiffFragment(context.getFragment()), range1, range2, ChangeList.this));
}
}.execute();
return result;
}
示例2: testChangedSpaceCorrection
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
public void testChangedSpaceCorrection() throws FilesTooBigForDiffException {
DiffCorrection correction = new DiffCorrection.ChangedSpace(ComparisonPolicy.DEFAULT);
DiffFragment[] fragments = correction.correct(new DiffFragment[]{
new DiffFragment("x", "y"),
new DiffFragment(" ", " "),
new DiffFragment("ab", "ab"),
new DiffFragment(" ", " "),
new DiffFragment(" ", " w o r d"),
new DiffFragment(" ", " w o r d")});
CHECK.compareAll(new DiffFragment[]{
new DiffFragment("x", "y"),
new DiffFragment(null, " "), new DiffFragment(" ", " "),
new DiffFragment("ab", "ab"),
new DiffFragment(" ", " "),
new DiffFragment(" ", " "), new DiffFragment(null, "w o r d"),
new DiffFragment(" ", null), new DiffFragment(" ", " "), new DiffFragment(null, "w o r d")}, fragments);
fragments = correction.correct(new DiffFragment[]{new DiffFragment("\n ", "\n ")});
CHECK.compareAll(new DiffFragment[]{new DiffFragment("\n", "\n"),
new DiffFragment(" ", null), new DiffFragment(" ", " ")}, fragments);
fragments = correction.correct(new DiffFragment[]{new DiffFragment("\n", "\n\n")});
CHECK.compareAll(new DiffFragment[]{new DiffFragment("\n", "\n"), new DiffFragment(null, "\n")}, fragments);
}
示例3: testConcatinateSingleSide
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
public void testConcatinateSingleSide() throws FilesTooBigForDiffException {
DiffCorrection correction = new DiffCorrection.ConcatenateSingleSide();
DiffFragment[] corrected = correction.correct(
new DiffFragment[]{new DiffFragment(null, "a"),
new DiffFragment("b", null),
new DiffFragment("c", "d"),
new DiffFragment(null, "a"),
new DiffFragment("b", null),
new DiffFragment("1", null),
new DiffFragment("x", "x"),
new DiffFragment(null, "a")});
CHECK.compareAll(new DiffFragment[]{new DiffFragment("b", "a"),
new DiffFragment("c", "d"),
new DiffFragment("b1", "a"),
new DiffFragment("x", "x"), new DiffFragment(null, "a")},
corrected);
}
示例4: process
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
@Override
public void process(@NotNull DiffFragment fragment, @NotNull DiffCorrection.FragmentsCollector collector) {
if (fragment.isEqual()) {
collector.add(fragment);
return;
}
if (fragment.isOneSide()) {
FragmentSide side = FragmentSide.chooseSide(fragment);
DiffString text = side.getText(fragment);
if (StringUtil.isEmptyOrSpaces(text)) {
collector.add(side.createFragment(text, DiffString.EMPTY, false));
return;
}
}
collector.add(fragment);
}
示例5: divide
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
public DiffFragment[][] divide(DiffFragment[] lineBlock) {
List2D result = new List2D();
FragmentSide currentSide = null;
boolean isNewLineLast = true;
for (int i = 0; i < lineBlock.length; i++) {
DiffFragment fragment = lineBlock[i];
if (!fragment.isOneSide()) {
if (currentSide != null && isNewLineLast) result.newRow();
isNewLineLast = StringUtil.endsWithChar(fragment.getText1(), '\n') && StringUtil.endsWithChar(fragment.getText2(), '\n');
currentSide = null;
} else {
FragmentSide side = FragmentSide.chooseSide(fragment);
if (currentSide != side) {
if (isNewLineLast) {
result.newRow();
currentSide = side;
} else currentSide = null;
}
isNewLineLast = StringUtil.endsWithChar(side.getText(fragment), '\n');
}
result.add(fragment);
}
return result.toArray();
}
示例6: testSingleSide
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
public void testSingleSide() throws FilesTooBigForDiffException {
DiffCorrection correction = DiffCorrection.Normalize.INSTANCE;
DiffFragment[] corrected = correction.correct(
new DiffFragment[]{new DiffFragment(null, "a"),
new DiffFragment("b", null),
new DiffFragment("c", "d"),
new DiffFragment(null, "a"),
new DiffFragment("b", null),
new DiffFragment("1", null),
new DiffFragment("x", "x"),
new DiffFragment(null, "a")});
CHECK.compareAll(new DiffFragment[]{new DiffFragment("b", "a"),
new DiffFragment("c", "d"),
new DiffFragment("b1", "a"),
new DiffFragment("x", "x"), new DiffFragment(null, "a")},
corrected);
}
示例7: testUniteFormattingOnly
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
public void testUniteFormattingOnly() {
prepareForFragments();
DiffFragment[] first = new DiffFragment[]{DiffFragment.unchanged("123", "abc")};
DiffFragment[] last = new DiffFragment[]{new DiffFragment("qqq", "qqq")};
DiffFragment inline1 = new DiffFragment(" ", " ");
DiffFragment inline2 = DiffFragment.unchanged("xyz", "cba");
DiffFragment inline3 = new DiffFragment(" ", " ");
DiffFragment inline4 = DiffFragment.unchanged("098", "890");
DiffFragment[][] lines = new DiffFragment[][]{
first,
new DiffFragment[]{inline1, inline2},
new DiffFragment[]{inline3, inline4},
last};
lines = Util.uniteFormattingOnly(lines);
CHECK.compareAll(new DiffFragment[][]{
first,
new DiffFragment[]{inline1, inline2, inline3, inline4},
last},
lines
);
}
示例8: findSubFragments
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
private ArrayList<LineFragment> findSubFragments(@NotNull DiffString text1, @NotNull DiffString text2) throws FilesTooBigForDiffException {
DiffFragment[] fragments = new ByWord(myComparisonPolicy).buildFragments(text1, text2);
fragments = DiffCorrection.ConnectSingleSideToChange.INSTANCE.correct(fragments);
fragments = UniteSameType.INSTANCE.correct(fragments);
fragments = PreferWholeLines.INSTANCE.correct(fragments);
fragments = UniteSameType.INSTANCE.correct(fragments);
DiffFragment[][] lines = Util.splitByUnchangedLines(fragments);
lines = Util.uniteFormattingOnly(lines);
LineFragmentsCollector collector = new LineFragmentsCollector();
for (DiffFragment[] line : lines) {
DiffFragment[][] subLines = LineBlockDivider.SINGLE_SIDE.divide(line);
subLines = Util.uniteFormattingOnly(subLines);
for (DiffFragment[] subLineFragments : subLines) {
LineFragment subLine = collector.addDiffFragment(Util.concatenate(subLineFragments));
if (!subLine.isOneSide()) {
subLine.setChildren(processInlineFragments(subLineFragments));
}
}
}
return collector.getFragments();
}
示例9: covertSequentialOneSideToChange
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
@NotNull
private static DiffFragment[] covertSequentialOneSideToChange(@NotNull DiffFragment[] fragments) {
if (fragments.length < 2) return fragments;
DiffCorrection.FragmentsCollector collector = new DiffCorrection.FragmentsCollector();
// DiffFragment previous = fragments[0];
DiffFragment previous = null;
for (int i = 0; i < fragments.length; i++) {
DiffFragment fragment = fragments[i];
if (fragment.isOneSide()) {
if (previous == null) previous = fragment;
else {
FragmentSide side = FragmentSide.chooseSide(fragment);
DiffString previousText = side.getText(previous);
if (previousText == null) previousText = DiffString.EMPTY;
previous = side.createFragment(DiffString.concatenateNullable(previousText, side.getText(fragment)),
side.getOtherText(previous), true);
}
} else {
if (previous != null) collector.add(previous);
previous = null;
collector.add(fragment);
}
}
if (previous != null) collector.add(previous);
return collector.toArray();
}
示例10: change
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
private void change(@NotNull TextRange range1, @NotNull TextRange range2) {
LOG.debug("DiffFragmentBuilder.change(" + range1 + "," + range2 + ")");
DiffString text1 = null, text2 = null;
int start1 = range1.getStartOffset();
int end1 = range1.getEndOffset();
int start2 = range2.getStartOffset();
int end2 = range2.getEndOffset();
if (myLastLine1 < start1) {
text1 = concatenate(mySource1, myLastLine1, start1 - 1);
}
if (myLastLine2 < start2) {
text2 = concatenate(mySource2, myLastLine2, start2 - 1);
}
if (text1 != null || text2 != null) {
myData.add(DiffFragment.unchanged(text1, text2));
}
myData.add(new DiffFragment(concatenate(mySource1, start1, end1),
concatenate(mySource2, start2, end2)));
myLastLine1 = end1 + 1;
myLastLine2 = end2 + 1;
}
示例11: append
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
private void append(int line, @NotNull TextRange range) {
LOG.debug("DiffFragmentBuilder.append(" + line + "," + range + "), modified:");
DiffString text1 = null;
DiffString text2 = null;
int start = range.getStartOffset();
int end = range.getEndOffset();
if (myLastLine1 <= line) {
text1 = concatenate(mySource1, myLastLine1, line);
}
if (myLastLine2 < start) {
text2 = concatenate(mySource2, myLastLine2, start - 1);
}
if (text1 != null || text2 != null) {
myData.add(DiffFragment.unchanged(text1, text2));
}
myData.add(new DiffFragment(null, concatenate(mySource2, start, end)));
myLastLine1 = line + 1;
myLastLine2 = end + 1;
}
示例12: addPostfixes
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
private void addPostfixes() throws FilesTooBigForDiffException {
DiffString postfix1 = myVersion1.getCurrentWordPostfixAndOneMore();
DiffString postfix2 = myVersion2.getCurrentWordPostfixAndOneMore();
int length1 = postfix1.length();
int length2 = postfix2.length();
DiffFragment wholePostfix = myComparisonPolicy.createFragment(postfix1, postfix2);
if (wholePostfix.isEqual()) {
add(DiffFragment.unchanged(cutLast(postfix1, length1), cutLast(postfix2, length2)));
return;
}
if (length1 > 0 || length2 > 0) {
DiffFragment[] fragments = BY_CHAR.buildFragments(postfix1, postfix2);
DiffFragment firstFragment = fragments[0];
if (firstFragment.isEqual()) {
final DiffString text1 = cutLast(firstFragment.getText1(), length1);
final DiffString text2 = cutLast(firstFragment.getText2(), length2);
add(myComparisonPolicy.createFragment(text1, text2));
//add(firstFragment);
}
}
}
示例13: execute
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
public void execute() {
for (DiffFragment fragment : myFragments) {
myContext.myFragment = fragment;
process(fragment);
DiffString text1 = fragment.getText1();
DiffString text2 = fragment.getText2();
myContext.myStarts[0] += StringUtil.length(text1);
myContext.myStarts[1] += StringUtil.length(text2);
myContext.myLines[0] += countLines(text1);
myContext.myLines[1] += countLines(text2);
}
}
示例14: processText
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
@NotNull
private static List<MergeFragment> processText(@NotNull String leftText,
@NotNull String baseText,
@NotNull String rightText,
@NotNull ContextLogger logger) throws FilesTooBigForDiffException {
DiffFragment[] leftFragments = DiffPolicy.DEFAULT_LINES.buildFragments(DiffString.create(baseText), DiffString.create(leftText));
DiffFragment[] rightFragments = DiffPolicy.DEFAULT_LINES.buildFragments(DiffString.create(baseText), DiffString.create(rightText));
int[] leftOffsets = {0, 0};
int[] rightOffsets = {0, 0};
int leftIndex = 0;
int rightIndex = 0;
MergeBuilder builder = new MergeBuilder(logger);
while (leftIndex < leftFragments.length || rightIndex < rightFragments.length) {
FragmentSide side;
TextRange[] equalRanges = new TextRange[2];
if (leftOffsets[0] < rightOffsets[0] && leftIndex < leftFragments.length) {
side = FragmentSide.SIDE1;
getEqualRanges(leftFragments[leftIndex], leftOffsets, equalRanges);
leftIndex++;
} else if (rightIndex < rightFragments.length) {
side = FragmentSide.SIDE2;
getEqualRanges(rightFragments[rightIndex], rightOffsets, equalRanges);
rightIndex++;
} else break;
if (equalRanges[0] != null && equalRanges[1] != null) builder.add(equalRanges[0], equalRanges[1], side);
else logger.assertTrue(equalRanges[0] == null && equalRanges[1] == null);
}
return builder.finish(leftText.length(), baseText.length(), rightText.length());
}
示例15: getEqualRanges
import com.intellij.openapi.diff.ex.DiffFragment; //导入依赖的package包/类
private static void getEqualRanges(@NotNull DiffFragment fragment, @NotNull int[] leftOffsets, @NotNull TextRange[] equalRanges) {
int baseLength = getTextLength(fragment.getText1());
int versionLength = getTextLength(fragment.getText2());
if (fragment.isEqual()) {
equalRanges[0] = new TextRange(leftOffsets[0], leftOffsets[0] + baseLength);
equalRanges[1] = new TextRange(leftOffsets[1], leftOffsets[1] + versionLength);
} else {
equalRanges[0] = null;
equalRanges[1] = null;
}
leftOffsets[0] += baseLength;
leftOffsets[1] += versionLength;
}