1 11 package org.eclipse.jdt.internal.ui.text.java.hover; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.graphics.GC; 20 import org.eclipse.swt.graphics.Image; 21 import org.eclipse.swt.graphics.Rectangle; 22 import org.eclipse.swt.widgets.Canvas; 23 24 import org.eclipse.jface.preference.IPreferenceStore; 25 import org.eclipse.jface.viewers.IDoubleClickListener; 26 27 import org.eclipse.jface.text.IDocument; 28 import org.eclipse.jface.text.IInformationControlExtension2; 29 import org.eclipse.jface.text.Position; 30 import org.eclipse.jface.text.source.Annotation; 31 import org.eclipse.jface.text.source.CompositeRuler; 32 import org.eclipse.jface.text.source.IAnnotationAccess; 33 import org.eclipse.jface.text.source.IAnnotationAccessExtension; 34 import org.eclipse.jface.text.source.IAnnotationModel; 35 import org.eclipse.jface.text.source.IAnnotationPresentation; 36 import org.eclipse.jface.text.source.ISourceViewer; 37 import org.eclipse.jface.text.source.ImageUtilities; 38 39 import org.eclipse.ui.texteditor.AnnotationPreference; 40 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup; 41 42 import org.eclipse.jdt.ui.PreferenceConstants; 43 44 import org.eclipse.jdt.internal.ui.JavaPlugin; 45 import org.eclipse.jdt.internal.ui.JavaPluginImages; 46 import org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation; 47 import org.eclipse.jdt.internal.ui.javaeditor.JavaMarkerAnnotation; 48 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.ProblemAnnotation; 49 import org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor; 50 import org.eclipse.jdt.internal.ui.text.java.hover.AnnotationExpansionControl.AnnotationHoverInput; 51 52 57 public class JavaExpandHover extends AnnotationExpandHover { 58 59 60 public static final String NO_BREAKPOINT_ANNOTATION= "org.eclipse.jdt.internal.ui.NoBreakpointAnnotation"; 62 private static class NoBreakpointAnnotation extends Annotation implements IAnnotationPresentation { 63 64 public NoBreakpointAnnotation() { 65 super(NO_BREAKPOINT_ANNOTATION, false, JavaHoverMessages.NoBreakpointAnnotation_addBreakpoint); 66 } 67 68 71 public void paint(GC gc, Canvas canvas, Rectangle bounds) { 72 Image fImage= JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC); 74 ImageUtilities.drawImage(fImage, gc, canvas, bounds, SWT.CENTER); 75 } 76 77 80 public int getLayer() { 81 return IAnnotationPresentation.DEFAULT_LAYER; 82 } 83 } 84 85 private AnnotationPreferenceLookup fLookup= new AnnotationPreferenceLookup(); 86 private IPreferenceStore fStore= JavaPlugin.getDefault().getCombinedPreferenceStore(); 87 88 public JavaExpandHover(CompositeRuler ruler, IAnnotationAccess access, IDoubleClickListener doubleClickListener) { 89 super(ruler, access, doubleClickListener); 90 } 91 92 95 protected Object getHoverInfoForLine(final ISourceViewer viewer, final int line) { 96 final boolean showTemporaryProblems= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION); 97 IAnnotationModel model= viewer.getAnnotationModel(); 98 IDocument document= viewer.getDocument(); 99 100 if (model == null) 101 return null; 102 103 List exact= new ArrayList (); 104 HashMap messagesAtPosition= new HashMap (); 105 106 Iterator e= model.getAnnotationIterator(); 107 while (e.hasNext()) { 108 Annotation annotation= (Annotation) e.next(); 109 110 if (fAnnotationAccess instanceof IAnnotationAccessExtension) 111 if (!((IAnnotationAccessExtension)fAnnotationAccess).isPaintable(annotation)) 112 continue; 113 114 if (annotation instanceof IJavaAnnotation && !isIncluded((IJavaAnnotation)annotation, showTemporaryProblems)) 115 continue; 116 117 AnnotationPreference pref= fLookup.getAnnotationPreference(annotation); 118 if (pref != null) { 119 String key= pref.getVerticalRulerPreferenceKey(); 120 if (key != null && !fStore.getBoolean(key)) 121 continue; 122 } 123 124 Position position= model.getPosition(annotation); 125 if (position == null) 126 continue; 127 128 if (compareRulerLine(position, document, line) == 1) { 129 130 if (isDuplicateMessage(messagesAtPosition, position, annotation.getText())) 131 continue; 132 133 exact.add(annotation); 134 } 135 } 136 137 sort(exact, model); 138 139 if (exact.size() > 0) 140 setLastRulerMouseLocation(viewer, line); 141 142 if (exact.size() > 0) { 143 Annotation first= (Annotation) exact.get(0); 144 if (!isBreakpointAnnotation(first)) 145 exact.add(0, new NoBreakpointAnnotation()); 146 } 147 148 if (exact.size() <= 1) 149 return null; 150 151 AnnotationHoverInput input= new AnnotationHoverInput(); 152 input.fAnnotations= (Annotation[]) exact.toArray(new Annotation[0]); 153 input.fViewer= viewer; 154 input.fRulerInfo= fCompositeRuler; 155 input.fAnnotationListener= fgListener; 156 input.fDoubleClickListener= fDblClickListener; 157 input.redoAction= new AnnotationExpansionControl.ICallback() { 158 159 public void run(IInformationControlExtension2 control) { 160 control.setInput(getHoverInfoForLine(viewer, line)); 161 } 162 163 }; 164 input.model= model; 165 166 return input; 167 } 168 169 private boolean isIncluded(IJavaAnnotation annotation, boolean showTemporaryProblems) { 170 171 if (annotation instanceof ProblemAnnotation && JavaMarkerAnnotation.TASK_ANNOTATION_TYPE.equals(annotation.getType())) 173 return false; 174 175 if (!annotation.isProblem()) 176 return true; 177 178 if (annotation.isMarkedDeleted() && !annotation.hasOverlay()) 179 return true; 180 181 if (annotation.hasOverlay() && !annotation.isMarkedDeleted()) 182 return true; 183 184 185 if (annotation.hasOverlay()) 186 return (!isIncluded(annotation.getOverlay(), showTemporaryProblems)); 187 188 return showTemporaryProblems && JavaCorrectionProcessor.hasCorrections((Annotation)annotation); 189 } 190 191 194 protected int getOrder(Annotation annotation) { 195 if (isBreakpointAnnotation(annotation)) 196 return 1000; 197 else 198 return super.getOrder(annotation); 199 } 200 201 private boolean isBreakpointAnnotation(Annotation a) { 202 if (a instanceof JavaMarkerAnnotation) { 203 JavaMarkerAnnotation jma= (JavaMarkerAnnotation) a; 204 return jma.getType().equals("org.eclipse.debug.core.breakpoint"); } 207 return false; 208 } 209 } 210 | Popular Tags |