VCS: patch creation stuff to [util] step 1
authorirengrig <Irina.Chernushina@jetbrains.com>
Thu, 4 Feb 2010 12:33:35 +0000 (15:33 +0300)
committerirengrig <Irina.Chernushina@jetbrains.com>
Thu, 4 Feb 2010 12:33:35 +0000 (15:33 +0300)
31 files changed:
platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/FragmentHighlighterImpl.java [new file with mode: 0644]
platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/DiffMarkup.java
platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/SimpleDiffPanelState.java
platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/LineFragmentsCollector.java
platform/platform-impl/src/com/intellij/openapi/diff/impl/splitter/DividerPoligon.java
platform/platform-impl/src/com/intellij/openapi/diff/impl/splitter/LineBlocks.java
platform/platform-impl/src/com/intellij/openapi/diff/impl/util/TextDiffType.java
platform/platform-resources-en/src/messages/CommonBundle.properties
platform/platform-resources-en/src/messages/DiffBundle.properties
platform/util/src/com/intellij/openapi/diff/LineTokenizer.java [moved from platform/platform-api/src/com/intellij/openapi/diff/LineTokenizer.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/ex/DiffFragment.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffFragment.java with 98% similarity]
platform/util/src/com/intellij/openapi/diff/impl/ComparisonPolicy.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/ComparisonPolicy.java with 96% similarity]
platform/util/src/com/intellij/openapi/diff/impl/DiffFragmentBuilder.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffFragmentBuilder.java with 99% similarity]
platform/util/src/com/intellij/openapi/diff/impl/DiffRange.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffRange.java with 99% similarity]
platform/util/src/com/intellij/openapi/diff/impl/fragments/Fragment.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/Fragment.java with 82% similarity]
platform/util/src/com/intellij/openapi/diff/impl/fragments/FragmentHighlighter.java [new file with mode: 0644]
platform/util/src/com/intellij/openapi/diff/impl/fragments/FragmentList.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/FragmentList.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/impl/fragments/FragmentListImpl.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/FragmentListImpl.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/impl/fragments/InlineFragment.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/InlineFragment.java with 82% similarity]
platform/util/src/com/intellij/openapi/diff/impl/fragments/LineBlock.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/LineBlock.java with 89% similarity]
platform/util/src/com/intellij/openapi/diff/impl/fragments/LineFragment.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/LineFragment.java with 73% similarity]
platform/util/src/com/intellij/openapi/diff/impl/highlighting/BufferedStringList.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/BufferedStringList.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/impl/highlighting/FragmentSide.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentSide.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/impl/highlighting/List2D.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/List2D.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/impl/highlighting/Util.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/Util.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/impl/processing/DiffCorrection.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/DiffCorrection.java with 96% similarity]
platform/util/src/com/intellij/openapi/diff/impl/processing/DiffPolicy.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/DiffPolicy.java with 92% similarity]
platform/util/src/com/intellij/openapi/diff/impl/processing/Formatting.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/Formatting.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/impl/processing/Word.java [moved from platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/Word.java with 100% similarity]
platform/util/src/com/intellij/openapi/diff/impl/util/TextDiffTypeEnum.java [new file with mode: 0644]
platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/PatchBuilder.java

diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/FragmentHighlighterImpl.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/FragmentHighlighterImpl.java
new file mode 100644 (file)
index 0000000..995375b
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.diff.impl.fragments;
+
+import com.intellij.openapi.diff.DiffColors;
+import com.intellij.openapi.diff.actions.MergeOperations;
+import com.intellij.openapi.diff.impl.highlighting.DiffMarkup;
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.editor.colors.TextAttributesKey;
+import com.intellij.openapi.util.TextRange;
+
+import java.util.Iterator;
+
+public class FragmentHighlighterImpl implements FragmentHighlighter {
+  private final DiffMarkup myAppender1;
+  private final DiffMarkup myAppender2;
+  private final boolean myIsLast;
+
+  public FragmentHighlighterImpl(DiffMarkup appender1, DiffMarkup appender2, boolean isLast) {
+    myAppender1 = appender1;
+    myAppender2 = appender2;
+    myIsLast = isLast;
+  }
+
+  public void highlightInline(final InlineFragment fragment) {
+    myAppender1.highlightText(fragment, true);
+    myAppender2.highlightText(fragment, true);
+  }
+
+  public void highlightLine(final LineFragment fragment) {
+    addModifyActions(fragment, myAppender1, myAppender2);
+    final Iterator<Fragment> iterator = fragment.getChildrenIterator();
+    if (iterator == null) {
+      myAppender1.highlightText(fragment, false);
+      myAppender2.highlightText(fragment, false);
+    }
+    else {
+      for (; iterator.hasNext();) {
+        Fragment childFragment = iterator.next();
+        childFragment.highlight(this);
+      }
+    }
+    if (fragment.isEqual() && myIsLast) return;
+    addBottomLine(fragment, myAppender1, fragment.getEndLine1());
+    addBottomLine(fragment, myAppender2, fragment.getEndLine2());
+  }
+
+  private void addModifyActions(final LineFragment fragment, DiffMarkup wrapper, DiffMarkup otherWrapper) {
+    if (fragment.isEqual()) return;
+    if (fragment.isHasLineChildren()) return;
+    TextRange range = fragment.getRange(wrapper.getSide());
+    TextRange otherRange = fragment.getRange(wrapper.getSide().otherSide());
+    Document document = wrapper.getDocument();
+    Document otherDocument = otherWrapper.getDocument();
+    wrapper.addAction(MergeOperations.mostSensible(document, otherDocument, range, otherRange), range.getStartOffset());
+    otherWrapper.addAction(MergeOperations.mostSensible(otherDocument, document, otherRange, range), otherRange.getStartOffset());
+  }
+
+  private void addBottomLine(final Fragment fragment, DiffMarkup appender, int endLine) {
+    if (endLine <= 0) return;
+    TextRange range = fragment.getRange(appender.getSide());
+    appender.addLineMarker(endLine - 1, getRangeType(fragment, range));
+  }
+
+  private TextAttributesKey getRangeType(final Fragment fragment, final TextRange range) {
+    if (range.getLength() == 0) return DiffColors.DIFF_DELETED;
+    return fragment.getType() == null ? null : DiffColors.DIFF_MODIFIED;
+  }
+}
index 40b9ae7176ff9bc31a6387fed8e336414c3ed306..e9f13b7c2a8850f289a282423125d49c07c0dd22 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.openapi.diff.impl.EditorSource;
 import com.intellij.openapi.diff.impl.fragments.Fragment;
 import com.intellij.openapi.diff.impl.util.GutterActionRenderer;
 import com.intellij.openapi.diff.impl.util.TextDiffType;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.colors.TextAttributesKey;
