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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
15 import java.util.Iterator;
17 import org.eclipse.core.resources.IMarker;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.ui.texteditor.MarkerAnnotation;
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;
29 import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil;
33 public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation {
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$
41 private IJavaAnnotation fOverlay;
44 public JavaMarkerAnnotation(IMarker marker) {
49 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getImage(org.eclipse.swt.widgets.Display)
51 public Image getImage(Display display) {
52 return super.getImage(display);
56 * @see IJavaAnnotation#getArguments()
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$
66 * @see IJavaAnnotation#getId()
69 IMarker marker= getMarker();
70 if (marker == null || !marker.exists())
74 return marker.getAttribute(IJavaModelMarker.ID, -1);
76 // if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
78 // if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
79 // return IProblem.Task;
81 // } catch (CoreException e) {
82 // JavaPlugin.log(e); // should no happen, we test for marker.exists
90 * @see IJavaAnnotation#isProblem()
92 public boolean isProblem() {
93 String type= getType();
94 return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
98 * Overlays this annotation with the given javaAnnotation.
100 * @param javaAnnotation annotation that is overlaid by this annotation
102 public void setOverlay(IJavaAnnotation javaAnnotation) {
103 if (fOverlay != null)
104 fOverlay.removeOverlaid(this);
106 fOverlay= javaAnnotation;
107 if (!isMarkedDeleted())
108 markDeleted(fOverlay != null);
110 if (fOverlay != null)
111 fOverlay.addOverlaid(this);
115 * @see IJavaAnnotation#hasOverlay()
117 public boolean hasOverlay() {
118 return fOverlay != null;
122 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
124 public IJavaAnnotation getOverlay() {
129 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
131 public void addOverlaid(IJavaAnnotation annotation) {
136 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
138 public void removeOverlaid(IJavaAnnotation annotation) {
143 * @see IJavaAnnotation#getOverlaidIterator()
145 public Iterator getOverlaidIterator() {
151 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
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) {