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;
14 import java.util.Iterator;
16 import net.sourceforge.phpdt.core.ICompilationUnit;
17 import net.sourceforge.phpdt.core.IJavaElement;
18 import net.sourceforge.phpdt.core.IJavaModelMarker;
19 import net.sourceforge.phpdt.core.JavaCore;
20 import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil;
22 import org.eclipse.core.resources.IMarker;
23 import org.eclipse.swt.graphics.Image;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.ui.texteditor.MarkerAnnotation;
27 public class JavaMarkerAnnotation extends MarkerAnnotation implements
30 public static final String JAVA_MARKER_TYPE_PREFIX = "net.sourceforge.phpdt"; //$NON-NLS-1$
32 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$
36 public static final String INFO_ANNOTATION_TYPE = "net.sourceforge.phpdt.ui.info"; //$NON-NLS-1$
38 public static final String TASK_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$
40 private IJavaAnnotation fOverlay;
42 public JavaMarkerAnnotation(IMarker marker) {
47 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getImage(org.eclipse.swt.widgets.Display)
49 public Image getImage(Display display) {
50 return super.getImage(display);
54 * @see IJavaAnnotation#getArguments()
56 public String[] getArguments() {
57 IMarker marker = getMarker();
58 if (marker != null && marker.exists() && isProblem())
59 return JavaModelUtil.getProblemArgumentsFromMarker(marker
60 .getAttribute(IJavaModelMarker.ARGUMENTS, "")); //$NON-NLS-1$
65 * @see IJavaAnnotation#getId()
68 IMarker marker = getMarker();
69 if (marker == null || !marker.exists())
73 return marker.getAttribute(IJavaModelMarker.ID, -1);
75 // if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
77 // if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
78 // return IProblem.Task;
80 // } catch (CoreException e) {
81 // JavaPlugin.log(e); // should no happen, we test for marker.exists
89 * @see IJavaAnnotation#isProblem()
91 public boolean isProblem() {
92 String type = getType();
93 return WARNING_ANNOTATION_TYPE.equals(type)
94 || ERROR_ANNOTATION_TYPE.equals(type);
98 * Overlays this annotation with the given javaAnnotation.
100 * @param javaAnnotation
101 * annotation that is overlaid by this annotation
103 public void setOverlay(IJavaAnnotation javaAnnotation) {
104 if (fOverlay != null)
105 fOverlay.removeOverlaid(this);
107 fOverlay = javaAnnotation;
108 if (!isMarkedDeleted())
109 markDeleted(fOverlay != null);
111 if (fOverlay != null)
112 fOverlay.addOverlaid(this);
116 * @see IJavaAnnotation#hasOverlay()
118 public boolean hasOverlay() {
119 return fOverlay != null;
123 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
125 public IJavaAnnotation getOverlay() {
130 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
132 public void addOverlaid(IJavaAnnotation annotation) {
137 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
139 public void removeOverlaid(IJavaAnnotation annotation) {
144 * @see IJavaAnnotation#getOverlaidIterator()
146 public Iterator getOverlaidIterator() {
154 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
156 public ICompilationUnit getCompilationUnit() {
157 IJavaElement element = JavaCore.create(getMarker().getResource());
158 if (element instanceof ICompilationUnit) {
159 ICompilationUnit cu = (ICompilationUnit) element;
160 ICompilationUnit workingCopy = EditorUtility.getWorkingCopy(cu);
161 if (workingCopy != null) {