1 /*******************************************************************************
2 * Copyright (c) 2000, 2012 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.text.java.hover;
13 import org.eclipse.jface.text.IInformationControlCreator;
14 import org.eclipse.jface.text.IRegion;
15 import org.eclipse.jface.text.ITextViewer;
16 import org.eclipse.jface.text.information.IInformationProvider;
17 import org.eclipse.jface.text.information.IInformationProviderExtension;
18 import org.eclipse.jface.text.information.IInformationProviderExtension2;
20 import org.eclipse.ui.IEditorPart;
22 import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
25 public class JavaInformationProvider implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 {
27 protected BestMatchHover fImplementation;
29 public JavaInformationProvider(IEditorPart editor) {
31 fImplementation= new BestMatchHover();
32 fImplementation.setEditor(editor);
37 * @see IInformationProvider#getSubject(ITextViewer, int)
39 public IRegion getSubject(ITextViewer textViewer, int offset) {
41 if (textViewer != null)
42 return JavaWordFinder.findWord(textViewer.getDocument(), offset);
48 * @see IInformationProvider#getInformation(ITextViewer, IRegion)
51 public String getInformation(ITextViewer textViewer, IRegion subject) {
52 if (fImplementation != null) {
53 String s= fImplementation.getHoverInfo(textViewer, subject);
54 if (s != null && s.trim().length() > 0) {
62 * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
64 public Object getInformation2(ITextViewer textViewer, IRegion subject) {
65 if (fImplementation == null)
67 return fImplementation.getHoverInfo2(textViewer, subject, true);
71 * @see IInformationProviderExtension2#getInformationPresenterControlCreator()
74 public IInformationControlCreator getInformationPresenterControlCreator() {
75 if (fImplementation == null)
77 return fImplementation.getInformationPresenterControlCreator();