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.phpdt.internal.ui.text.java.hover;
14 import java.util.Iterator;
16 import net.sourceforge.phpdt.ui.PreferenceConstants;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import net.sourceforge.phpeclipse.phpeditor.IJavaAnnotation;
19 import net.sourceforge.phpeclipse.phpeditor.JavaAnnotationIterator;
20 import net.sourceforge.phpeclipse.phpeditor.PHPUnitEditor;
22 import org.eclipse.jface.text.IRegion;
23 import org.eclipse.jface.text.ITextViewer;
24 import org.eclipse.jface.text.Position;
25 import org.eclipse.jface.text.source.Annotation;
26 import org.eclipse.jface.text.source.IAnnotationModel;
27 import org.eclipse.ui.IEditorPart;
28 import org.eclipse.ui.externaltools.internal.ant.editor.derived.HTMLPrinter;
29 import org.eclipse.ui.texteditor.IDocumentProvider;
32 public class JavaProblemHover extends AbstractJavaEditorTextHover {
35 * Formats a message as HTML text.
37 private String formatMessage(String message) {
38 StringBuffer buffer= new StringBuffer();
39 HTMLPrinter.addPageProlog(buffer);
40 HTMLPrinter.addParagraph(buffer, HTMLPrinter.convertToHTMLContent(message));
41 HTMLPrinter.addPageEpilog(buffer);
42 return buffer.toString();
46 * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
48 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
50 if (getEditor() == null)
53 IDocumentProvider provider= PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider();
54 IAnnotationModel model= provider.getAnnotationModel(getEditor().getEditorInput());
57 Iterator e= new JavaAnnotationIterator(model, true);
59 Annotation a= (Annotation) e.next();
60 Position p= model.getPosition(a);
61 if (p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
62 String msg= ((IJavaAnnotation) a).getMessage();
63 if (msg != null && msg.trim().length() > 0)
64 return formatMessage(msg);
73 * @see IJavaEditorTextHover#setEditor(IEditorPart)
75 public void setEditor(IEditorPart editor) {
76 if (editor instanceof PHPUnitEditor)
77 super.setEditor(editor);
79 super.setEditor(null);
82 static boolean isJavaProblemHover(String id) {
83 return PreferenceConstants.ID_PROBLEM_HOVER.equals(id);