Skip to main content
summaryrefslogtreecommitdiffstats
blob: a35e0729dc04194329a6e5bf3d0e5d8460c71275 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.text.reconciler;


import org.eclipse.jface.text.ITypedRegion;

/**
 * A dirty region describes a document range which has been changed.
 */
public class DirtyRegion implements ITypedRegion {
	
	/** 
	 * Identifies an insert operation.
	 */
	final static public String INSERT= "__insert"; //$NON-NLS-1$
	/**
	 * Identifies a remove operation.
	 */
	final static public String REMOVE= "__remove"; //$NON-NLS-1$
	
	/** The region's offset */
	private int fOffset;
	/** The region's length */
	private int fLength;
	/** Indicates the type of the applied change */
	private String fType;
	/** The text which has been inserted */
	private String fText;

	/**
	 * Creates a new dirty region.
	 *
	 * 
	 * @param offset the offset within the document where the change occurred
	 * @param length the length of the text within the document that changed
	 * @param type the type of change that this region represents: <code>INSERT</code> or <code>REMOVE</code>
	 * @param text the substitution text
	 */
	public DirtyRegion(int offset, int length, String type, String text) {
		fOffset= offset;
		fLength= length;
		fType= type;
		fText= text;
	}

	/*
	 * @see ITypedRegion#getOffset()
	 */
	public int getOffset() {
		return fOffset;
	}
	
	/*
	 * @see ITypedRegion#getLength()
	 */
	public int getLength() {
		return fLength;
	}
	
	/*
	 * @see ITypedRegion#getType
	 */
	public String getType() {
		return fType;
	}
	
	/**
	 * Returns the text that changed as part of the region change.
	 * 
	 * @return the changed text
	 */
	public String getText() {
		return fText;
	}
	
	/**
	 * Modify the receiver so that it encompasses the region specified by the dirty region.
	 * 
	 * @param dr the dirty region with which to merge
	 */
	void mergeWith(DirtyRegion dr) {
		int start= Math.min(fOffset, dr.fOffset);
		int end= Math.max(fOffset + fLength, dr.fOffset + dr.fLength);
		fOffset= start;
		fLength= end - start;
		fText= (dr.fText == null ? fText : (fText == null) ? dr.fText : fText + dr.fText);
	}
}

Back to the top