129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2005 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.ILineTracker;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18 /**
|
|
19 * A line tracker maps character positions to line numbers and vice versa.
|
|
20 * Initially the line tracker is informed about its underlying text in order to
|
|
21 * initialize the mapping information. After that, the line tracker is informed
|
|
22 * about all changes of the underlying text allowing for incremental updates of
|
|
23 * the mapping information. It is the client's responsibility to actively inform
|
|
24 * the line tacker about text changes. For example, when using a line tracker in
|
|
25 * combination with a document the document controls the line tracker.
|
|
26 * <p>
|
|
27 * In order to provide backward compatibility for clients of <code>ILineTracker</code>, extension
|
|
28 * interfaces are used to provide a means of evolution. The following extension interfaces
|
|
29 * exist:
|
|
30 * <ul>
|
|
31 * <li> {@link dwtx.jface.text.ILineTrackerExtension} since version 3.1 introducing the concept
|
|
32 * of rewrite sessions.</li>
|
|
33 * </ul>
|
|
34 * <p>
|
|
35 * Clients may implement this interface or use the standard implementation
|
|
36 * </p>
|
|
37 * {@link dwtx.jface.text.DefaultLineTracker}or
|
|
38 * {@link dwtx.jface.text.ConfigurableLineTracker}.
|
|
39 */
|
|
40 public interface ILineTracker {
|
|
41
|
|
42 /**
|
|
43 * Returns the strings this tracker considers as legal line delimiters.
|
|
44 *
|
|
45 * @return the legal line delimiters
|
|
46 */
|
|
47 String[] getLegalLineDelimiters();
|
|
48
|
|
49 /**
|
|
50 * Returns the line delimiter of the specified line. Returns <code>null</code> if the
|
|
51 * line is not closed with a line delimiter.
|
|
52 *
|
|
53 * @param line the line whose line delimiter is queried
|
|
54 * @return the line's delimiter or <code>null</code> if line does not have a delimiter
|
|
55 * @exception BadLocationException if the line number is invalid in this tracker's line structure
|
|
56 */
|
|
57 String getLineDelimiter(int line) throws BadLocationException;
|
|
58
|
|
59 /**
|
|
60 * Computes the number of lines in the given text.
|
|
61 *
|
|
62 * @param text the text whose number of lines should be computed
|
|
63 * @return the number of lines in the given text
|
|
64 */
|
|
65 int computeNumberOfLines(String text);
|
|
66
|
|
67 /**
|
|
68 * Returns the number of lines.
|
|
69 *
|
|
70 * @return the number of lines in this tracker's line structure
|
|
71 */
|
|
72 int getNumberOfLines();
|
|
73
|
|
74 /**
|
|
75 * Returns the number of lines which are occupied by a given text range.
|
|
76 *
|
|
77 * @param offset the offset of the specified text range
|
|
78 * @param length the length of the specified text range
|
|
79 * @return the number of lines occupied by the specified range
|
|
80 * @exception BadLocationException if specified range is unknown to this tracker
|
|
81 */
|
|
82 int getNumberOfLines(int offset, int length) throws BadLocationException;
|
|
83
|
|
84 /**
|
|
85 * Returns the position of the first character of the specified line.
|
|
86 *
|
|
87 * @param line the line of interest
|
|
88 * @return offset of the first character of the line
|
|
89 * @exception BadLocationException if the line is unknown to this tracker
|
|
90 */
|
|
91 int getLineOffset(int line) throws BadLocationException;
|
|
92
|
|
93 /**
|
|
94 * Returns length of the specified line including the line's delimiter.
|
|
95 *
|
|
96 * @param line the line of interest
|
|
97 * @return the length of the line
|
|
98 * @exception BadLocationException if line is unknown to this tracker
|
|
99 */
|
|
100 int getLineLength(int line) throws BadLocationException;
|
|
101
|
|
102 /**
|
|
103 * Returns the line number the character at the given offset belongs to.
|
|
104 *
|
|
105 * @param offset the offset whose line number to be determined
|
|
106 * @return the number of the line the offset is on
|
|
107 * @exception BadLocationException if the offset is invalid in this tracker
|
|
108 */
|
|
109 int getLineNumberOfOffset(int offset) throws BadLocationException;
|
|
110
|
|
111 /**
|
|
112 * Returns a line description of the line at the given offset.
|
|
113 * The description contains the start offset and the length of the line
|
|
114 * excluding the line's delimiter.
|
|
115 *
|
|
116 * @param offset the offset whose line should be described
|
|
117 * @return a region describing the line
|
|
118 * @exception BadLocationException if offset is invalid in this tracker
|
|
119 */
|
|
120 IRegion getLineInformationOfOffset(int offset) throws BadLocationException;
|
|
121
|
|
122 /**
|
|
123 * Returns a line description of the given line. The description
|
|
124 * contains the start offset and the length of the line excluding the line's
|
|
125 * delimiter.
|
|
126 *
|
|
127 * @param line the line that should be described
|
|
128 * @return a region describing the line
|
|
129 * @exception BadLocationException if line is unknown to this tracker
|
|
130 */
|
|
131 IRegion getLineInformation(int line) throws BadLocationException;
|
|
132
|
|
133 /**
|
|
134 * Informs the line tracker about the specified change in the tracked text.
|
|
135 *
|
|
136 * @param offset the offset of the replaced text
|
|
137 * @param length the length of the replaced text
|
|
138 * @param text the substitution text
|
|
139 * @exception BadLocationException if specified range is unknown to this tracker
|
|
140 */
|
|
141 void replace(int offset, int length, String text) throws BadLocationException;
|
|
142
|
|
143 /**
|
|
144 * Sets the tracked text to the specified text.
|
|
145 *
|
|
146 * @param text the new tracked text
|
|
147 */
|
|
148 void set(String text);
|
|
149 }
|