Mercurial > projects > dwt-addons
annotate dwtx/jface/internal/text/revisions/HunkComputer.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | 25f1f92fa3df |
children |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2006 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.internal.text.revisions.HunkComputer; | |
14 | |
131 | 15 import dwtx.jface.internal.text.revisions.LineIndexOutOfBoundsException; // packageimport |
16 import dwtx.jface.internal.text.revisions.Hunk; // packageimport | |
17 import dwtx.jface.internal.text.revisions.Colors; // packageimport | |
18 import dwtx.jface.internal.text.revisions.ChangeRegion; // packageimport | |
19 import dwtx.jface.internal.text.revisions.Range; // packageimport | |
20 import dwtx.jface.internal.text.revisions.RevisionPainter; // packageimport | |
21 import dwtx.jface.internal.text.revisions.RevisionSelectionProvider; // packageimport | |
22 | |
23 | |
129 | 24 import dwt.dwthelper.utils; |
25 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
26 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
133
diff
changeset
|
27 |
129 | 28 |
29 import dwtx.jface.text.source.ILineDiffInfo; | |
30 import dwtx.jface.text.source.ILineDiffer; | |
31 | |
32 | |
33 /** | |
34 * Computes the diff hunks from an {@link ILineDiffer}. | |
158 | 35 * |
129 | 36 * @since 3.3 |
37 */ | |
38 public final class HunkComputer { | |
39 /** | |
40 * Converts the line-based information of {@link ILineDiffer} into {@link Hunk}s, grouping | |
41 * contiguous blocks of lines that are changed (added, deleted). | |
158 | 42 * |
129 | 43 * @param differ the line differ to query |
44 * @param lines the number of lines to query | |
45 * @return the corresponding {@link Hunk} information | |
46 */ | |
47 public static Hunk[] computeHunks(ILineDiffer differ, int lines) { | |
48 List hunks= new ArrayList(lines); | |
49 | |
50 int added= 0; | |
51 int changed= 0; | |
52 ILineDiffInfo info= null; | |
53 for (int line= 0; line < lines; line++) { | |
54 info= differ.getLineInfo(line); | |
55 if (info is null) | |
56 continue; | |
57 | |
58 int changeType= info.getChangeType(); | |
59 switch (changeType) { | |
60 case ILineDiffInfo.ADDED: | |
61 added++; | |
62 continue; | |
63 case ILineDiffInfo.CHANGED: | |
64 changed++; | |
65 continue; | |
66 case ILineDiffInfo.UNCHANGED: | |
67 added -= info.getRemovedLinesAbove(); | |
68 if (added !is 0 || changed !is 0) { | |
69 hunks.add(new Hunk(line - changed - Math.max(0, added), added, changed)); | |
70 added= 0; | |
71 changed= 0; | |
72 } | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
73 default: |
129 | 74 } |
75 } | |
76 | |
77 // last hunk | |
78 if (info !is null) { | |
79 added -= info.getRemovedLinesBelow(); | |
80 if (added !is 0 || changed !is 0) { | |
81 hunks.add(new Hunk(lines - changed, added, changed)); | |
82 added= 0; | |
83 changed= 0; | |
84 } | |
85 } | |
158 | 86 |
87 return arraycast!(Hunk)( hunks.toArray()); | |
129 | 88 } |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
89 private this() { |
129 | 90 } |
91 } |