]>
Commit | Line | Data |
---|---|---|
1 | /******************************************************************************* | |
2 | * Copyright (c) 2000, 2010 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 | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.ui.text; | |
12 | ||
13 | ||
14 | import org.eclipse.jface.text.IRegion; | |
15 | import org.eclipse.jface.text.ITextViewer; | |
16 | import org.eclipse.jface.text.Region; | |
17 | import org.eclipse.jface.text.information.IInformationProvider; | |
18 | import org.eclipse.jface.text.information.IInformationProviderExtension; | |
19 | ||
20 | import org.eclipse.ui.IEditorPart; | |
21 | ||
22 | import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; | |
23 | ||
24 | /** | |
25 | * Provides a Java element to be displayed in by an information presenter. | |
26 | */ | |
27 | public class JavaElementProvider implements IInformationProvider, IInformationProviderExtension { | |
28 | ||
29 | public JavaEditor fEditor; | |
30 | public boolean fUseCodeResolve; | |
31 | ||
32 | public JavaElementProvider(IEditorPart editor) { | |
33 | fUseCodeResolve= false; | |
34 | if (editor instanceof JavaEditor) | |
35 | fEditor= (JavaEditor)editor; | |
36 | } | |
37 | ||
38 | public JavaElementProvider(IEditorPart editor, boolean useCodeResolve) { | |
39 | this(editor); | |
40 | fUseCodeResolve= useCodeResolve; | |
41 | } | |
42 | ||
43 | /* | |
44 | * @see IInformationProvider#getSubject(ITextViewer, int) | |
45 | */ | |
46 | public IRegion getSubject(ITextViewer textViewer, int offset) { | |
47 | if (textViewer != null && fEditor != null) { | |
48 | IRegion region= JavaWordFinder.findWord(textViewer.getDocument(), offset); | |
49 | if (region != null) | |
50 | return region; | |
51 | else | |
52 | return new Region(offset, 0); | |
53 | } | |
54 | return null; | |
55 | } | |
56 | ||
57 | /* | |
58 | * @see IInformationProvider#getInformation(ITextViewer, IRegion) | |
59 | */ | |
60 | public String getInformation(ITextViewer textViewer, IRegion subject) { | |
61 | return getInformation2(textViewer, subject).toString(); | |
62 | } | |
63 | ||
64 | /* | |
65 | * @see IInformationProviderExtension#getElement(ITextViewer, IRegion) | |
66 | */ | |
67 | public Object getInformation2(ITextViewer textViewer, IRegion subject) { | |
68 | if (fEditor == null) | |
69 | return null; | |
70 | ||
71 | return fEditor.generated_8531874811260307211(this); | |
72 | } | |
73 | } |