improved PHP parser
[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 net.sourceforge.phpdt.core.ICompilationUnit;
18 import net.sourceforge.phpdt.core.IJavaElement;
19 import net.sourceforge.phpdt.core.IJavaModelMarker;
20 import net.sourceforge.phpdt.core.JavaCore;
21 import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil;
22
23 import org.eclipse.core.resources.IMarker;
24 import org.eclipse.swt.graphics.Image;
25 import org.eclipse.swt.widgets.Display;
26 import org.eclipse.ui.texteditor.MarkerAnnotation;
27
28
29
30 public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation {
31
32         public static final String JAVA_MARKER_TYPE_PREFIX= "net.sourceforge.phpdt"; //$NON-NLS-1$
33         public static final String ERROR_ANNOTATION_TYPE= "net.sourceforge.phpdt.ui.error"; //$NON-NLS-1$
34         public static final String WARNING_ANNOTATION_TYPE= "net.sourceforge.phpdt.ui.warning"; //$NON-NLS-1$
35         public static final String INFO_ANNOTATION_TYPE= "net.sourceforge.phpdt.ui.info"; //$NON-NLS-1$
36         public static final String 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 net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getImage(org.eclipse.swt.widgets.Display)
47          */
48         public Image getImage(Display display) {
49                 return super.getImage(display);
50         }
51         
52         /*
53          * @see IJavaAnnotation#getArguments()
54          */
55         public String[] getArguments() {
56                 IMarker marker= getMarker();
57                 if (marker != null && marker.exists() && isProblem())
58                         return JavaModelUtil.getProblemArgumentsFromMarker(marker.getAttribute(IJavaModelMarker.ARGUMENTS, "")); //$NON-NLS-1$
59                 return null;
60         }
61
62         /*
63          * @see IJavaAnnotation#getId()
64          */
65         public int getId() {
66                 IMarker marker= getMarker();
67                 if (marker == null  || !marker.exists())
68                         return -1;
69                 
70                 if (isProblem())
71                         return marker.getAttribute(IJavaModelMarker.ID, -1);
72                         
73 //              if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
74 //                      try {
75 //                              if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
76 //                                      return IProblem.Task;
77 //                              }
78 //                      } catch (CoreException e) {
79 //                              JavaPlugin.log(e); // should no happen, we test for marker.exists
80 //                      }
81 //              }
82                 
83                 return -1;
84         }
85         
86         /*
87          * @see IJavaAnnotation#isProblem()
88          */
89         public boolean isProblem() {
90                 String type= getType();
91                 return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
92         }
93
94         /**
95          * Overlays this annotation with the given javaAnnotation.
96          * 
97          * @param javaAnnotation annotation that is overlaid by this annotation
98          */
99         public void setOverlay(IJavaAnnotation javaAnnotation) {
100                 if (fOverlay != null)
101                         fOverlay.removeOverlaid(this);
102                         
103                 fOverlay= javaAnnotation;
104                 if (!isMarkedDeleted())
105                         markDeleted(fOverlay != null);
106                 
107                 if (fOverlay != null)
108                         fOverlay.addOverlaid(this);
109         }
110         
111         /*
112          * @see IJavaAnnotation#hasOverlay()
113          */
114         public boolean hasOverlay() {
115                 return fOverlay != null;
116         }
117         
118         /*
119          * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
120          */
121         public IJavaAnnotation getOverlay() {
122                 return fOverlay;
123         }
124         
125         /*
126          * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
127          */
128         public void addOverlaid(IJavaAnnotation annotation) {
129                 // not supported
130         }
131
132         /*
133          * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
134          */
135         public void removeOverlaid(IJavaAnnotation annotation) {
136                 // not supported
137         }
138         
139         /*
140          * @see IJavaAnnotation#getOverlaidIterator()
141          */
142         public Iterator getOverlaidIterator() {
143                 // not supported
144                 return null;
145         }
146
147         /* (non-Javadoc)
148          * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
149          */
150         public ICompilationUnit getCompilationUnit() {
151                 IJavaElement element= JavaCore.create(getMarker().getResource());
152                 if (element instanceof ICompilationUnit) {
153                         ICompilationUnit cu= (ICompilationUnit)element;
154                         ICompilationUnit workingCopy= EditorUtility.getWorkingCopy(cu);
155                         if (workingCopy != null) {
156                                 return workingCopy;
157                         }
158                         return cu;
159                 }
160                 return null;
161         }
162 }