@@ -59,7 +60,9 @@ public abstract class DiffMarkup implements EditorSource {
   }
 
   public void highlightText(Fragment fragment, boolean drawBorder) {
-    TextDiffType type = fragment.getType();
+    final TextDiffTypeEnum diffTypeEnum = fragment.getType();
+    if (diffTypeEnum == null) return;
+    TextDiffType type = TextDiffType.create(diffTypeEnum);
     if (type == null) return;
     TextRange range = fragment.getRange(getSide());
     TextAttributes attributes = type.getTextAttributes(getEditor());
index a03ed667b7872885dcbd289be004ff79e0e12cc6..e57161f990fe7ad2323c7a4d04d57c87e3c4fa97 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.openapi.diff.impl.highlighting;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diff.impl.ComparisonPolicy;
+import com.intellij.openapi.diff.impl.fragments.FragmentHighlighterImpl;
 import com.intellij.openapi.diff.impl.fragments.FragmentList;
 import com.intellij.openapi.diff.impl.fragments.FragmentListImpl;
 import com.intellij.openapi.diff.impl.fragments.LineFragment;
@@ -60,7 +61,8 @@ public class SimpleDiffPanelState<DiffMarkupType extends DiffMarkup> implements
       public void run() {
         for (Iterator<LineFragment> iterator = lines.iterator(); iterator.hasNext();) {
           LineFragment line = iterator.next();
-          line.highlight(myAppender1, myAppender2, !iterator.hasNext());
+          final FragmentHighlighterImpl fragmentHighlighter = new FragmentHighlighterImpl(myAppender1, myAppender2, !iterator.hasNext());
+          line.highlight(fragmentHighlighter);
         }
       }
     });
index 1397bf8ac43ae4ca6c3b9603252cf479d91cc79d..89ccc9a032a9145f99d7180edc8f685aab406c9b 100644 (file)
@@ -17,7 +17,7 @@ package com.intellij.openapi.diff.impl.processing;
 
 import com.intellij.openapi.diff.ex.DiffFragment;
 import com.intellij.openapi.diff.impl.fragments.LineFragment;
-import com.intellij.openapi.diff.impl.util.TextDiffType;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.text.StringUtil;
 
