diff dwtx/jface/internal/text/revisions/ChangeRegion.d @ 162:1a5b8f8129df

...
author Frank Benoit <benoit@tionex.de>
date Mon, 08 Sep 2008 00:51:37 +0200
parents 3678e4f1a766
children
line wrap: on
line diff
--- a/dwtx/jface/internal/text/revisions/ChangeRegion.d	Wed Aug 27 14:49:30 2008 +0200
+++ b/dwtx/jface/internal/text/revisions/ChangeRegion.d	Mon Sep 08 00:51:37 2008 +0200
@@ -20,12 +20,9 @@
 import dwtx.jface.internal.text.revisions.RevisionPainter; // packageimport
 import dwtx.jface.internal.text.revisions.RevisionSelectionProvider; // packageimport
 
-
 import dwt.dwthelper.utils;
-
 import dwtx.dwtxhelper.Collection;
-
-
+import tango.text.convert.Format;
 
 import dwtx.core.runtime.Assert;
 import dwtx.jface.text.revisions.Revision;
@@ -36,32 +33,33 @@
  * A change region describes a contiguous range of lines that was changed in the same revision of a
  * document. Once it is adjusted to diff information, the originally contiguous range may be split
  * into several ranges or even be empty.
- * 
+ *
  * @since 3.2
  */
 public final class ChangeRegion {
     private const Revision fRevision;
     private const ILineRange fLines;
-    private const List fAdjusted= new LinkedList();
-    
+    private const List fAdjusted;
+
     /**
      * Creates a new change region for the given revision and line range.
-     * 
+     *
      * @param revision the revision of the new region
      * @param lines the line range of the new region
      * @throws IndexOutOfBoundsException if the line range is not well-formed
      */
     public this(Revision revision, ILineRange lines)  {
+        fAdjusted= new LinkedList();
         Assert.isLegal(revision !is null);
         Assert.isLegal(lines !is null);
         fLines= Range.copy(lines);
         fRevision=revision;
         clearDiff();
     }
-    
+
     /**
      * Returns the revision that this region belongs to.
-     * 
+     *
      * @return the revision that this region belongs to
      */
     public Revision getRevision() {
@@ -70,7 +68,7 @@
 
     /**
      * Returns the original (before applying diff information) line range of this change region.
-     * 
+     *
      * @return the original (before applying diff information) line range of this change region
      */
     public ILineRange getOriginalRange() {
@@ -80,28 +78,28 @@
     /**
      * Returns the list of {@link ILineRange}s of this change region for which the revision
      * information is still valid.
-     * 
+     *
      * @return the list of adjusted line ranges
      */
     public List getAdjustedRanges() {
         return fAdjusted;
     }
-    
+
     /**
      * Returns the line coverage of the adjusted ranges, an empty range if the coverage is empty.
-     * 
+     *
      * @return the line coverage of the adjusted ranges
      */
     public ILineRange getAdjustedCoverage() {
         if (fAdjusted.isEmpty())
             return new LineRange(fLines.getStartLine(), 0);
-        
+
         Range first= cast(Range) fAdjusted.get(0);
         Range last= cast(Range) fAdjusted.get(fAdjusted.size() - 1);
-        
+
         return Range.createAbsolute(first.start(), last.end());
     }
-    
+
     /**
      * Clears any adjusted ranges, restoring the original range.
      */
@@ -109,16 +107,16 @@
         fAdjusted.clear();
         fAdjusted.add(Range.copy(fLines));
     }
-    
+
     /**
      * Adjusts this change region to a diff hunk. This will change the adjusted ranges.
-     * 
+     *
      * @param hunk the diff hunk to adjust to
      */
     public void adjustTo(Hunk hunk) {
         for (ListIterator it= fAdjusted.listIterator(); it.hasNext();) {
             Range range= cast(Range) it.next();
-            
+
             // do we need a split?
             int unchanged= getUnchanged(hunk, range.start());
             if (unchanged > 0) {
@@ -128,40 +126,40 @@
                 it.add(range);
                 it.previous(); it.next(); // needed so we can remove below
             }
-            
+
             int line= range.start();
             Assert.isTrue(hunk.line <= line);
-            
+
             // by how much do we shrink?
             int overlap= getOverlap(hunk, line);
             if (overlap >= range.length()) {
                 it.remove();
                 continue;
             }
-            
+
             // by how much do we move?
             range.moveBy(hunk.delta + overlap);
             range.resizeBy(-overlap);
         }
-        
+
     }
-    
+
     private int getUnchanged(Hunk hunk, int line) {
         return Math.max(0, hunk.line - line);
     }
 
     /*
-     * Returns the number of lines after line that the hunk reports as changed. 
+     * Returns the number of lines after line that the hunk reports as changed.
      */
     private int getOverlap(Hunk hunk, int line) {
-        
+
         int deltaLine= hunk.line + hunk.changed;
         if (hunk.delta >= 0) {
             if (deltaLine <= line)
                 return 0;
             return deltaLine - line;
         }
-        
+
         // hunk.delta < 0
         int hunkEnd= deltaLine - hunk.delta;
         int cutCount= hunkEnd - line;
@@ -172,6 +170,6 @@
      * @see java.lang.Object#toString()
      */
     public override String toString() {
-        return "ChangeRegion [" + fRevision.toString() + ", [" + fLines.getStartLine() + "+" + fLines.getNumberOfLines() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        return Format("ChangeRegion [{},[{}+{})]", fRevision.toString(), fLines.getStartLine(), fLines.getNumberOfLines() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
     }
 }