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 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text;
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.core.JavaModelException;
15 import net.sourceforge.phpdt.internal.ui.actions.SelectionConverter;
16 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
18 import org.eclipse.jface.text.IRegion;
19 import org.eclipse.jface.text.ITextViewer;
20 import org.eclipse.jface.text.Region;
21 import org.eclipse.jface.text.information.IInformationProvider;
22 import org.eclipse.jface.text.information.IInformationProviderExtension;
23 import org.eclipse.jface.viewers.IStructuredSelection;
24 import org.eclipse.ui.IEditorPart;
27 * Provides a Java element to be displayed in by an information presenter.
29 public class JavaElementProvider implements IInformationProvider,
30 IInformationProviderExtension {
32 private PHPEditor fEditor;
34 private boolean fUseCodeResolve;
36 public JavaElementProvider(IEditorPart editor) {
37 fUseCodeResolve = false;
38 if (editor instanceof PHPEditor)
39 fEditor = (PHPEditor) editor;
42 public JavaElementProvider(IEditorPart editor, boolean useCodeResolve) {
44 fUseCodeResolve = useCodeResolve;
48 * @see IInformationProvider#getSubject(ITextViewer, int)
50 public IRegion getSubject(ITextViewer textViewer, int offset) {
51 if (textViewer != null && fEditor != null) {
52 IRegion region = JavaWordFinder.findWord(textViewer.getDocument(),
57 return new Region(offset, 0);
63 * @see IInformationProvider#getInformation(ITextViewer, IRegion)
65 public String getInformation(ITextViewer textViewer, IRegion subject) {
66 return getInformation2(textViewer, subject).toString();
70 * @see IInformationProviderExtension#getElement(ITextViewer, IRegion)
72 public Object getInformation2(ITextViewer textViewer, IRegion subject) {
77 if (fUseCodeResolve) {
78 IStructuredSelection sel = SelectionConverter
79 .getStructuredSelection(fEditor);
81 return sel.getFirstElement();
83 IJavaElement element = SelectionConverter
84 .getElementAtOffset(fEditor);
87 return SelectionConverter.getInput(fEditor);
88 } catch (JavaModelException e) {