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 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;
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;
30 public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation {
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$
38 private IJavaAnnotation fOverlay;
41 public JavaMarkerAnnotation(IMarker marker) {
46 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getImage(org.eclipse.swt.widgets.Display)
48 public Image getImage(Display display) {
49 return super.getImage(display);
53 * @see IJavaAnnotation#getArguments()
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$
63 * @see IJavaAnnotation#getId()
66 IMarker marker= getMarker();
67 if (marker == null || !marker.exists())
71 return marker.getAttribute(IJavaModelMarker.ID, -1);
73 // if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
75 // if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
76 // return IProblem.Task;
78 // } catch (CoreException e) {
79 // JavaPlugin.log(e); // should no happen, we test for marker.exists
87 * @see IJavaAnnotation#isProblem()
89 public boolean isProblem() {
90 String type= getType();
91 return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
95 * Overlays this annotation with the given javaAnnotation.
97 * @param javaAnnotation annotation that is overlaid by this annotation
99 public void setOverlay(IJavaAnnotation javaAnnotation) {
100 if (fOverlay != null)
101 fOverlay.removeOverlaid(this);
103 fOverlay= javaAnnotation;
104 if (!isMarkedDeleted())
105 markDeleted(fOverlay != null);
107 if (fOverlay != null)
108 fOverlay.addOverlaid(this);
112 * @see IJavaAnnotation#hasOverlay()
114 public boolean hasOverlay() {
115 return fOverlay != null;
119 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
121 public IJavaAnnotation getOverlay() {
126 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
128 public void addOverlaid(IJavaAnnotation annotation) {
133 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
135 public void removeOverlaid(IJavaAnnotation annotation) {
140 * @see IJavaAnnotation#getOverlaidIterator()
142 public Iterator getOverlaidIterator() {
148 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
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) {