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.reconciler.DirtyRegion;
|
|
14
|
131
|
15 import dwtx.jface.text.reconciler.IReconciler; // packageimport
|
|
16 import dwtx.jface.text.reconciler.DirtyRegionQueue; // packageimport
|
|
17 import dwtx.jface.text.reconciler.IReconcilingStrategy; // packageimport
|
|
18 import dwtx.jface.text.reconciler.AbstractReconcileStep; // packageimport
|
|
19 import dwtx.jface.text.reconciler.IReconcilingStrategyExtension; // packageimport
|
|
20 import dwtx.jface.text.reconciler.MonoReconciler; // packageimport
|
|
21 import dwtx.jface.text.reconciler.IReconcileStep; // packageimport
|
|
22 import dwtx.jface.text.reconciler.AbstractReconciler; // packageimport
|
|
23 import dwtx.jface.text.reconciler.Reconciler; // packageimport
|
|
24 import dwtx.jface.text.reconciler.IReconcilableModel; // packageimport
|
|
25 import dwtx.jface.text.reconciler.IReconcileResult; // packageimport
|
|
26 import dwtx.jface.text.reconciler.IReconcilerExtension; // packageimport
|
|
27
|
|
28
|
129
|
29 import dwt.dwthelper.utils;
|
|
30
|
|
31 import dwtx.jface.text.ITypedRegion;
|
|
32
|
|
33
|
|
34 /**
|
|
35 * A dirty region describes a document range which has been changed.
|
|
36 */
|
|
37 public class DirtyRegion : ITypedRegion {
|
|
38
|
|
39 /**
|
|
40 * Identifies an insert operation.
|
|
41 */
|
|
42 final static public String INSERT= "__insert"; //$NON-NLS-1$
|
|
43 /**
|
|
44 * Identifies a remove operation.
|
|
45 */
|
|
46 final static public String REMOVE= "__remove"; //$NON-NLS-1$
|
|
47
|
|
48 /** The region's offset. */
|
|
49 private int fOffset;
|
|
50 /** The region's length. */
|
|
51 private int fLength;
|
|
52 /** Indicates the type of the applied change. */
|
|
53 private String fType;
|
|
54 /** The text which has been inserted. */
|
|
55 private String fText;
|
|
56
|
|
57 /**
|
|
58 * Creates a new dirty region.
|
|
59 *
|
|
60 * @param offset the offset within the document where the change occurred
|
|
61 * @param length the length of the text within the document that changed
|
|
62 * @param type the type of change that this region represents: {@link #INSERT} {@link #REMOVE}
|
|
63 * @param text the substitution text
|
|
64 */
|
|
65 public DirtyRegion(int offset, int length, String type, String text) {
|
|
66 fOffset= offset;
|
|
67 fLength= length;
|
|
68 fType= normalizeTypeValue(type);
|
|
69 fText= text;
|
|
70 }
|
|
71
|
|
72 /**
|
|
73 * Computes the normalized type value to ensure that the implementation can use object identity rather
|
|
74 * than equality.
|
|
75 *
|
|
76 * @param type the type value
|
|
77 * @return the normalized type value or <code>null</code>
|
|
78 * @since 3.1
|
|
79 */
|
|
80 private String normalizeTypeValue(String type) {
|
|
81 if (INSERT.equals(type))
|
|
82 return INSERT;
|
|
83 if (REMOVE.equals(type))
|
|
84 return REMOVE;
|
|
85 return null;
|
|
86 }
|
|
87
|
|
88 /*
|
|
89 * @see ITypedRegion#getOffset()
|
|
90 */
|
|
91 public int getOffset() {
|
|
92 return fOffset;
|
|
93 }
|
|
94
|
|
95 /*
|
|
96 * @see ITypedRegion#getLength()
|
|
97 */
|
|
98 public int getLength() {
|
|
99 return fLength;
|
|
100 }
|
|
101
|
|
102 /*
|
|
103 * @see ITypedRegion#getType
|
|
104 */
|
|
105 public String getType() {
|
|
106 return fType;
|
|
107 }
|
|
108
|
|
109 /**
|
|
110 * Returns the text that changed as part of the region change.
|
|
111 *
|
|
112 * @return the changed text
|
|
113 */
|
|
114 public String getText() {
|
|
115 return fText;
|
|
116 }
|
|
117
|
|
118 /**
|
|
119 * Modify the receiver so that it encompasses the region specified by the dirty region.
|
|
120 *
|
|
121 * @param dr the dirty region with which to merge
|
|
122 */
|
|
123 void mergeWith(DirtyRegion dr) {
|
|
124 int start= Math.min(fOffset, dr.fOffset);
|
|
125 int end= Math.max(fOffset + fLength, dr.fOffset + dr.fLength);
|
|
126 fOffset= start;
|
|
127 fLength= end - start;
|
|
128 fText= (dr.fText is null ? fText : (fText is null) ? dr.fText : fText + dr.fText);
|
|
129 }
|
|
130 }
|