Mercurial > projects > dwt-addons
annotate dwtx/jface/text/link/LinkedPosition.d @ 160:3678e4f1a766
toHash, toString
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 02:07:22 +0200 |
parents | b6bad70d540a |
children | 1a5b8f8129df |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 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.text.link.LinkedPosition; | |
14 | |
131 | 15 import dwtx.jface.text.link.LinkedModeModel; // packageimport |
16 import dwtx.jface.text.link.ILinkedModeListener; // packageimport | |
17 import dwtx.jface.text.link.TabStopIterator; // packageimport | |
18 import dwtx.jface.text.link.LinkedModeUI; // packageimport | |
19 import dwtx.jface.text.link.InclusivePositionUpdater; // packageimport | |
20 import dwtx.jface.text.link.LinkedPositionGroup; // packageimport | |
21 import dwtx.jface.text.link.LinkedModeManager; // packageimport | |
22 import dwtx.jface.text.link.LinkedPositionAnnotations; // packageimport | |
23 import dwtx.jface.text.link.ProposalPosition; // packageimport | |
24 | |
25 | |
129 | 26 import dwt.dwthelper.utils; |
27 | |
28 | |
29 import dwtx.core.runtime.Assert; | |
30 import dwtx.jface.text.BadLocationException; | |
31 import dwtx.jface.text.DocumentEvent; | |
32 import dwtx.jface.text.IDocument; | |
33 import dwtx.jface.text.Position; | |
34 | |
35 /** | |
36 * A <code>Position</code> on a document that knows which document it is | |
37 * registered with and has a sequence number for tab stops. | |
38 * <p> | |
39 * Clients may extend this class. | |
40 * </p> | |
41 * @since 3.0 | |
42 */ | |
43 public class LinkedPosition : Position { | |
44 | |
45 /** The document this position belongs to. */ | |
46 private IDocument fDocument; | |
47 private int fSequenceNumber; | |
48 | |
49 /** | |
50 * Creates a new instance. | |
51 * | |
52 * @param document the document | |
53 * @param offset the offset of the position | |
54 * @param length the length of the position | |
55 * @param sequence the iteration sequence rank | |
56 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
57 public this(IDocument document, int offset, int length, int sequence) { |
129 | 58 super(offset, length); |
59 Assert.isNotNull(document); | |
60 fDocument= document; | |
61 fSequenceNumber= sequence; | |
62 } | |
63 | |
64 /** | |
65 * Creates a new instance. Equivalent to calling | |
66 * <code>LinkedPosition(document, offset, length, LinkedPositionGroup.NO_STOP)</code> | |
67 * | |
68 * @param document the document | |
69 * @param offset the offset of the position | |
70 * @param length the length of the position | |
71 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
72 public this(IDocument document, int offset, int length) { |
129 | 73 this(document, offset, length, LinkedPositionGroup.NO_STOP); |
74 } | |
75 | |
76 /** | |
77 * @return Returns the document. | |
78 */ | |
79 public IDocument getDocument() { | |
80 return fDocument; | |
81 } | |
82 | |
83 /* | |
84 * @see dwtx.jface.text.Position#equals(java.lang.Object) | |
85 */ | |
86 public bool equals(Object other) { | |
138 | 87 if ( cast(LinkedPosition)other ) { |
134 | 88 LinkedPosition p= cast(LinkedPosition) other; |
129 | 89 return p.offset is offset && p.length is length && p.fDocument is fDocument; |
90 } | |
91 return false; | |
92 } | |
93 | |
94 /** | |
95 * Returns whether this position overlaps with <code>position</code>. | |
96 * | |
97 * @param position the position to check. | |
98 * @return <code>true</code> if this position overlaps with | |
99 * <code>position</code>,<code>false</code> otherwise | |
100 */ | |
101 public bool overlapsWith(LinkedPosition position) { | |
102 return position.getDocument() is fDocument && overlapsWith(position.getOffset(), position.getLength()); | |
103 } | |
104 | |
105 /** | |
106 * Returns whether this position includes <code>event</code>. | |
107 * | |
108 * @param event the event to check. | |
109 * @return <code>true</code> if this position includes <code>event</code>, | |
110 * <code>false</code> otherwise | |
111 */ | |
112 public bool includes(DocumentEvent event) { | |
113 return includes(event.getDocument(), event.getOffset(), event.getLength()); | |
114 } | |
115 | |
116 /** | |
117 * Returns whether this position includes <code>position</code>. | |
118 * | |
119 * @param position the position to check. | |
120 * @return <code>true</code> if this position includes | |
121 * <code>position</code>,<code>false</code> otherwise | |
122 */ | |
123 public bool includes(LinkedPosition position) { | |
124 return includes(position.getDocument(), position.getOffset(), position.getLength()); | |
125 } | |
126 | |
127 /** | |
128 * Overrides {@link Position#includes(int)}so every offset is considered | |
129 * included that lies in between the first and last offset of this position, | |
130 * and offsets that are right at the end of the position. | |
131 * | |
132 * @param pOffset the offset to check | |
133 * @return <code>true</code> if <code>pOffset</code> is in | |
134 * <code>[offset, offset + length]</code> | |
135 */ | |
136 public bool includes(int pOffset) { | |
137 return this.offset <= pOffset && pOffset <= this.offset + this.length; | |
138 } | |
139 | |
140 /** | |
141 * Returns whether this position includes the range given by | |
142 * <code>offset</code> and <code>length</code>. A range is included by | |
143 * a <code>LinkedPosition</code> if {@link #includes(int) includes(offset)} | |
144 * returns true for every offset in the range, including the borders of the | |
145 * range. | |
146 * | |
147 * @param doc the document that the given range refers to, may be <code>null</code> | |
148 * @param off the offset of the range, referring to <code>document</code> | |
149 * @param len the length of the range | |
150 * @return <code>true</code> if <code>doc</code> is the same document as | |
151 * this position refers to, and if the entire range is included in | |
152 * this position | |
153 */ | |
154 protected bool includes(IDocument doc, int off, int len) { | |
155 return doc is fDocument && off >= offset && len + off <= offset + length; | |
156 | |
157 } | |
158 | |
159 /** | |
160 * Returns the content of this position on the referenced document. | |
161 * | |
162 * @return the content of the document at this position | |
163 * @throws BadLocationException if the position is not valid | |
164 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
165 public String getContent() { |
129 | 166 return fDocument.get(offset, length); |
167 } | |
168 | |
169 /** | |
170 * Returns the sequence number of this position. | |
171 * | |
172 * @return the sequence number of this position | |
173 */ | |
174 public int getSequenceNumber() { | |
175 return fSequenceNumber; | |
176 } | |
177 | |
178 /** | |
179 * Sets the sequence number of this position. | |
180 * | |
181 * @param sequence the new sequence number | |
182 */ | |
183 public void setSequenceNumber(int sequence) { | |
184 fSequenceNumber= sequence; | |
185 } | |
186 | |
187 /* | |
188 * @see dwtx.jface.text.Position#hashCode() | |
189 */ | |
160 | 190 public override hash_t toHash() { |
191 return fDocument.toHash() | super.toHash() | fSequenceNumber; | |
129 | 192 } |
193 } |