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;
14 import net.sourceforge.phpdt.core.IJavaElement;
15 import net.sourceforge.phpdt.core.JavaModelException;
16 import net.sourceforge.phpdt.internal.ui.actions.SelectionConverter;
17 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
19 import org.eclipse.jface.text.IRegion;
20 import org.eclipse.jface.text.ITextViewer;
21 import org.eclipse.jface.text.Region;
22 import org.eclipse.jface.text.information.IInformationProvider;
23 import org.eclipse.jface.text.information.IInformationProviderExtension;
24 import org.eclipse.jface.viewers.IStructuredSelection;
25 import org.eclipse.ui.IEditorPart;
30 * Provides a Java element to be displayed in by an information presenter.
32 public class JavaElementProvider implements IInformationProvider, IInformationProviderExtension {
34 private PHPEditor fEditor;
35 private boolean fUseCodeResolve;
37 public JavaElementProvider(IEditorPart editor) {
38 fUseCodeResolve= false;
39 if (editor instanceof PHPEditor)
40 fEditor= (PHPEditor)editor;
43 public JavaElementProvider(IEditorPart editor, boolean useCodeResolve) {
45 fUseCodeResolve= useCodeResolve;
49 * @see IInformationProvider#getSubject(ITextViewer, int)
51 public IRegion getSubject(ITextViewer textViewer, int offset) {
52 if (textViewer != null && fEditor != null) {
53 IRegion region= JavaWordFinder.findWord(textViewer.getDocument(), offset);
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.getStructuredSelection(fEditor);
80 return sel.getFirstElement();
82 IJavaElement element= SelectionConverter.getElementAtOffset(fEditor);
85 return SelectionConverter.getInput(fEditor);
86 } catch (JavaModelException e) {