Skip to content

Commit

Permalink
AnnotationModel uses both fAnnotations and getAnnotationMap()
Browse files Browse the repository at this point in the history
(Fixes eclipse-platform#19)

AnnotationModel.fAnnotations is deprecated and getAnnotationMap() should
be used instead.

However I still see the code that uses AnnotationModel.fAnnotations
inside AnnotationModel, even together with the getAnnotationMap(). This
should be fixed as precondition to fix of inefficient map iterations
inside same class.

eclipse-platform#19
  • Loading branch information
iloveeclipse committed May 6, 2022
1 parent 119d01a commit 3e6937a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.text/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.text
Bundle-Version: 3.12.0.qualifier
Bundle-Version: 3.12.100.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,11 @@ protected void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extend
* @throws BadLocationException if the position is not a valid document position
*/
protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException {
if (!fAnnotations.containsKey(annotation)) {
IAnnotationMap annotations= getAnnotationMap();
if (!annotations.containsKey(annotation)) {

addPosition(fDocument, position);
fAnnotations.put(annotation, position);
annotations.put(annotation, position);
fPositions.put(position, annotation);
synchronized (getLockObject()) {
getAnnotationModelEvent().annotationAdded(annotation);
Expand Down Expand Up @@ -640,9 +641,10 @@ private void cleanup(boolean fireModelChanged, boolean forkNotification) {

ArrayList<Annotation> deleted= new ArrayList<>();
Iterator<Annotation> e= getAnnotationMap().keySetIterator();
IAnnotationMap annotations= getAnnotationMap();
while (e.hasNext()) {
Annotation a= e.next();
Position p= fAnnotations.get(a);
Position p= annotations.get(a);
if (p == null || p.isDeleted())
deleted.add(a);
}
Expand Down Expand Up @@ -763,7 +765,7 @@ protected Iterator<Annotation> getAnnotationIterator(boolean cleanup) {

@Override
public Position getPosition(Annotation annotation) {
Position position= fAnnotations.get(annotation);
Position position= getAnnotationMap().get(annotation);
if (position != null)
return position;

Expand All @@ -785,12 +787,12 @@ public void removeAllAnnotations() {
* @param fireModelChanged indicates whether to notify all model listeners
*/
protected void removeAllAnnotations(boolean fireModelChanged) {

IAnnotationMap annotations= getAnnotationMap();
if (fDocument != null) {
Iterator<Annotation> e= getAnnotationMap().keySetIterator();
while (e.hasNext()) {
Annotation a= e.next();
Position p= fAnnotations.get(a);
Position p= annotations.get(a);
removePosition(fDocument, p);
// p.delete();
synchronized (getLockObject()) {
Expand All @@ -799,7 +801,7 @@ protected void removeAllAnnotations(boolean fireModelChanged) {
}
}

fAnnotations.clear();
annotations.clear();
fPositions.clear();

if (fireModelChanged)
Expand All @@ -819,16 +821,17 @@ public void removeAnnotation(Annotation annotation) {
* @param fireModelChanged indicates whether to notify all model listeners
*/
protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) {
if (fAnnotations.containsKey(annotation)) {
IAnnotationMap annotations= getAnnotationMap();
if (annotations.containsKey(annotation)) {

Position p= null;
p= fAnnotations.get(annotation);
p= annotations.get(annotation);
if (fDocument != null) {
removePosition(fDocument, p);
// p.delete();
}

fAnnotations.remove(annotation);
annotations.remove(annotation);
fPositions.remove(p);
synchronized (getLockObject()) {
getAnnotationModelEvent().annotationRemoved(annotation, p);
Expand Down Expand Up @@ -864,7 +867,7 @@ protected void modifyAnnotationPosition(Annotation annotation, Position position
if (position == null) {
removeAnnotation(annotation, fireModelChanged);
} else {
Position p= fAnnotations.get(annotation);
Position p= getAnnotationMap().get(annotation);
if (p != null) {

if (position.getOffset() != p.getOffset() || position.getLength() != p.getLength()) {
Expand Down Expand Up @@ -905,7 +908,7 @@ protected void modifyAnnotationPosition(Annotation annotation, Position position
* @since 3.0
*/
protected void modifyAnnotation(Annotation annotation, boolean fireModelChanged) {
if (fAnnotations.containsKey(annotation)) {
if (getAnnotationMap().containsKey(annotation)) {
synchronized (getLockObject()) {
getAnnotationModelEvent().annotationChanged(annotation);
}
Expand Down

0 comments on commit 3e6937a

Please sign in to comment.