blob: 0988ab60f483b9240406044f19247e4a226a51d2 (
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.text.revisions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.internal.text.revisions.Hunk;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.information.IInformationProviderExtension2;
/**
* Encapsulates revision information for one line-based document.
* <p>
* Clients may instantiate.
* </p>
*
* @since 3.2
* @see Revision
*/
public final class RevisionInformation implements ITextHoverExtension, IInformationProviderExtension2 {
/** The revisions. */
private final List<Revision> fRevisions= new ArrayList<>();
/** A unmodifiable view of <code>fRevisions</code>. */
private final List<Revision> fRORevisions= Collections.unmodifiableList(fRevisions);
/**
* The flattened list of {@link RevisionRange}s, unmodifiable. <code>null</code> if the list
* must be re-computed.
*
* @since 3.3
*/
private List<RevisionRange> fRanges= null;
/**
* The hover control creator. Can be <code>null</code>.
*
* @since 3.3
*/
private IInformationControlCreator fHoverControlCreator;
/**
* The information presenter control creator. Can be <code>null</code>.
*
* @since 3.3
*/
private IInformationControlCreator fInformationPresenterControlCreator;
/**
* Creates a new revision information model.
*/
public RevisionInformation() {
}
/**
* Adds a revision.
*
* @param revision a revision
*/
public void addRevision(Revision revision) {
Assert.isLegal(revision != null);
fRevisions.add(revision);
}
/**
* Returns the contained revisions.
*
* @return an unmodifiable view of the contained revisions
*/
public List<Revision> getRevisions() {
return fRORevisions;
}
/**
* Returns the line ranges of this revision information. The returned information is only valid
* at the moment it is returned, and may change as the annotated document is modified. See
* {@link IRevisionListener} for a way to be informed when the revision information changes. The
* returned list is sorted by document offset.
*
* @return an unmodifiable view of the line ranges
* @see IRevisionListener
* @since 3.3
*/
public List<RevisionRange> getRanges() {
if (fRanges == null) {
List<RevisionRange> ranges= new ArrayList<>(fRevisions.size() * 2); // wild size guess
for (Iterator<Revision> it= fRevisions.iterator(); it.hasNext();) {
Revision revision= it.next();
ranges.addAll(revision.getRegions());
}
// sort by start line
Collections.sort(ranges, (r1, r2) -> r1.getStartLine() - r2.getStartLine());
fRanges= Collections.unmodifiableList(ranges);
}
return fRanges;
}
/**
* Adjusts the revision information to the given diff information. Any previous diff information
* is discarded. <strong>Note:</strong> This is an internal framework method and must not be
* called by clients.
*
* @param hunks the diff hunks to adjust the revision information to
* @since 3.3
* @noreference This method is not intended to be referenced by clients.
*/
public void applyDiff(Hunk[] hunks) {
fRanges= null; // mark for recomputation
for (Iterator<Revision> revisions= getRevisions().iterator(); revisions.hasNext();)
revisions.next().applyDiff(hunks);
}
@Override
public IInformationControlCreator getHoverControlCreator() {
return fHoverControlCreator;
}
/**
* {@inheritDoc}
* @return the information control creator or <code>null</code>
* @since 3.3
*/
@Override
public IInformationControlCreator getInformationPresenterControlCreator() {
return fInformationPresenterControlCreator;
}
/**
* Sets the hover control creator.
* <p>
* <strong>Note:</strong> The created information control must be able to display the object
* returned by the concrete implementation of {@link Revision#getHoverInfo()}.
* </p>
*
* @param creator the control creator
* @since 3.3
*/
public void setHoverControlCreator(IInformationControlCreator creator) {
fHoverControlCreator= creator;
}
/**
* Sets the information presenter control creator.
*
* @param creator the control creator
* @since 3.3
*/
public void setInformationPresenterControlCreator(IInformationControlCreator creator) {
fInformationPresenterControlCreator= creator;
}
}
|