upload tizen1.0 source
[sdk/ide/product.git] / org.eclipse.cdt.ui / src / org / eclipse / cdt / internal / ui / editor / CMarkerAnnotation.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *     QNX Software System
11  *     Anton Leherbauer (Wind River Systems)
12  *******************************************************************************/
13 package org.eclipse.cdt.internal.ui.editor;
14
15 import java.util.Iterator;
16
17 import org.eclipse.core.resources.IMarker;
18 import org.eclipse.ui.texteditor.MarkerAnnotation;
19 import org.eclipse.ui.texteditor.MarkerUtilities;
20
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;
25
26
27 public class CMarkerAnnotation extends MarkerAnnotation implements IProblemAnnotation, ICAnnotation {           
28
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$
34
35         private boolean fIsProblemMarker;
36
37         private ICAnnotation fOverlay;
38
39         public CMarkerAnnotation(IMarker marker) {
40                 super(marker);
41                 fIsProblemMarker = MarkerUtilities.isMarkerType(getMarker(), IMarker.PROBLEM); 
42         }
43
44         /**
45          * @see IProblemAnnotation#getMessage()
46          */
47         public String getMessage() {
48                 if (fIsProblemMarker)
49                         return getMarker().getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
50                 return ""; //$NON-NLS-1$
51         }
52
53         /**
54          * @see IProblemAnnotation#isError()
55          */
56         public boolean isError() {
57                 if (fIsProblemMarker) {
58                         int markerSeverity= getMarker().getAttribute(IMarker.SEVERITY, -1);
59                         return (markerSeverity == IMarker.SEVERITY_ERROR);
60                 }
61                 return false;
62         }
63
64         /**
65          * @see IProblemAnnotation#isWarning()
66          */
67         public boolean isWarning() {
68                 if (fIsProblemMarker) {
69                         int markerSeverity= getMarker().getAttribute(IMarker.SEVERITY, -1);
70                         return (markerSeverity == IMarker.SEVERITY_WARNING);
71                 }
72                 return false;
73         }
74         
75         /**
76          * @see IProblemAnnotation#isTemporaryProblem()
77          */
78         public boolean isTemporaryProblem() {
79                 return false;
80         }
81         
82         /**
83          * @see IProblemAnnotation#getArguments()
84          */
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));
89                 return s;
90                 //returnm null;
91         }
92
93         /**
94          * @see IProblemAnnotation#getId()
95          */
96         public int getId() {
97                 if (fIsProblemMarker)
98                         return getMarker().getAttribute(ICModelMarker.C_MODEL_PROBLEM_MARKER, -1);
99                 return 0;
100         }
101         
102         /*
103          * @see org.eclipse.cdt.internal.ui.editor.IProblemAnnotation#isProblem()
104          */
105         public boolean isProblem() {
106                 return fIsProblemMarker;
107         }
108         
109         /**
110          * Overlays this annotation with the given cAnnotation.
111          * 
112          * @param cAnnotation annotation that is overlaid by this annotation
113          */
114         public void setOverlay(ICAnnotation cAnnotation) {
115                 if (fOverlay != null)
116                         fOverlay.removeOverlaid(this);
117                         
118                 fOverlay= cAnnotation;
119                 if (!isMarkedDeleted())
120                         markDeleted(fOverlay != null);
121                 
122                 if (fOverlay != null)
123                         fOverlay.addOverlaid(this);
124         }
125
126         /*
127          * @see ICAnnotation#hasOverlay()
128          */
129         public boolean hasOverlay() {
130                 return fOverlay != null;
131         }
132         
133         /*
134          * @see org.eclipse.cdt.internal.ui.editor.ICAnnotation#getOverlay()
135          */
136         public ICAnnotation getOverlay() {
137                 return fOverlay;
138         }
139         
140         /*
141          * @see ICAnnotation#addOverlaid(ICAnnotation)
142          */
143         public void addOverlaid(ICAnnotation annotation) {
144                 // not supported
145         }
146
147         /*
148          * @see ICAnnotation#removeOverlaid(ICAnnotation)
149          */
150         public void removeOverlaid(ICAnnotation annotation) {
151                 // not supported
152         }
153         
154         /*
155          * @see ICAnnotation#getOverlaidIterator()
156          */
157         public Iterator<ICAnnotation> getOverlaidIterator() {
158                 // not supported
159                 return null;
160         }
161
162         /* (non-Javadoc)
163          * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
164          */
165         public ITranslationUnit getTranslationUnit() {
166                 ICElement element= CoreModel.getDefault().create(getMarker().getResource());
167                 if (element instanceof ITranslationUnit) {
168                         return (ITranslationUnit)element;
169                 }
170                 return null;
171         }
172
173         public String getMarkerType() {
174                 IMarker marker= getMarker();
175                 if (marker == null || !marker.exists())
176                         return null;
177                 
178                 return MarkerUtilities.getMarkerType(getMarker());
179         }
180 }