diff: move HighlightingMode logic to TextCompareProcessor
authorAleksey Pivovarov <Aleksey.Pivovarov@jetbrains.com>
Sat, 1 Mar 2014 07:41:03 +0000 (11:41 +0400)
committerAleksey Pivovarov <Aleksey.Pivovarov@jetbrains.com>
Sat, 1 Mar 2014 07:41:03 +0000 (11:41 +0400)
platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentedDiffPanelState.java
platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/SimpleDiffPanelState.java
platform/platform-impl/src/com/intellij/openapi/diff/impl/processing/TextCompareProcessor.java
platform/platform-tests/testSrc/com/intellij/openapi/diff/impl/processing/TextCompareProcessorTest.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/FragmentedDiffRequestFromChange.java

index d3b273fdaba971e2033783d7835db5cf0464bf3d..7e395c1b4a9ecb0eabb822bd69fff5f34b66a590 100644 (file)
@@ -137,7 +137,8 @@ public class FragmentedDiffPanelState extends DiffPanelState {
     //setDiffPolicy(diffPolicy);
     diffPolicy.setRanges(ranges);
 
-    return addMarkup(new TextCompareProcessor(myComparisonPolicy, diffPolicy).process(myAppender1.getText(), myAppender2.getText()));
+    return addMarkup(
+      new TextCompareProcessor(myComparisonPolicy, diffPolicy, myHighlightMode).process(myAppender1.getText(), myAppender2.getText()));
   }
 
   private BeforeAfter<Integer> lineStarts(int i) {
index 14c235470347cdc1d4e70fc7d91f771d05240d9e..d3e1dfd5a64a4b793f007d0c943b11144cc0cbef 100644 (file)
@@ -30,8 +30,8 @@ import com.intellij.util.diff.FilesTooBigForDiffException;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 
 public abstract class SimpleDiffPanelState implements Disposable  {
   protected ComparisonPolicy myComparisonPolicy = ComparisonPolicy.DEFAULT;
@@ -84,7 +84,7 @@ public abstract class SimpleDiffPanelState implements Disposable  {
   public void dispose() {
   }
 
-  private LineBlocks addMarkup(final ArrayList<LineFragment> lines) {
+  private LineBlocks addMarkup(final List<LineFragment> lines) {
     ApplicationManager.getApplication().runWriteAction(new Runnable() {
       public void run() {
         final FragmentHighlighterImpl fragmentHighlighter = new FragmentHighlighterImpl(myAppender1, myAppender2);
@@ -114,12 +114,8 @@ public abstract class SimpleDiffPanelState implements Disposable  {
       return LineBlocks.EMPTY;
     }
 
-    if (myHighlightMode == HighlightMode.NO_HIGHLIGHTING) {
-      return LineBlocks.fromLineFragments(Collections.<LineFragment>emptyList());
-    }
-
-    return addMarkup(new TextCompareProcessor(myComparisonPolicy, myDiffPolicy, myHighlightMode == HighlightMode.BY_WORD)
-                       .process(myAppender1.getText(), myAppender2.getText()));
+    return addMarkup(
+      new TextCompareProcessor(myComparisonPolicy, myDiffPolicy, myHighlightMode).process(myAppender1.getText(), myAppender2.getText()));
   }
 
   public Project getProject() { return myProject; }
index 96d5e76ad48dfbe87d880811ddfd5523df26b527..bdf414c53935fa5146486b62d8b4aaa74e45a926 100644 (file)
@@ -16,7 +16,6 @@
 package com.intellij.openapi.diff.impl.processing;
 
 import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.diff.impl.string.DiffString;
 import com.intellij.openapi.diff.ex.DiffFragment;
 import com.intellij.openapi.diff.impl.ComparisonPolicy;
 import com.intellij.openapi.diff.impl.fragments.Fragment;
@@ -24,36 +23,39 @@ import com.intellij.openapi.diff.impl.fragments.LineFragment;
 import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
 import com.intellij.openapi.diff.impl.highlighting.LineBlockDivider;
 import com.intellij.openapi.diff.impl.highlighting.Util;
+import com.intellij.openapi.diff.impl.string.DiffString;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.diff.FilesTooBigForDiffException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 public class TextCompareProcessor {
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.diff.impl.processing.Processor");
   private final DiffPolicy myDiffPolicy;
   @NotNull private final ComparisonPolicy myComparisonPolicy;
-  private final boolean mySearchForSubFragments;
+  @NotNull private final HighlightMode myHighlightMode;
 
   public TextCompareProcessor(@NotNull ComparisonPolicy comparisonPolicy,
-                              final DiffPolicy diffPolicy,
-                              boolean searchForSubFragments) {
+                              @NotNull DiffPolicy diffPolicy,
+                              @NotNull HighlightMode highlightMode) {
     myComparisonPolicy = comparisonPolicy;
     myDiffPolicy = diffPolicy;
-    mySearchForSubFragments = searchForSubFragments;
-  }
-
-  public TextCompareProcessor(@NotNull ComparisonPolicy comparisonPolicy, final DiffPolicy diffPolicy) {
-    this(comparisonPolicy, diffPolicy, true);
+    myHighlightMode = highlightMode;
   }
 
   public TextCompareProcessor(@NotNull ComparisonPolicy comparisonPolicy) {
-    this(comparisonPolicy, DiffPolicy.LINES_WO_FORMATTING);
+    this(comparisonPolicy, DiffPolicy.LINES_WO_FORMATTING, HighlightMode.BY_WORD);
   }
 
-  public ArrayList<LineFragment> process(@Nullable String text1, @Nullable String text2) throws FilesTooBigForDiffException {
+  public List<LineFragment> process(@Nullable String text1, @Nullable String text2) throws FilesTooBigForDiffException {
+    if (myHighlightMode == HighlightMode.NO_HIGHLIGHTING) {
+      return Collections.emptyList();
+    }
+
     text1 = StringUtil.notNullize(text1);
     text2 = StringUtil.notNullize(text2);
     if (text1.isEmpty() || text2.isEmpty()) {
@@ -68,7 +70,7 @@ public class TextCompareProcessor {
     ArrayList<LineFragment> lineBlocks = new DiffFragmentsProcessor().process(step1lineFragments);
 
     int badLinesCount = 0;
-    if (mySearchForSubFragments) {
+    if (myHighlightMode == HighlightMode.BY_WORD) {
       for (LineFragment lineBlock : lineBlocks) {
         if (lineBlock.isOneSide() || lineBlock.isEqual()) continue;
         try {
index 4d4ed9b9937fe7d8c9220d36c52b4f4ab43d8f28..854a17d47ebd2e6d9782d52163a2cd6addb12c97 100644 (file)
@@ -5,12 +5,12 @@ import com.intellij.openapi.diff.impl.fragments.LineFragment;
 import com.intellij.util.diff.FilesTooBigForDiffException;
 import junit.framework.TestCase;
 
-import java.util.ArrayList;
+import java.util.List;
 
 public class TextCompareProcessorTest extends TestCase {
   public void testIgnoreWrappingEqualText() throws FilesTooBigForDiffException {
     TextCompareProcessor processor = new TextCompareProcessor(ComparisonPolicy.IGNORE_SPACE);
-    ArrayList<LineFragment> lineFragments = processor.process("f(a, b)\n", "f(a,\nb)\n");
+    List<LineFragment> lineFragments = processor.process("f(a, b)\n", "f(a,\nb)\n");
     assertTrue(lineFragments.size() == 1);
     assertNull(lineFragments.get(0).getType());
   }
index 5b95283e1b305b1121d44ac2c2b103dd1bfb739c..2f3788ae509c4f1b87f2f0cad3a1f92c77006b19 100644 (file)
@@ -146,7 +146,7 @@ public class FragmentedDiffRequestFromChange {
           comparisonPolicy = ComparisonPolicy.DEFAULT;
         }
         final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy);
-        final ArrayList<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
+        final List<LineFragment> lineFragments = processor.process(myOldDocument.getText(), myDocument.getText());
         myRanges = new ArrayList<BeforeAfter<TextRange>>(lineFragments.size());
         for (LineFragment lineFragment : lineFragments) {
           if (!lineFragment.isEqual()) {