65b7e5de98f1b6578aca7ca20defce300694d7c3
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / JavaMarkerAnnotation.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpeclipse.phpeditor;
13
14
15 import java.util.Iterator;
16
17 import org.eclipse.core.resources.IMarker;
18
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.widgets.Display;
21
22 import org.eclipse.ui.texteditor.MarkerAnnotation;
23
24 import net.sourceforge.phpdt.core.ICompilationUnit;
25 import net.sourceforge.phpdt.core.IJavaElement;
26 import net.sourceforge.phpdt.core.IJavaModelMarker;
27 import net.sourceforge.phpdt.core.JavaCore;
28
29 import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil;
30
31
32
33 public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation {
34
35         public static final String JAVA_MARKER_TYPE_PREFIX= "org.eclipse.jdt"; //$NON-NLS-1$
36         public static final String ERROR_ANNOTATION_TYPE= "org.eclipse.jdt.ui.error"; //$NON-NLS-1$
37         public static final String WARNING_ANNOTATION_TYPE= "org.eclipse.jdt.ui.warning"; //$NON-NLS-1$
38         public static final String INFO_ANNOTATION_TYPE= "org.eclipse.jdt.ui.info"; //$NON-NLS-1$
39         public static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$
40
41         private IJavaAnnotation fOverlay;
42         
43         
44         public JavaMarkerAnnotation(IMarker marker) {
45                 super(marker);
46         }
47         
48         /*
49          * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getImage(org.eclipse.swt.widgets.Display)
50          */
51         public Image getImage(Display display) {
52                 return super.getImage(display);
53         }
54         
55         /*
56          * @see IJavaAnnotation#getArguments()
57          */
58         public String[] getArguments() {
59                 IMarker marker= getMarker();
60                 if (marker != null && marker.exists() && isProblem())
61                         return JavaModelUtil.getProblemArgumentsFromMarker(marker.getAttribute(IJavaModelMarker.ARGUMENTS, "")); //$NON-NLS-1$
62                 return null;
63         }
64
65         /*
66          * @see IJavaAnnotation#getId()
67          */
68         public int getId() {
69                 IMarker marker= getMarker();
70                 if (marker == null  || !marker.exists())
71                         return -1;
72                 
73                 if (isProblem())
74                         return marker.getAttribute(IJavaModelMarker.ID, -1);
75                         
76 //              if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
77 //                      try {
78 //                              if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
79 //                                      return IProblem.Task;
80 //                              }
81 //                      } catch (CoreException e) {
82 //                              JavaPlugin.log(e); // should no happen, we test for marker.exists
83 //                      }
84 //              }
85                 
86                 return -1;
87         }
88         
89         /*
90          * @see IJavaAnnotation#isProblem()
91          */
92         public boolean isProblem() {
93                 String type= getType();
94                 return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
95         }
96
97         /**
98          * Overlays this annotation with the given javaAnnotation.
99          * 
100          * @param javaAnnotation annotation that is overlaid by this annotation
101          */
102         public void setOverlay(IJavaAnnotation javaAnnotation) {
103                 if (fOverlay != null)
104                         fOverlay.removeOverlaid(this);
105                         
106                 fOverlay= javaAnnotation;
107                 if (!isMarkedDeleted())
108                         markDeleted(fOverlay != null);
109                 
110                 if (fOverlay != null)
111                         fOverlay.addOverlaid(this);
112         }
113         
114         /*
115          * @see IJavaAnnotation#hasOverlay()
116          */
117         public boolean hasOverlay() {
118                 return fOverlay != null;
119         }
120         
121         /*
122          * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
123          */
124         public IJavaAnnotation getOverlay() {
125                 return fOverlay;
126         }
127         
128         /*
129          * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
130          */
131         public void addOverlaid(IJavaAnnotation annotation) {
132                 // not supported
133         }
134
135         /*
136          * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
137          */
138         public void removeOverlaid(IJavaAnnotation annotation) {
139                 // not supported
140         }
141         
142         /*
143          * @see IJavaAnnotation#getOverlaidIterator()
144          */
145         public Iterator getOverlaidIterator() {
146                 // not supported
147                 return null;
148         }
149
150         /* (non-Javadoc)
151          * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
152          */
153         public ICompilationUnit getCompilationUnit() {
154                 IJavaElement element= JavaCore.create(getMarker().getResource());
155                 if (element instanceof ICompilationUnit) {
156                         ICompilationUnit cu= (ICompilationUnit)element;
157                         ICompilationUnit workingCopy= EditorUtility.getWorkingCopy(cu);
158                         if (workingCopy != null) {
159                                 return workingCopy;
160                         }
161                         return cu;
162                 }
163                 return null;
164         }
165 }