comparison org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children 6f068362a363
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 org.eclipse.jface.internal.text.revisions.Hunk;
14
15 import org.eclipse.jface.internal.text.revisions.HunkComputer; // packageimport
16 import org.eclipse.jface.internal.text.revisions.LineIndexOutOfBoundsException; // packageimport
17 import org.eclipse.jface.internal.text.revisions.Colors; // packageimport
18 import org.eclipse.jface.internal.text.revisions.ChangeRegion; // packageimport
19 import org.eclipse.jface.internal.text.revisions.Range; // packageimport
20 import org.eclipse.jface.internal.text.revisions.RevisionPainter; // packageimport
21 import org.eclipse.jface.internal.text.revisions.RevisionSelectionProvider; // packageimport
22
23 import java.lang.all;
24 import tango.text.convert.Format;
25
26 import org.eclipse.core.runtime.Assert;
27
28 /**
29 * A hunk describes a contiguous range of changed, added or deleted lines. <code>Hunk</code>s are separated by
30 * one or more unchanged lines.
31 *
32 * @since 3.3
33 */
34 public final class Hunk {
35 /**
36 * The line at which the hunk starts in the current document. Must be in
37 * <code>[0, numberOfLines]</code> &ndash; note the inclusive end; there may be a hunk with
38 * <code>line is numberOfLines</code> to describe deleted lines at then end of the document.
39 */
40 public const int line;
41 /**
42 * The difference in lines compared to the corresponding line range in the original. Positive
43 * for added lines, negative for deleted lines.
44 */
45 public const int delta;
46 /** The number of changed lines in this hunk, must be &gt;= 0. */
47 public const int changed;
48
49 /**
50 * Creates a new hunk.
51 *
52 * @param line the line at which the hunk starts, must be &gt;= 0
53 * @param delta the difference in lines compared to the original
54 * @param changed the number of changed lines in this hunk, must be &gt;= 0
55 */
56 public this(int line, int delta, int changed) {
57 Assert.isLegal(line >= 0);
58 Assert.isLegal(changed >= 0);
59 this.line= line;
60 this.delta= delta;
61 this.changed= changed;
62 }
63
64 /*
65 * @see java.lang.Object#toString()
66 */
67 public override String toString() {
68 return Format("Hunk [{}>{}{}{}]", line, changed, delta < 0 ? "-" : "+", Math.abs(delta) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
69 }
70
71 /*
72 * @see java.lang.Object#hashCode()
73 */
74 public override hash_t toHash() {
75 final int prime= 31;
76 int result= 1;
77 result= prime * result + changed;
78 result= prime * result + delta;
79 result= prime * result + line;
80 return result;
81 }
82
83 /*
84 * @see java.lang.Object#equals(java.lang.Object)
85 */
86 public override int opEquals(Object obj) {
87 if (obj is this)
88 return true;
89 if ( Hunk other= cast(Hunk)obj ) {
90 return other.line is this.line && other.delta is this.delta && other.changed is this.changed;
91 }
92 return false;
93 }
94 }