Eclipse 3M7
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / JavaMarkerAnnotation.java
index 64905c4..65b7e5d 100644 (file)
@@ -14,46 +14,31 @@ package net.sourceforge.phpeclipse.phpeditor;
 
 import java.util.Iterator;
 
-import net.sourceforge.phpdt.internal.ui.PHPUiImages;
-import net.sourceforge.phpdt.ui.PreferenceConstants;
-import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-
 import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.debug.core.model.IBreakpoint;
-import org.eclipse.debug.ui.DebugUITools;
-import org.eclipse.debug.ui.IDebugModelPresentation;
-import org.eclipse.jface.resource.ImageRegistry;
-import org.eclipse.jface.text.Assert;
-import org.eclipse.search.ui.SearchUI;
-import org.eclipse.swt.SWT;
+
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
+
 import org.eclipse.ui.texteditor.MarkerAnnotation;
-import org.eclipse.ui.texteditor.MarkerUtilities;
+
+import net.sourceforge.phpdt.core.ICompilationUnit;
+import net.sourceforge.phpdt.core.IJavaElement;
+import net.sourceforge.phpdt.core.IJavaModelMarker;
+import net.sourceforge.phpdt.core.JavaCore;
+
+import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil;
 
 
 
 public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation {
-       
-       private static final int NO_IMAGE= 0;
-       private static final int ORIGINAL_MARKER_IMAGE= 1;
-       private static final int QUICKFIX_IMAGE= 2;
-       private static final int QUICKFIX_ERROR_IMAGE= 3;
-       private static final int OVERLAY_IMAGE= 4;
-       private static final int GRAY_IMAGE= 5;
-       private static final int BREAKPOINT_IMAGE= 6;
 
-       private static Image fgQuickFixImage;
-       private static Image fgQuickFixErrorImage;
-       private static ImageRegistry fgGrayMarkersImageRegistry;
-       
-       private IDebugModelPresentation fPresentation;
+       public static final String JAVA_MARKER_TYPE_PREFIX= "org.eclipse.jdt"; //$NON-NLS-1$
+       public static final String ERROR_ANNOTATION_TYPE= "org.eclipse.jdt.ui.error"; //$NON-NLS-1$
+       public static final String WARNING_ANNOTATION_TYPE= "org.eclipse.jdt.ui.warning"; //$NON-NLS-1$
+       public static final String INFO_ANNOTATION_TYPE= "org.eclipse.jdt.ui.info"; //$NON-NLS-1$
+       public static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$
+
        private IJavaAnnotation fOverlay;
-       private boolean fNotRelevant= false;
-       private AnnotationType fType;
-       private int fImageType;
-       private boolean fQuickFixIconEnabled;
        
        
        public JavaMarkerAnnotation(IMarker marker) {
@@ -61,95 +46,10 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot
        }
        
        /*
-        * @see MarkerAnnotation#getUnknownImageName(IMarker)
-        */
-       protected String getUnknownImageName(IMarker marker) {
-               return PHPUiImages.IMG_OBJS_GHOST;
-       }
-       
-       /**
-        * Initializes the annotation's icon representation and its drawing layer
-        * based upon the properties of the underlying marker.
-        */
-       protected void initialize() {
-               fQuickFixIconEnabled= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
-               fImageType= NO_IMAGE;
-               IMarker marker= getMarker();
-               
-               if (MarkerUtilities.isMarkerType(marker, IBreakpoint.BREAKPOINT_MARKER)) {
-                       
-                       if (fPresentation == null) 
-                               fPresentation= DebugUITools.newDebugModelPresentation();
-
-                       setImage(null); // see bug 32469
-                       setLayer(4);
-                       fImageType= BREAKPOINT_IMAGE;                                   
-                       
-                       fType= AnnotationType.UNKNOWN;
-                       
-               } else {
-                       
-                       fType= AnnotationType.UNKNOWN;
-                       if (marker.exists()) {
-                               try {
-                                       
-                                       if (marker.isSubtypeOf(IMarker.PROBLEM)) {
-                                               int severity= marker.getAttribute(IMarker.SEVERITY, -1);
-                                               switch (severity) {
-                                                       case IMarker.SEVERITY_ERROR:
-                                                               fType= AnnotationType.ERROR;
-                                                               break;
-                                                       case IMarker.SEVERITY_WARNING:
-                                                               fType= AnnotationType.WARNING;
-                                                               break;
-                                               }
-                                       } else if (marker.isSubtypeOf(IMarker.TASK))
-                                               fType= AnnotationType.TASK; 
-                                       else if (marker.isSubtypeOf(SearchUI.SEARCH_MARKER)) 
-                                               fType= AnnotationType.SEARCH;
-                                       else if (marker.isSubtypeOf(IMarker.BOOKMARK))
-                                               fType= AnnotationType.BOOKMARK;
-                                               
-                               } catch(CoreException e) {
-                                       PHPeclipsePlugin.log(e);
-                               }
-                       }
-                       super.initialize();
-               }
-       }
-       
-//     private boolean mustShowQuickFixIcon() {
-//             return fQuickFixIconEnabled && JavaCorrectionProcessor.hasCorrections(getMarker());
-//     }
-//     
-//     private Image getQuickFixImage() {
-//             if (fgQuickFixImage == null)
-//                     fgQuickFixImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
-//             return fgQuickFixImage;
-//     }
-//
-//     private Image getQuickFixErrorImage() {
-//             if (fgQuickFixErrorImage == null)
-//                     fgQuickFixErrorImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
-//             return fgQuickFixErrorImage;
-//     }
-
-       /*
-        * @see IJavaAnnotation#getMessage()
-        */
-       public String getMessage() {
-               IMarker marker= getMarker();
-               if (marker == null || !marker.exists())
-                       return ""; //$NON-NLS-1$
-               else
-                       return marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
-       }
-
-       /*
-        * @see IJavaAnnotation#isTemporary()
+        * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getImage(org.eclipse.swt.widgets.Display)
         */
-       public boolean isTemporary() {
-               return false;
+       public Image getImage(Display display) {
+               return super.getImage(display);
        }
        
        /*
@@ -157,8 +57,8 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot
         */
        public String[] getArguments() {
                IMarker marker= getMarker();
-//             if (marker != null && marker.exists() && isProblem())
-//                     return Util.getProblemArgumentsFromMarker(marker.getAttribute(IJavaModelMarker.ARGUMENTS, "")); //$NON-NLS-1$
+               if (marker != null && marker.exists() && isProblem())
+                       return JavaModelUtil.getProblemArgumentsFromMarker(marker.getAttribute(IJavaModelMarker.ARGUMENTS, "")); //$NON-NLS-1$
                return null;
        }
 
@@ -167,8 +67,22 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot
         */
        public int getId() {
                IMarker marker= getMarker();
-//             if (marker != null  && marker.exists() && isProblem())
-//                     return marker.getAttribute(IJavaModelMarker.ID, -1);
+               if (marker == null  || !marker.exists())
+                       return -1;
+               
+               if (isProblem())
+                       return marker.getAttribute(IJavaModelMarker.ID, -1);
+                       
+//             if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
+//                     try {
+//                             if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
+//                                     return IProblem.Task;
+//                             }
+//                     } catch (CoreException e) {
+//                             JavaPlugin.log(e); // should no happen, we test for marker.exists
+//                     }
+//             }
+               
                return -1;
        }
        
@@ -176,14 +90,8 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot
         * @see IJavaAnnotation#isProblem()
         */
        public boolean isProblem() {
-               return fType == AnnotationType.WARNING || fType == AnnotationType.ERROR;
-       }
-       
-       /*
-        * @see IJavaAnnotation#isRelevant()
-        */
-       public boolean isRelevant() {
-               return !fNotRelevant;
+               String type= getType();
+               return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type);
        }
 
        /**
@@ -196,10 +104,11 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot
                        fOverlay.removeOverlaid(this);
                        
                fOverlay= javaAnnotation;
-               fNotRelevant= (fNotRelevant || fOverlay != null);
+               if (!isMarkedDeleted())
+                       markDeleted(fOverlay != null);
                
-               if (javaAnnotation != null)
-                       javaAnnotation.addOverlaid(this);
+               if (fOverlay != null)
+                       fOverlay.addOverlaid(this);
        }
        
        /*
@@ -210,84 +119,10 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot
        }
        
        /*
-        * @see MarkerAnnotation#getImage(Display)
+        * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
         */
-       public Image getImage(Display display) {
-               if (fImageType == BREAKPOINT_IMAGE) {
-                       Image result= super.getImage(display);
-                       if (result == null) {
-                               IMarker marker= getMarker();
-                               if (marker != null && marker.exists()) {
-                                       result= fPresentation.getImage(getMarker());
-                                       setImage(result);
-                               }
-                       }                                       
-                       return result;
-               }
-
-               int newImageType= NO_IMAGE;
-
-               if (hasOverlay())
-                       newImageType= OVERLAY_IMAGE;
-               else if (isRelevant()) {
-//                     if (mustShowQuickFixIcon()) {
-//                             if (fType == AnnotationType.ERROR)
-//                                     newImageType= QUICKFIX_ERROR_IMAGE;
-//                             else
-//                                     newImageType= QUICKFIX_IMAGE; 
-//                     } else
-                               newImageType= ORIGINAL_MARKER_IMAGE; 
-               } else
-                       newImageType= GRAY_IMAGE;
-
-               if (fImageType == newImageType && newImageType != OVERLAY_IMAGE)
-                       // Nothing changed - simply return the current image
-                       return super.getImage(display);
-
-               Image newImage= null;
-               switch (newImageType) {
-                       case ORIGINAL_MARKER_IMAGE:
-                               newImage= null;
-                               break;
-                       case OVERLAY_IMAGE:
-                               newImage= fOverlay.getImage(display);
-                               break;
-//                     case QUICKFIX_IMAGE:
-//                             newImage= getQuickFixImage();
-//                             break;
-//                     case QUICKFIX_ERROR_IMAGE:
-//                             newImage= getQuickFixErrorImage();
-//                             break;
-                       case GRAY_IMAGE:
-                               if (fImageType != ORIGINAL_MARKER_IMAGE)
-                                       setImage(null);
-                               Image originalImage= super.getImage(display);
-                               if (originalImage != null) {
-                                       ImageRegistry imageRegistry= getGrayMarkerImageRegistry(display);
-                                       if (imageRegistry != null) {
-                                               String key= Integer.toString(originalImage.hashCode());
-                                               Image grayImage= imageRegistry.get(key);
-                                               if (grayImage == null) {
-                                                       grayImage= new Image(display, originalImage, SWT.IMAGE_GRAY);
-                                                       imageRegistry.put(key, grayImage);
-                                               }
-                                               newImage= grayImage;
-                                       }
-                               }
-                               break;
-                       default:
-                               Assert.isLegal(false);
-               }
-
-               fImageType= newImageType;
-               setImage(newImage);
-               return super.getImage(display);
-       }
-       
-       private ImageRegistry getGrayMarkerImageRegistry(Display display) {
-               if (fgGrayMarkersImageRegistry == null)
-                       fgGrayMarkersImageRegistry= new ImageRegistry(display);
-               return fgGrayMarkersImageRegistry;
+       public IJavaAnnotation getOverlay() {
+               return fOverlay;
        }
        
        /*
@@ -311,11 +146,20 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot
                // not supported
                return null;
        }
-       
-       /*
-        * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getAnnotationType()
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
         */
-       public AnnotationType getAnnotationType() {
-               return fType;
+       public ICompilationUnit getCompilationUnit() {
+               IJavaElement element= JavaCore.create(getMarker().getResource());
+               if (element instanceof ICompilationUnit) {
+                       ICompilationUnit cu= (ICompilationUnit)element;
+                       ICompilationUnit workingCopy= EditorUtility.getWorkingCopy(cu);
+                       if (workingCopy != null) {
+                               return workingCopy;
+                       }
+                       return cu;
+               }
+               return null;
        }
 }