Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5db64bc5cd80807e483de419fd8e0fe85b5ab885 (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
/*******************************************************************************
 * Copyright (c) 2000, 2008 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.ui.texteditor;

import org.eclipse.core.runtime.Assert;

import org.eclipse.core.resources.IMarker;

import org.eclipse.jface.text.source.Annotation;

import org.eclipse.ui.internal.editors.text.EditorsPlugin;


/**
 * An annotation representing a marker. This is a model annotation.
 *
 * @see IMarker
 * @since 3.0
 */
public class SimpleMarkerAnnotation extends Annotation {

	private IMarker fMarker;

	/**
	 * Creates a new annotation for the given marker.
	 * @see IMarker
	 *
	 * @param marker the marker
	 */
	public SimpleMarkerAnnotation(IMarker marker) {
		this(EditorsPlugin.getDefault().getAnnotationTypeLookup().getAnnotationType(marker), marker);
	}

	/**
	 * Creates a new annotation of the given type for the given marker.
	 *
	 * @param annotationType the annotation type
	 * @param marker the marker
	 */
	public SimpleMarkerAnnotation(String annotationType, IMarker marker) {
		super(annotationType, true, null);
		Assert.isNotNull(marker);
		fMarker= marker;
	}

	/**
	 * Returns this annotation's underlying marker.
	 *
	 * @return the marker
	 */
	public IMarker getMarker() {
		return fMarker;
	}

	/**
	 * The <code>SimpleMarkerAnnotation</code> implementation of this
	 * <code>Object</code> method returns <code>true</code> iff the other
	 * object is of the same class and the marker handles are equal.
	 *
	 * @see Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object o) {
		if (o != null && o.getClass() == getClass())
			return fMarker.equals(((SimpleMarkerAnnotation) o).fMarker);
		return false;
	}

	@Override
	public int hashCode() {
		return fMarker.hashCode();
	}

	/**
	 * Informs this annotation about changes applied to its underlying marker
	 * and adapts to those changes.
	 * <p>
	 * Subclasses may extend this method.
	 * </p>
	 */
	public void update() {
		updateType();
	}

	/**
	 * Updates the type to be synchronized with its underlying marker.
	 *
	 * @since 3.0
	 */
	private void updateType() {
		String annotationType= EditorsPlugin.getDefault().getAnnotationTypeLookup().getAnnotationType(fMarker);
		if (annotationType != null && !annotationType.equals(getType()))
			setType(annotationType);
	}

	@Override
	public String getText() {
		return MarkerUtilities.getMessage(fMarker);
	}
}

Back to the top