KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > JavaMarkerAnnotation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.javaeditor;
13
14
15 import java.util.Iterator JavaDoc;
16
17 import org.eclipse.core.resources.IMarker;
18
19 import org.eclipse.ui.texteditor.MarkerAnnotation;
20 import org.eclipse.ui.texteditor.MarkerUtilities;
21
22 import org.eclipse.jdt.core.CorrectionEngine;
23 import org.eclipse.jdt.core.ICompilationUnit;
24 import org.eclipse.jdt.core.IJavaElement;
25 import org.eclipse.jdt.core.IJavaModelMarker;
26 import org.eclipse.jdt.core.JavaCore;
27
28
29
30 public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation {
31
32     public static final String JavaDoc JAVA_MARKER_TYPE_PREFIX= "org.eclipse.jdt"; //$NON-NLS-1$
33
public static final String JavaDoc ERROR_ANNOTATION_TYPE= "org.eclipse.jdt.ui.error"; //$NON-NLS-1$
34
public static final String JavaDoc WARNING_ANNOTATION_TYPE= "org.eclipse.jdt.ui.warning"; //$NON-NLS-1$
35
public static final String JavaDoc INFO_ANNOTATION_TYPE= "org.eclipse.jdt.ui.info"; //$NON-NLS-1$
36
public static final String JavaDoc TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$
37

38     private IJavaAnnotation fOverlay;
39
40
41     public JavaMarkerAnnotation(IMarker marker) {
42         super(marker);
43     }
44
45     /*
46      * @see IJavaAnnotation#getArguments()
47      */

48     public String JavaDoc[] getArguments() {
49         IMarker marker= getMarker();
50         if (marker != null && marker.exists() && isProblem())
51             return CorrectionEngine.getProblemArguments(marker);
52         return null;
53     }
54
55     /*
56      * @see IJavaAnnotation#getId()
57      */

58     public int getId() {
59         IMarker marker= getMarker();
60         if (marker == null || !marker.exists())
61             return -1;
62
63         if (isProblem())
64             return marker.getAttribute(IJavaModelMarker.ID, -1);
65
66 // if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
67
// try {
68
// if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
69
// return IProblem.Task;
70
// }
71
// } catch (CoreException e) {
72
// JavaPlugin.log(e); // should no happen, we test for marker.exists
73
// }
74
// }
75

76         return -1;
77     }
78
79     /*
80      * @see IJavaAnnotation#isProblem()
81      */

82     public boolean isProblem() {
83         String JavaDoc type= getType();
84         return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
85     }
86
87     /**
88      * Overlays this annotation with the given javaAnnotation.
89      *
90      * @param javaAnnotation annotation that is overlaid by this annotation
91      */

92     public void setOverlay(IJavaAnnotation javaAnnotation) {
93         if (fOverlay != null)
94             fOverlay.removeOverlaid(this);
95
96         fOverlay= javaAnnotation;
97         if (!isMarkedDeleted())
98             markDeleted(fOverlay != null);
99
100         if (fOverlay != null)
101             fOverlay.addOverlaid(this);
102     }
103
104     /*
105      * @see IJavaAnnotation#hasOverlay()
106      */

107     public boolean hasOverlay() {
108         return fOverlay != null;
109     }
110
111     /*
112      * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
113      */

114     public IJavaAnnotation getOverlay() {
115         return fOverlay;
116     }
117
118     /*
119      * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
120      */

121     public void addOverlaid(IJavaAnnotation annotation) {
122         // not supported
123
}
124
125     /*
126      * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
127      */

128     public void removeOverlaid(IJavaAnnotation annotation) {
129         // not supported
130
}
131
132     /*
133      * @see IJavaAnnotation#getOverlaidIterator()
134      */

135     public Iterator JavaDoc getOverlaidIterator() {
136         // not supported
137
return null;
138     }
139
140     /* (non-Javadoc)
141      * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
142      */

143     public ICompilationUnit getCompilationUnit() {
144         IJavaElement element= JavaCore.create(getMarker().getResource());
145         if (element instanceof ICompilationUnit) {
146             return (ICompilationUnit)element;
147         }
148         return null;
149     }
150
151     /* (non-Javadoc)
152      * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getMarkerType()
153      */

154     public String JavaDoc getMarkerType() {
155         IMarker marker= getMarker();
156         if (marker == null || !marker.exists())
157             return null;
158         
159         return MarkerUtilities.getMarkerType(getMarker());
160     }
161 }
162
Popular Tags