1 /*******************************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
11 * Anton Leherbauer (Wind River Systems)
12 *******************************************************************************/
13 package org.eclipse.cdt.internal.ui.editor;
15 import java.util.Iterator;
17 import org.eclipse.core.resources.IMarker;
18 import org.eclipse.ui.texteditor.MarkerAnnotation;
19 import org.eclipse.ui.texteditor.MarkerUtilities;
21 import org.eclipse.cdt.core.model.CoreModel;
22 import org.eclipse.cdt.core.model.ICElement;
23 import org.eclipse.cdt.core.model.ICModelMarker;
24 import org.eclipse.cdt.core.model.ITranslationUnit;
27 public class CMarkerAnnotation extends MarkerAnnotation implements IProblemAnnotation, ICAnnotation {
29 public static final String C_MARKER_TYPE_PREFIX= "org.eclipse.cdt"; //$NON-NLS-1$
30 public static final String ERROR_ANNOTATION_TYPE= "org.eclipse.cdt.ui.error"; //$NON-NLS-1$
31 public static final String WARNING_ANNOTATION_TYPE= "org.eclipse.cdt.ui.warning"; //$NON-NLS-1$
32 public static final String INFO_ANNOTATION_TYPE= "org.eclipse.cdt.ui.info"; //$NON-NLS-1$
33 public static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$
35 private boolean fIsProblemMarker;
37 private ICAnnotation fOverlay;
39 public CMarkerAnnotation(IMarker marker) {
41 fIsProblemMarker = MarkerUtilities.isMarkerType(getMarker(), IMarker.PROBLEM);
45 * @see IProblemAnnotation#getMessage()
47 public String getMessage() {
49 return getMarker().getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
50 return ""; //$NON-NLS-1$
54 * @see IProblemAnnotation#isError()
56 public boolean isError() {
57 if (fIsProblemMarker) {
58 int markerSeverity= getMarker().getAttribute(IMarker.SEVERITY, -1);
59 return (markerSeverity == IMarker.SEVERITY_ERROR);
65 * @see IProblemAnnotation#isWarning()
67 public boolean isWarning() {
68 if (fIsProblemMarker) {
69 int markerSeverity= getMarker().getAttribute(IMarker.SEVERITY, -1);
70 return (markerSeverity == IMarker.SEVERITY_WARNING);
76 * @see IProblemAnnotation#isTemporaryProblem()
78 public boolean isTemporaryProblem() {
83 * @see IProblemAnnotation#getArguments()
85 public String[] getArguments() {
86 String [] s = {"problem", "here"}; //$NON-NLS-1$ //$NON-NLS-2$
87 //if (fIsProblemMarker)
88 // return Util.getProblemArgumentsFromMarker(getMarker().getAttribute(CCorePlugin.C_PROBLEMMARKER));
94 * @see IProblemAnnotation#getId()
98 return getMarker().getAttribute(ICModelMarker.C_MODEL_PROBLEM_MARKER, -1);
103 * @see org.eclipse.cdt.internal.ui.editor.IProblemAnnotation#isProblem()
105 public boolean isProblem() {
106 return fIsProblemMarker;
110 * Overlays this annotation with the given cAnnotation.
112 * @param cAnnotation annotation that is overlaid by this annotation
114 public void setOverlay(ICAnnotation cAnnotation) {
115 if (fOverlay != null)
116 fOverlay.removeOverlaid(this);
118 fOverlay= cAnnotation;
119 if (!isMarkedDeleted())
120 markDeleted(fOverlay != null);
122 if (fOverlay != null)
123 fOverlay.addOverlaid(this);
127 * @see ICAnnotation#hasOverlay()
129 public boolean hasOverlay() {
130 return fOverlay != null;
134 * @see org.eclipse.cdt.internal.ui.editor.ICAnnotation#getOverlay()
136 public ICAnnotation getOverlay() {
141 * @see ICAnnotation#addOverlaid(ICAnnotation)
143 public void addOverlaid(ICAnnotation annotation) {
148 * @see ICAnnotation#removeOverlaid(ICAnnotation)
150 public void removeOverlaid(ICAnnotation annotation) {
155 * @see ICAnnotation#getOverlaidIterator()
157 public Iterator<ICAnnotation> getOverlaidIterator() {
163 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
165 public ITranslationUnit getTranslationUnit() {
166 ICElement element= CoreModel.getDefault().create(getMarker().getResource());
167 if (element instanceof ITranslationUnit) {
168 return (ITranslationUnit)element;
173 public String getMarkerType() {
174 IMarker marker= getMarker();
175 if (marker == null || !marker.exists())
178 return MarkerUtilities.getMarkerType(getMarker());