@@ -30,7 +30,7 @@ class LineFragmentsCollector {
   private int myOffset1 = 0;
   private int myOffset2 = 0;
 
-  private LineFragment addFragment(TextDiffType type, String text1, String text2) {
+  private LineFragment addFragment(TextDiffTypeEnum type, String text1, String text2) {
     int lines1 = countLines(text1);
     int lines2 = countLines(text2);
     int endOffset1 = myOffset1 + getLength(text1);
@@ -65,11 +65,11 @@ class LineFragmentsCollector {
     return myLineFragments;
   }
 
-  static TextDiffType getType(DiffFragment fragment) {
-    TextDiffType type;
-    if (fragment.getText1() == null) type = TextDiffType.INSERT;
-    else if (fragment.getText2() == null) type = TextDiffType.DELETED;
-    else if (fragment.isModified()) type = TextDiffType.CHANGED;
+  static TextDiffTypeEnum getType(DiffFragment fragment) {
+    TextDiffTypeEnum type;
+    if (fragment.getText1() == null) type = TextDiffTypeEnum.INSERT;
+    else if (fragment.getText2() == null) type = TextDiffTypeEnum.DELETED;
+    else if (fragment.isModified()) type = TextDiffTypeEnum.CHANGED;
     else type = null;
     return type;
   }
index 5669d1082cea47f1b4583e26035fb32c6a754de1..b69ce5e457f86754efdf331e62b04a2935d17cfa 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.openapi.diff.impl.splitter;
 import com.intellij.openapi.diff.impl.EditingSides;
 import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
 import com.intellij.openapi.diff.impl.util.TextDiffType;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.LogicalPosition;
 import com.intellij.openapi.util.Comparing;
@@ -91,7 +92,9 @@ class DividerPoligon {
     ArrayList<DividerPoligon> poligons = new ArrayList<DividerPoligon>();
     for (int i = indecies.getStart(); i < indecies.getEnd(); i++) {
       Trapezium trapezium = lineBlocks.getTrapezium(i);
-      TextDiffType type = lineBlocks.getType(i);
+      final TextDiffTypeEnum diffTypeEnum = lineBlocks.getType(i);
+      if (diffTypeEnum == null) continue;
+      TextDiffType type = TextDiffType.create(diffTypeEnum);
       if (type == null) continue;
       Color color = type.getPoligonColor(editor1);
       poligons.add(createPoligon(transformations, trapezium, color, left));
index 5bfed8fa38a80582181d1d4c5c4619f8e9f5f29e..be99deef041d6d32e0f048f910b23b38a7efcfb2 100644 (file)
@@ -20,7 +20,7 @@ import com.intellij.openapi.diff.impl.fragments.LineBlock;
 import com.intellij.openapi.diff.impl.fragments.LineFragment;
 import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
 import com.intellij.openapi.diff.impl.incrementalMerge.Change;
-import com.intellij.openapi.diff.impl.util.TextDiffType;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 import com.intellij.util.containers.IntArrayList;
 
 import java.util.ArrayList;
@@ -29,12 +29,12 @@ import java.util.Comparator;
 import java.util.Iterator;
 
 public class LineBlocks {
-  public static final LineBlocks EMPTY = new LineBlocks(SimpleIntervalProvider.EMPTY, new TextDiffType[0]);
+  public static final LineBlocks EMPTY = new LineBlocks(SimpleIntervalProvider.EMPTY, new TextDiffTypeEnum[0]);
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.splitter.LineBlocks");
   private final IntervalsProvider myIntervalsProvider;
-  private final TextDiffType[] myTypes;
+  private final TextDiffTypeEnum[] myTypes;
 
-  private LineBlocks(IntervalsProvider intervalsProvider, TextDiffType[] types) {
+  private LineBlocks(IntervalsProvider intervalsProvider, TextDiffTypeEnum[] types) {
     myIntervalsProvider = intervalsProvider;
     myTypes = types;
   }
@@ -56,7 +56,7 @@ public class LineBlocks {
                          getIntervals(FragmentSide.SIDE2)[index]);
   }
 
-  public TextDiffType getType(int index) {
+  public TextDiffTypeEnum getType(int index) {
     return myTypes[index];
   }
 
@@ -151,7 +151,7 @@ public class LineBlocks {
     Arrays.sort(blocks, LineBlock.COMPARATOR);
     Interval[] intervals1 = new Interval[blocks.length];
     Interval[] intervals2 = new Interval[blocks.length];
-    TextDiffType[] types = new TextDiffType[blocks.length];
+    TextDiffTypeEnum[] types = new TextDiffTypeEnum[blocks.length];
     for (int i = 0; i < blocks.length; i++) {
       LineBlock block = blocks[i];
       intervals1[i] = new Interval(block.getStartingLine1(), block.getModifiedLines1());
@@ -161,14 +161,14 @@ public class LineBlocks {
     return create(intervals1, intervals2, types);
   }
 
-  private static LineBlocks create(Interval[] intervals1, Interval[] intervals2, TextDiffType[] types) {
+  private static LineBlocks create(Interval[] intervals1, Interval[] intervals2, TextDiffTypeEnum[] types) {
     return new LineBlocks(new SimpleIntervalProvider(intervals1, intervals2), types);
   }
 
   public static LineBlocks fromChanges(ArrayList<Change> changes) {
     ArrayList<Interval> intervals1 = new ArrayList<Interval>();
     ArrayList<Interval> intervals2 = new ArrayList<Interval>();
-    ArrayList<TextDiffType> types = new ArrayList<TextDiffType>();
+    ArrayList<TextDiffTypeEnum> types = new ArrayList<TextDiffTypeEnum>();
     //int prevEnd1 = 0;
     //int prevEnd2 = 0;
     for (Iterator<Change> iterator = changes.iterator(); iterator.hasNext();) {
@@ -185,7 +185,7 @@ public class LineBlocks {
       intervals1.add(Interval.fromTo(start1, end1));
       int end2 = change.getChangeSide(FragmentSide.SIDE2).getEndLine();
       intervals2.add(Interval.fromTo(start2, end2));
-      types.add(change.getType().getTypeKey());
+      types.add(change.getType().getTypeKey().getType());
       //prevEnd1 = end1;
       //prevEnd2 = end2;
     }
@@ -197,10 +197,10 @@ public class LineBlocks {
     //}
 
     return create(intervals1.toArray(new Interval[intervals1.size()]),
-                  intervals2.toArray(new Interval[intervals2.size()]), types.toArray(new TextDiffType[types.size()]));
+                  intervals2.toArray(new Interval[intervals2.size()]), types.toArray(new TextDiffTypeEnum[types.size()]));
   }
 
-  public TextDiffType[] getTypes() {
+  public TextDiffTypeEnum[] getTypes() {
     return myTypes;
   }
 
index a29f130cfe8394e598e3fce59ba31f7aab44bc96..a5337169e95194f67b45cda9533a76fe97fe6d79 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2010 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,19 +23,21 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme;
 import com.intellij.openapi.editor.colors.TextAttributesKey;
 import com.intellij.openapi.editor.markup.TextAttributes;
 import com.intellij.util.containers.Convertor;
+import org.jetbrains.annotations.NotNull;
 
 import java.awt.*;
 import java.util.Arrays;
 import java.util.List;
 
 public class TextDiffType implements DiffStatusBar.LegendTypeDescriptor {
-  public static final TextDiffType INSERT = new TextDiffType(DiffBundle.message("diff.type.inserted.name"), DiffColors.DIFF_INSERTED);
-  public static final TextDiffType CHANGED = new TextDiffType(DiffBundle.message("diff.type.changed.name"), DiffColors.DIFF_MODIFIED);
-  public static final TextDiffType DELETED = new TextDiffType(DiffBundle.message("diff.type.deleted.name"), DiffColors.DIFF_DELETED);
-  public static final TextDiffType CONFLICT = new TextDiffType(DiffBundle.message("diff.type.conflict.name"), DiffColors.DIFF_CONFLICT);
+  public static final TextDiffType INSERT = new TextDiffType(TextDiffTypeEnum.INSERT, DiffBundle.message("diff.type.inserted.name"), DiffColors.DIFF_INSERTED);
+  public static final TextDiffType CHANGED = new TextDiffType(TextDiffTypeEnum.CHANGED, DiffBundle.message("diff.type.changed.name"), DiffColors.DIFF_MODIFIED);
+  public static final TextDiffType DELETED = new TextDiffType(TextDiffTypeEnum.DELETED, DiffBundle.message("diff.type.deleted.name"), DiffColors.DIFF_DELETED);
+  public static final TextDiffType CONFLICT = new TextDiffType(TextDiffTypeEnum.CONFLICT, DiffBundle.message("diff.type.conflict.name"), DiffColors.DIFF_CONFLICT);
 
-  public static final TextDiffType NONE = new TextDiffType(DiffBundle.message("diff.type.none.name"), null);
+  public static final TextDiffType NONE = new TextDiffType(TextDiffTypeEnum.NONE, DiffBundle.message("diff.type.none.name"), null);
 
+  private final TextDiffTypeEnum myType;
   public static final List<TextDiffType> DIFF_TYPES = Arrays.asList(new TextDiffType[]{DELETED, CHANGED, INSERT});
   public static final List<TextDiffType> MERGE_TYPES = Arrays.asList(new TextDiffType[]{DELETED, CHANGED, INSERT, CONFLICT});
   private final TextAttributesKey myAttributesKey;
@@ -46,7 +48,23 @@ public class TextDiffType implements DiffStatusBar.LegendTypeDescriptor {
     }
   };
 
-  private TextDiffType(String displayName, TextAttributesKey attrubutesKey) {
+  public static TextDiffType create(@NotNull final TextDiffTypeEnum type) {
+    if (TextDiffTypeEnum.INSERT.equals(type)) {
+      return INSERT;
+    } else if (TextDiffTypeEnum.CHANGED.equals(type)) {
+      return CHANGED;
+    } else if (TextDiffTypeEnum.DELETED.equals(type)) {
+      return DELETED;
+    } else if (TextDiffTypeEnum.CONFLICT.equals(type)) {
+      return CONFLICT;
+    } else {
+      // NONE
+      return NONE;
+    }
+  }
+
+  private TextDiffType(TextDiffTypeEnum type, String displayName, TextAttributesKey attrubutesKey) {
+    myType = type;
     myAttributesKey = attrubutesKey;
     myDisplayName = displayName;
   }
@@ -84,4 +102,8 @@ public class TextDiffType implements DiffStatusBar.LegendTypeDescriptor {
   public String toString(){
     return myDisplayName;
   }
+
+  public TextDiffTypeEnum getType() {
+    return myType;
+  }
 }
index b9477834d43afc354f0b4a7f5d9f743678d639ba..d4ffd54ba1bbdd3adddcfc463ac94fa5ef2e2d65 100644 (file)
@@ -137,4 +137,8 @@ cannot.start.other.instance.is.running.error.message={0} was unable to create a
 button.load.file=Load File
 date.frequency=Once {0}
 name.label.text=Na&me:
-smth.already.exist.error.message={0} with name ''{1}'' already exist.
\ No newline at end of file
+smth.already.exist.error.message={0} with name ''{1}'' already exist.
+comparison.policy.default.name=Default
+comparison.policy.trim.space.name=Trim space
+comparison.policy.ignore.spaces.name=Ignore spaces
+comparison.ignore.whitespace.acton.name=Ignore whitespace:
\ No newline at end of file
index 988120f135efdc9dadba2b00d2bdd3a43217aa1c..36ff0f0129443ac264230eff2e374e6b6dddf029 100644 (file)
@@ -78,4 +78,4 @@ diff.type.inserted.name=Inserted
 diff.type.changed.name=Changed
 diff.type.deleted.name=Deleted
 diff.type.conflict.name=Conflict
-diff.type.none.name=None
\ No newline at end of file
+diff.type.none.name=None
similarity index 98%
rename from platform/platform-impl/src/com/intellij/openapi/diff/ex/DiffFragment.java
rename to platform/util/src/com/intellij/openapi/diff/ex/DiffFragment.java
index c6db5b031552030311316ca519dfa48398af7657..f4b3a910260a137a2727e4a20b00e0ab79e4057a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2010 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -76,4 +76,4 @@ public class DiffFragment {
   public boolean isOneSide() {
     return myText1 == null || myText2 == null;
   }
-}
\ No newline at end of file
+}
similarity index 96%
rename from platform/platform-impl/src/com/intellij/openapi/diff/impl/ComparisonPolicy.java
rename to platform/util/src/com/intellij/openapi/diff/impl/ComparisonPolicy.java
index 14ed3b76c2cd69e40626e815b15d268a5ca4ed84..85e30c8c7032377c3ac11c6dfebccf5dae1159c6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2010 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 package com.intellij.openapi.diff.impl;
 
+import com.intellij.CommonBundle;
 import com.intellij.openapi.diff.ex.DiffFragment;
 import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
 import com.intellij.openapi.diff.impl.highlighting.Util;
 import com.intellij.openapi.diff.impl.processing.DiffCorrection;
 import com.intellij.openapi.diff.impl.processing.Formatting;
 import com.intellij.openapi.diff.impl.processing.Word;
-import com.intellij.openapi.diff.DiffBundle;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.text.StringUtil;
@@ -50,7 +50,7 @@ public abstract class ComparisonPolicy {
     return DiffFragmentBuilder.buildFragments(builder, change);
   }
 
-  public static final ComparisonPolicy DEFAULT = new ComparisonPolicy(DiffBundle.message("comparison.policy.default.name")) {
+  public static final ComparisonPolicy DEFAULT = new ComparisonPolicy(CommonBundle.message("comparison.policy.default.name")) {
     protected Object[] getWrappers(String[] strings) {
       return strings;
     }
@@ -69,7 +69,7 @@ public abstract class ComparisonPolicy {
     }
   };
 
-  public static final ComparisonPolicy TRIM_SPACE = new ComparisonPolicy(DiffBundle.message("comparison.policy.trim.space.name")) {
+  public static final ComparisonPolicy TRIM_SPACE = new ComparisonPolicy(CommonBundle.message("comparison.policy.trim.space.name")) {
     protected Object[] getLineWrappers(String[] lines) {
       return trimStrings(lines);
     }
@@ -182,7 +182,7 @@ public abstract class ComparisonPolicy {
 
   private static class IgnoreSpacePolicy extends ComparisonPolicy implements DiffCorrection.FragmentProcessor<DiffCorrection.FragmentsCollector> {
     public IgnoreSpacePolicy() {
-      super(DiffBundle.message("comparison.policy.ignore.spaces.name"));
+      super(CommonBundle.message("comparison.policy.ignore.spaces.name"));
     }
 
     protected Object[] getLineWrappers(String[] lines) {
similarity index 99%
rename from platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffRange.java
rename to platform/util/src/com/intellij/openapi/diff/impl/DiffRange.java
index e31d31e79869b2086ee148a60d8b1826f6a8be6b..f81b5112d557bc55ee8a90fae417e0ec53a27f4d 100644 (file)
@@ -41,4 +41,4 @@ public class DiffRange implements DiffFragmentBuilder.Range {
   public String toString() {
     return "DiffRange: " + myStart + "," + myEnd;
   }
-}
\ No newline at end of file
+}
similarity index 82%
rename from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/Fragment.java
rename to platform/util/src/com/intellij/openapi/diff/impl/fragments/Fragment.java
index e79d62e10e73cf204347b53b4d320a9e6d0103a6..6ccd997a5cf2c94fc3a6c149b2c3466a585d1cfc 100644 (file)
  */
 package com.intellij.openapi.diff.impl.fragments;
 
-import com.intellij.openapi.diff.impl.highlighting.DiffMarkup;
 import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
-import com.intellij.openapi.diff.impl.util.TextDiffType;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.TextRange;
 
 public interface Fragment {
-  TextDiffType getType();
+  TextDiffTypeEnum getType();
   TextRange getRange(FragmentSide side);
 
   Fragment shift(TextRange range1, TextRange range2, int startingLine1, int startingLine2);
 
-  void highlight(DiffMarkup appender1, DiffMarkup appender2, boolean isLast);
+  void highlight(FragmentHighlighter fragmentHighlighter);
 
   Fragment getSubfragmentAt(int offset, FragmentSide side, Condition<Fragment> condition);
 }
diff --git a/platform/util/src/com/intellij/openapi/diff/impl/fragments/FragmentHighlighter.java b/platform/util/src/com/intellij/openapi/diff/impl/fragments/FragmentHighlighter.java
new file mode 100644 (file)
index 0000000..5a6de85
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.diff.impl.fragments;
+
+public interface FragmentHighlighter {
+  void highlightInline(InlineFragment fragment);
+  void highlightLine(LineFragment fragment);
+}
similarity index 82%
rename from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/InlineFragment.java
rename to platform/util/src/com/intellij/openapi/diff/impl/fragments/InlineFragment.java
index ae70e6bf3fd1734dc0ebce41e2d4993c832b59f4..5e81165862936ca841c2c3aebdbb3f5e5c5a63c7 100644 (file)
@@ -16,9 +16,8 @@
 package com.intellij.openapi.diff.impl.fragments;
 
 import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.diff.impl.highlighting.DiffMarkup;
 import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
-import com.intellij.openapi.diff.impl.util.TextDiffType;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.TextRange;
 
@@ -28,15 +27,15 @@ public class InlineFragment implements Fragment {
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.fragments.InlineFragment");
   private final TextRange myRange1;
   private final TextRange myRange2;
-  private final TextDiffType myType;
+  private final TextDiffTypeEnum myType;
 
-  public InlineFragment(TextDiffType type, TextRange range1, TextRange range2) {
+  public InlineFragment(TextDiffTypeEnum type, TextRange range1, TextRange range2) {
     myType = type;
     myRange1 = range1;
     myRange2 = range2;
   }
 
-  public TextDiffType getType() {
+  public TextDiffTypeEnum getType() {
     return myType;
   }
 
@@ -52,9 +51,8 @@ public class InlineFragment implements Fragment {
                               LineFragment.shiftRange(range2, myRange2));
   }
 
-  public void highlight(DiffMarkup appender1, DiffMarkup appender2, boolean isLast) {
-    appender1.highlightText(this, true);
-    appender2.highlightText(this, true);
+  public void highlight(FragmentHighlighter fragmentHighlighter) {
+    fragmentHighlighter.highlightInline(this);
   }
 
   public Fragment getSubfragmentAt(int offset, FragmentSide side, Condition<Fragment> condition) {
similarity index 89%
rename from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/LineBlock.java
rename to platform/util/src/com/intellij/openapi/diff/impl/fragments/LineBlock.java
index 69d4b66365af8987c829a48f722eee4ebc7e4e0a..6ff9de438e15a2e46b833f908caf15acfd784770 100644 (file)
@@ -15,7 +15,7 @@
  */
 package com.intellij.openapi.diff.impl.fragments;
 
-import com.intellij.openapi.diff.impl.util.TextDiffType;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 
 import java.util.Comparator;
 
@@ -24,9 +24,9 @@ public class LineBlock {
   private final int myModifiedLines1;
   private final int myStartingLine2;
   private final int myModifiedLines2;
-  private final TextDiffType myType;
+  private final TextDiffTypeEnum myType;
 
-  public LineBlock(int startingLine1, int modifiedLines1, int startingLine2, int modifiedLines2, TextDiffType blockType) {
+  public LineBlock(int startingLine1, int modifiedLines1, int startingLine2, int modifiedLines2, TextDiffTypeEnum blockType) {
     myStartingLine1 = startingLine1;
     myModifiedLines1 = modifiedLines1;
     myStartingLine2 = startingLine2;
@@ -64,7 +64,7 @@ public class LineBlock {
     }
   };
 
-  public TextDiffType getType() {
+  public TextDiffTypeEnum getType() {
     return myType;
   }
 }
similarity index 73%
rename from platform/platform-impl/src/com/intellij/openapi/diff/impl/fragments/LineFragment.java
rename to platform/util/src/com/intellij/openapi/diff/impl/fragments/LineFragment.java
index 144395a19cf62ef463eff9e524e758680c8f0696..e56f13277c4ba0f35ffe22a4c945abca582984a6 100644 (file)
 package com.intellij.openapi.diff.impl.fragments;
 
 import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.diff.DiffColors;
-import com.intellij.openapi.diff.actions.MergeOperations;
-import com.intellij.openapi.diff.impl.highlighting.DiffMarkup;
 import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
-import com.intellij.openapi.diff.impl.util.TextDiffType;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.colors.TextAttributesKey;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.TextRange;
 
@@ -39,7 +34,7 @@ public class LineFragment extends LineBlock implements Fragment {
 
   public LineFragment(int startingLine1, int modifiedLines1,
                       int startingLine2, int modifiedLines2,
-                      TextDiffType blockType, TextRange range1, TextRange range2) {
+                      TextDiffTypeEnum blockType, TextRange range1, TextRange range2) {
     this(startingLine1, modifiedLines1,
          startingLine2, modifiedLines2,
          blockType, range1, range2, FragmentList.EMPTY);
@@ -47,7 +42,7 @@ public class LineFragment extends LineBlock implements Fragment {
 
   private LineFragment(int startingLine1, int modifiedLines1,
                        int startingLine2, int modifiedLines2,
-                       TextDiffType blockType, TextRange range1, TextRange range2, FragmentList children) {
+                       TextDiffTypeEnum blockType, TextRange range1, TextRange range2, FragmentList children) {
     super(startingLine1, modifiedLines1, startingLine2, modifiedLines2, blockType);
     LOG.assertTrue(modifiedLines1 > 0 || modifiedLines2 > 0);
     myRange1 = range1;
@@ -79,43 +74,8 @@ public class LineFragment extends LineBlock implements Fragment {
     return new TextRange(newStart, newEnd);
   }
 
-  public void highlight(DiffMarkup wrapper1, DiffMarkup wrapper2, boolean isLast) {
-    addModifyActions(wrapper1, wrapper2);
-    if (myChildren.isEmpty()) {
-      wrapper1.highlightText(this, false);
-      wrapper2.highlightText(this, false);
-    }
-    else {
-      for (Iterator<Fragment> iterator = myChildren.iterator(); iterator.hasNext();) {
-        Fragment fragment = iterator.next();
-        fragment.highlight(wrapper1, wrapper2, !iterator.hasNext());
-      }
-    }
-    if (isEqual() && isLast) return;
-    addBottomLine(wrapper1, getEndLine1());
-    addBottomLine(wrapper2, getEndLine2());
-  }
-
-  private void addModifyActions(DiffMarkup wrapper, DiffMarkup otherWrapper) {
-    if (isEqual()) return;
-    if (myHasLineChildren) return;
-    TextRange range = getRange(wrapper.getSide());
-    TextRange otherRange = getRange(wrapper.getSide().otherSide());
-    Document document = wrapper.getDocument();
-    Document otherDocument = otherWrapper.getDocument();
-    wrapper.addAction(MergeOperations.mostSensible(document, otherDocument, range, otherRange), range.getStartOffset());
-    otherWrapper.addAction(MergeOperations.mostSensible(otherDocument, document, otherRange, range), otherRange.getStartOffset());
-  }
-
-  private void addBottomLine(DiffMarkup appender, int endLine) {
-    if (endLine <= 0) return;
-    TextRange range = getRange(appender.getSide());
-    appender.addLineMarker(endLine - 1, getRangeType(range));
-  }
-
-  private TextAttributesKey getRangeType(TextRange range) {
-    if (range.getLength() == 0) return DiffColors.DIFF_DELETED;
-    return getType() == null ? null : DiffColors.DIFF_MODIFIED;
+  public void highlight(FragmentHighlighter fragmentHighlighter) {
+    fragmentHighlighter.highlightLine(this);
   }
 
   public boolean isOneSide() {
@@ -131,6 +91,10 @@ public class LineFragment extends LineBlock implements Fragment {
     return childFragment != null ? childFragment : this;
   }
 
+  public Iterator<Fragment> getChildrenIterator() {
+    return myChildren == null || myChildren.isEmpty() ? null : myChildren.iterator();
+  }
+
   public String getText(String text, FragmentSide side) {
     TextRange range = getRange(side);
     return range.substring(text);
@@ -191,4 +155,18 @@ public class LineFragment extends LineBlock implements Fragment {
     return getRange(FragmentSide.SIDE1).equals(fragment.getRange(FragmentSide.SIDE1)) &&
            getRange(FragmentSide.SIDE2).equals(fragment.getRange(FragmentSide.SIDE2));
   }
+
+  public boolean isHasLineChildren() {
+    return myHasLineChildren;
+  }
+
+  @Override
+  public int getEndLine1() {
+    return super.getEndLine1();
+  }
+
+  @Override
+  public int getEndLine2() {
+    return super.getEndLine2();
+  }
 }
similarity index 96%
rename from platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/DiffCorrection.java
rename to platform/util/src/com/intellij/openapi/diff/impl/processing/DiffCorrection.java
index 3b47b4c2c2237d9126b6f23b17ed09999ba6ac08..3f7d4da9d8cbd72ba1009d30f2af6e1defee055f 100644 (file)
@@ -19,7 +19,6 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.diff.LineTokenizer;
 import com.intellij.openapi.diff.ex.DiffFragment;
 import com.intellij.openapi.diff.impl.ComparisonPolicy;
-import com.intellij.openapi.diff.impl.DiffUtil;
 import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
 import com.intellij.openapi.diff.impl.highlighting.Util;
 import com.intellij.openapi.util.text.StringUtil;
@@ -133,7 +132,7 @@ public interface DiffCorrection {
     }
 
     protected final void actualAdd(DiffFragment fragment) {
-      if (DiffUtil.isEmpty(fragment)) return;
+      if (isEmpty(fragment)) return;
       myItems.add(fragment);
     }
 
@@ -153,6 +152,16 @@ public interface DiffCorrection {
       }
     }
 
+    // todo think where
+    public static int getTextLength(String text) {
+      return text != null ? text.length() : 0;
+    }
+
+    public static boolean isEmpty(DiffFragment fragment) {
+      return getTextLength(fragment.getText1()) == 0 &&
+             getTextLength(fragment.getText2()) == 0;
+    }
+
   }
 
   class FragmentsCollector extends BaseFragmentRunner<FragmentsCollector> {
similarity index 92%
rename from platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/DiffPolicy.java
rename to platform/util/src/com/intellij/openapi/diff/impl/processing/DiffPolicy.java
index b11a74abc96020087bc1dfc48adb237d50141ef7..2a932eb1c8d4eb904ae40262f261e28f14c0db44 100644 (file)
@@ -15,9 +15,9 @@
  */
 package com.intellij.openapi.diff.impl.processing;
 
+import com.intellij.openapi.diff.LineTokenizer;
 import com.intellij.openapi.diff.ex.DiffFragment;
 import com.intellij.openapi.diff.impl.ComparisonPolicy;
-import com.intellij.openapi.diff.impl.DiffUtil;
 
 public interface DiffPolicy {
   DiffFragment[] buildFragments(String text1, String text2);
@@ -33,8 +33,8 @@ public interface DiffPolicy {
     }
 
     public DiffFragment[] buildFragments(String text1, String text2) {
-      String[] strings1 = DiffUtil.convertToLines(text1);
-      String[] strings2 = DiffUtil.convertToLines(text2);
+      String[] strings1 = new LineTokenizer(text1).execute();
+      String[] strings2 = new LineTokenizer(text2).execute();
       return myComparisonPolicy.buildDiffFragmentsFromLines(strings1, strings2);
     }
 
diff --git a/platform/util/src/com/intellij/openapi/diff/impl/util/TextDiffTypeEnum.java b/platform/util/src/com/intellij/openapi/diff/impl/util/TextDiffTypeEnum.java
new file mode 100644 (file)
index 0000000..64f0db7
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.diff.impl.util;
+
+public enum TextDiffTypeEnum {
+  INSERT,
+  CHANGED,
+  DELETED,
+  CONFLICT,
+  NONE
+}
index 3941b53fca31ee62e66725426a70fc133ac63b80..606fa0bf836325d32ca1c1acd116a6c96d5cc66b 100644 (file)
  */
 package com.intellij.openapi.diff.impl.patch;
 
+import com.intellij.openapi.diff.LineTokenizer;
 import com.intellij.openapi.diff.ex.DiffFragment;
 import com.intellij.openapi.diff.impl.ComparisonPolicy;
-import com.intellij.openapi.diff.impl.DiffUtil;
 import com.intellij.openapi.diff.impl.fragments.LineFragment;
 import com.intellij.openapi.diff.impl.processing.DiffCorrection;
 import com.intellij.openapi.diff.impl.processing.DiffFragmentsProcessor;
 import com.intellij.openapi.diff.impl.processing.DiffPolicy;
-import com.intellij.openapi.diff.impl.util.TextDiffType;
+import com.intellij.openapi.diff.impl.util.TextDiffTypeEnum;
 import com.intellij.openapi.progress.ProcessCanceledException;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
@@ -104,14 +104,14 @@ public class PatchBuilder {
       if (afterContent == null) {
         throw new VcsException("Failed to fetch new content for changed file " + afterRevision.getFile().getPath());
       }
-      String[] beforeLines = DiffUtil.convertToLines(beforeContent);
-      String[] afterLines = DiffUtil.convertToLines(afterContent);
+      String[] beforeLines = new LineTokenizer(beforeContent).execute();
+      String[] afterLines = new LineTokenizer(afterContent).execute();
 
       DiffFragment[] woFormattingBlocks = DiffPolicy.LINES_WO_FORMATTING.buildFragments(beforeContent, afterContent);
       DiffFragment[] step1lineFragments = new DiffCorrection.TrueLineBlocks(ComparisonPolicy.DEFAULT).correctAndNormalize(woFormattingBlocks);
       ArrayList<LineFragment> fragments = new DiffFragmentsProcessor().process(step1lineFragments);
 
-      if (fragments.size() > 1 || (fragments.size() == 1 && fragments.get(0).getType() != null && fragments.get(0).getType() != TextDiffType.NONE)) {
+      if (fragments.size() > 1 || (fragments.size() == 1 && fragments.get(0).getType() != null && fragments.get(0).getType() != TextDiffTypeEnum.NONE)) {
         TextFilePatch patch = buildPatchHeading(basePath, beforeRevision, afterRevision);
         result.add(patch);
 
@@ -203,7 +203,7 @@ public class PatchBuilder {
     if (content == null) {
       throw new VcsException("Failed to fetch content for added file " + afterRevision.getFile().getPath());
     }
-    String[] lines = DiffUtil.convertToLines(content);
+    String[] lines = new LineTokenizer(content).execute();
     TextFilePatch result = buildPatchHeading(basePath, afterRevision, afterRevision);
     PatchHunk hunk = new PatchHunk(-1, -1, 0, lines.length);
     for(String line: lines) {
@@ -219,7 +219,7 @@ public class PatchBuilder {
     if (content == null) {
       throw new VcsException("Failed to fetch old content for deleted file " + beforeRevision.getFile().getPath());
     }
-    String[] lines = DiffUtil.convertToLines(content);
+    String[] lines = new LineTokenizer(content).execute();
     TextFilePatch result = buildPatchHeading(basePath, beforeRevision, beforeRevision);
     PatchHunk hunk = new PatchHunk(0, lines.length, -1, -1);
     for(String line: lines) {
@@ -235,7 +235,7 @@ public class PatchBuilder {
     int endLine = -1;
     while(!fragments.isEmpty()) {
       LineFragment fragment = fragments.get(0);
-      if (fragment.getType() == null || fragment.getType() == TextDiffType.NONE) {
+      if (fragment.getType() == null || fragment.getType() == TextDiffTypeEnum.NONE) {
         fragments.remove(0);
         continue;
       }