comparison dwtx/jface/text/DefaultTextHover.d @ 136:6dcb0baaa031

Regex removal of throws decls, some instanceof
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 02:20:40 +0200
parents 51e6e63f930e
children f70d9508c95c
comparison
equal deleted inserted replaced
135:65801ad2b265 136:6dcb0baaa031
164 import dwtx.jface.text.source.ISourceViewer; 164 import dwtx.jface.text.source.ISourceViewer;
165 import dwtx.jface.text.source.ISourceViewerExtension2; 165 import dwtx.jface.text.source.ISourceViewerExtension2;
166 166
167 /** 167 /**
168 * Standard implementation of {@link dwtx.jface.text.ITextHover}. 168 * Standard implementation of {@link dwtx.jface.text.ITextHover}.
169 * 169 *
170 * @since 3.2 170 * @since 3.2
171 */ 171 */
172 public class DefaultTextHover : ITextHover { 172 public class DefaultTextHover : ITextHover {
173 173
174 /** This hover's source viewer */ 174 /** This hover's source viewer */
175 private ISourceViewer fSourceViewer; 175 private ISourceViewer fSourceViewer;
176 176
177 /** 177 /**
178 * Creates a new annotation hover. 178 * Creates a new annotation hover.
179 * 179 *
180 * @param sourceViewer this hover's annotation model 180 * @param sourceViewer this hover's annotation model
181 */ 181 */
182 public this(ISourceViewer sourceViewer) { 182 public this(ISourceViewer sourceViewer) {
183 Assert.isNotNull(sourceViewer); 183 Assert.isNotNull(sourceViewer);
184 fSourceViewer= sourceViewer; 184 fSourceViewer= sourceViewer;
185 } 185 }
186 186
187 /* 187 /*
188 * @see dwtx.jface.text.ITextHover#getHoverInfo(dwtx.jface.text.ITextViewer, dwtx.jface.text.IRegion) 188 * @see dwtx.jface.text.ITextHover#getHoverInfo(dwtx.jface.text.ITextViewer, dwtx.jface.text.IRegion)
189 */ 189 */
190 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { 190 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
191 IAnnotationModel model= getAnnotationModel(fSourceViewer); 191 IAnnotationModel model= getAnnotationModel(fSourceViewer);
192 if (model is null) 192 if (model is null)
193 return null; 193 return null;
194 194
195 Iterator e= model.getAnnotationIterator(); 195 Iterator e= model.getAnnotationIterator();
196 while (e.hasNext()) { 196 while (e.hasNext()) {
197 Annotation a= cast(Annotation) e.next(); 197 Annotation a= cast(Annotation) e.next();
198 if (isIncluded(a)) { 198 if (isIncluded(a)) {
199 Position p= model.getPosition(a); 199 Position p= model.getPosition(a);
202 if (msg !is null && msg.trim().length() > 0) 202 if (msg !is null && msg.trim().length() > 0)
203 return msg; 203 return msg;
204 } 204 }
205 } 205 }
206 } 206 }
207 207
208 return null; 208 return null;
209 } 209 }
210 210
211 /* 211 /*
212 * @see dwtx.jface.text.ITextHover#getHoverRegion(dwtx.jface.text.ITextViewer, int) 212 * @see dwtx.jface.text.ITextHover#getHoverRegion(dwtx.jface.text.ITextViewer, int)
213 */ 213 */
214 public IRegion getHoverRegion(ITextViewer textViewer, int offset) { 214 public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
215 return findWord(textViewer.getDocument(), offset); 215 return findWord(textViewer.getDocument(), offset);
216 } 216 }
217 217
218 /** 218 /**
219 * Tells whether the annotation should be included in 219 * Tells whether the annotation should be included in
220 * the computation. 220 * the computation.
221 * 221 *
222 * @param annotation the annotation to test 222 * @param annotation the annotation to test
223 * @return <code>true</code> if the annotation is included in the computation 223 * @return <code>true</code> if the annotation is included in the computation
224 */ 224 */
225 protected bool isIncluded(Annotation annotation) { 225 protected bool isIncluded(Annotation annotation) {
226 return true; 226 return true;
227 } 227 }
228 228
229 private IAnnotationModel getAnnotationModel(ISourceViewer viewer) { 229 private IAnnotationModel getAnnotationModel(ISourceViewer viewer) {
230 if (viewer instanceof ISourceViewerExtension2) { 230 if (cast(ISourceViewerExtension2)viewer ) {
231 ISourceViewerExtension2 extension= cast(ISourceViewerExtension2) viewer; 231 ISourceViewerExtension2 extension= cast(ISourceViewerExtension2) viewer;
232 return extension.getVisualAnnotationModel(); 232 return extension.getVisualAnnotationModel();
233 } 233 }
234 return viewer.getAnnotationModel(); 234 return viewer.getAnnotationModel();
235 } 235 }
236 236
237 private IRegion findWord(IDocument document, int offset) { 237 private IRegion findWord(IDocument document, int offset) {
238 int start= -2; 238 int start= -2;
239 int end= -1; 239 int end= -1;
240 240
241 try { 241 try {