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
|
/*******************************************************************************
* Copyright (c) 2000, 2004 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.ui.texteditor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.core.resources.IMarker;
/**
* Updates a marker's positional attributes which are
* start position, end position, and line number.
*/
public final class BasicMarkerUpdater implements IMarkerUpdater {
private final static String[] ATTRIBUTES= {
IMarker.CHAR_START,
IMarker.CHAR_END,
IMarker.LINE_NUMBER
};
/**
* Creates a new basic marker updater.
*/
public BasicMarkerUpdater() {
super();
}
/*
* @see IMarkerUpdater#getAttribute()
*/
public String[] getAttribute() {
return ATTRIBUTES;
}
/*
* @see IMarkerUpdater#getMarkerType()
*/
public String getMarkerType() {
return null;
}
/*
* @see IMarkerUpdater#updateMarker(IMarker, IDocument, Position)
*/
public boolean updateMarker(IMarker marker, IDocument document, Position position) {
if (position == null)
return true;
if (position.isDeleted())
return false;
boolean offsetsInitialized= false;
boolean offsetsChanged= false;
int markerStart= MarkerUtilities.getCharStart(marker);
int markerEnd= MarkerUtilities.getCharEnd(marker);
if (markerStart != -1 && markerEnd != -1) {
offsetsInitialized= true;
int offset= position.getOffset();
if (markerStart != offset) {
MarkerUtilities.setCharStart(marker, offset);
offsetsChanged= true;
}
offset += position.getLength();
if (markerEnd != offset) {
MarkerUtilities.setCharEnd(marker, offset);
offsetsChanged= true;
}
}
if (!offsetsInitialized || (offsetsChanged && MarkerUtilities.getLineNumber(marker) != -1)) {
try {
// marker line numbers are 1-based
MarkerUtilities.setLineNumber(marker, document.getLineOfOffset(position.getOffset()) + 1);
} catch (BadLocationException x) {
}
}
return true;
}
}
|