1 11 12 package org.eclipse.jdt.internal.ui.javaeditor; 13 14 15 import java.util.Iterator ; 16 17 import org.eclipse.core.resources.IMarker; 18 19 import org.eclipse.ui.texteditor.MarkerAnnotation; 20 import org.eclipse.ui.texteditor.MarkerUtilities; 21 22 import org.eclipse.jdt.core.CorrectionEngine; 23 import org.eclipse.jdt.core.ICompilationUnit; 24 import org.eclipse.jdt.core.IJavaElement; 25 import org.eclipse.jdt.core.IJavaModelMarker; 26 import org.eclipse.jdt.core.JavaCore; 27 28 29 30 public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation { 31 32 public static final String JAVA_MARKER_TYPE_PREFIX= "org.eclipse.jdt"; public static final String ERROR_ANNOTATION_TYPE= "org.eclipse.jdt.ui.error"; public static final String WARNING_ANNOTATION_TYPE= "org.eclipse.jdt.ui.warning"; public static final String INFO_ANNOTATION_TYPE= "org.eclipse.jdt.ui.info"; public static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; 38 private IJavaAnnotation fOverlay; 39 40 41 public JavaMarkerAnnotation(IMarker marker) { 42 super(marker); 43 } 44 45 48 public String [] getArguments() { 49 IMarker marker= getMarker(); 50 if (marker != null && marker.exists() && isProblem()) 51 return CorrectionEngine.getProblemArguments(marker); 52 return null; 53 } 54 55 58 public int getId() { 59 IMarker marker= getMarker(); 60 if (marker == null || !marker.exists()) 61 return -1; 62 63 if (isProblem()) 64 return marker.getAttribute(IJavaModelMarker.ID, -1); 65 66 76 return -1; 77 } 78 79 82 public boolean isProblem() { 83 String type= getType(); 84 return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type); 85 } 86 87 92 public void setOverlay(IJavaAnnotation javaAnnotation) { 93 if (fOverlay != null) 94 fOverlay.removeOverlaid(this); 95 96 fOverlay= javaAnnotation; 97 if (!isMarkedDeleted()) 98 markDeleted(fOverlay != null); 99 100 if (fOverlay != null) 101 fOverlay.addOverlaid(this); 102 } 103 104 107 public boolean hasOverlay() { 108 return fOverlay != null; 109 } 110 111 114 public IJavaAnnotation getOverlay() { 115 return fOverlay; 116 } 117 118 121 public void addOverlaid(IJavaAnnotation annotation) { 122 } 124 125 128 public void removeOverlaid(IJavaAnnotation annotation) { 129 } 131 132 135 public Iterator getOverlaidIterator() { 136 return null; 138 } 139 140 143 public ICompilationUnit getCompilationUnit() { 144 IJavaElement element= JavaCore.create(getMarker().getResource()); 145 if (element instanceof ICompilationUnit) { 146 return (ICompilationUnit)element; 147 } 148 return null; 149 } 150 151 154 public String getMarkerType() { 155 IMarker marker= getMarker(); 156 if (marker == null || !marker.exists()) 157 return null; 158 159 return MarkerUtilities.getMarkerType(getMarker()); 160 } 161 } 162 | Popular Tags |