blob: d9cb80f4800e11968af369235d179074430c7432 (
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.text;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.core.runtime.Assert;
/**
* Event describing the change of document partitionings.
*
* @see org.eclipse.jface.text.IDocumentExtension3
* @since 3.0
*/
public class DocumentPartitioningChangedEvent {
/** The document whose partitionings changed */
private final IDocument fDocument;
/** The map of partitionings to changed regions. */
private final Map<String, Region> fMap= new HashMap<>();
/**
* Creates a new document partitioning changed event for the given document.
* Initially this event is empty, i.e. does not describe any change.
*
* @param document the changed document
*/
public DocumentPartitioningChangedEvent(IDocument document) {
fDocument= document;
}
/**
* Returns the changed document.
*
* @return the changed document
*/
public IDocument getDocument() {
return fDocument;
}
/**
* Returns the changed region of the given partitioning or <code>null</code>
* if the given partitioning did not change.
*
* @param partitioning the partitioning
* @return the changed region of the given partitioning or <code>null</code>
*/
public IRegion getChangedRegion(String partitioning) {
return fMap.get(partitioning);
}
/**
* Returns the set of changed partitionings.
*
* @return the set of changed partitionings
*/
public String[] getChangedPartitionings() {
String[] partitionings= new String[fMap.size()];
fMap.keySet().toArray(partitionings);
return partitionings;
}
/**
* Sets the specified range as changed region for the given partitioning.
*
* @param partitioning the partitioning
* @param offset the region offset
* @param length the region length
*/
public void setPartitionChange(String partitioning, int offset, int length) {
Assert.isNotNull(partitioning);
fMap.put(partitioning, new Region(offset, length));
}
/**
* Returns <code>true</code> if the set of changed partitionings is empty,
* <code>false</code> otherwise.
*
* @return <code>true</code> if the set of changed partitionings is empty
*/
public boolean isEmpty() {
return fMap.isEmpty();
}
/**
* Returns the coverage of this event. This is the minimal region that
* contains all changed regions of all changed partitionings.
*
* @return the coverage of this event
*/
public IRegion getCoverage() {
if (fMap.isEmpty())
return new Region(0, 0);
int offset= -1;
int endOffset= -1;
Iterator<Region> e= fMap.values().iterator();
while (e.hasNext()) {
IRegion r= e.next();
if (offset < 0 || r.getOffset() < offset)
offset= r.getOffset();
int end= r.getOffset() + r.getLength();
if (end > endOffset)
endOffset= end;
}
return new Region(offset, endOffset - offset);
}
}
|