Bug 378258: [hovering] F2 hover shows variable name instead of rich variable value hover
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/BestMatchHover.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/BestMatchHover.java
index 1909867..0a87c56 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/BestMatchHover.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/BestMatchHover.java
@@ -126,6 +126,27 @@
*/
@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
+ return getHoverInfo2(textViewer, hoverRegion, false);
+ }
+
+ /**
+ * Returns the information which should be presented when a hover or persistent popup is shown
+ * for the specified hover region.
+ *
+ * @param textViewer the viewer on which the hover popup should be shown
+ * @param hoverRegion the text range in the viewer which is used to determine the hover display
+ * information
+ * @param forInformationProvider <code>true</code> iff the hover info is requested by the
+ * information presenter. In this case, the method only considers text hovers for
+ * which a proper IInformationControlCreator is available that can supply focusable
+ * and resizable information controls.
+ *
+ * @return the hover popup display information, or <code>null</code> if none available
+ *
+ * @see ITextHoverExtension2#getHoverInfo2(ITextViewer, IRegion)
+ * @since 3.8
+ */
+ public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion, boolean forInformationProvider) {
checkTextHovers();
fBestHover= null;
@@ -140,7 +161,7 @@
if (hover instanceof ITextHoverExtension2) {
Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
- if (info != null) {
+ if (info != null && !(forInformationProvider && getInformationPresenterControlCreator(hover) == null)) {
fBestHover= hover;
return info;
}
@@ -174,11 +195,15 @@
*/
@Override
public IInformationControlCreator getInformationPresenterControlCreator() {
- if (fBestHover instanceof IInformationProviderExtension2) // this is wrong, but left here for backwards compatibility
- return ((IInformationProviderExtension2)fBestHover).getInformationPresenterControlCreator();
+ return getInformationPresenterControlCreator(fBestHover);
+ }
- if (fBestHover instanceof AbstractJavaEditorTextHover) {
- return ((AbstractJavaEditorTextHover) fBestHover).getInformationPresenterControlCreator();
+ private static IInformationControlCreator getInformationPresenterControlCreator(ITextHover hover) {
+ if (hover instanceof IInformationProviderExtension2) // this is wrong, but left here for backwards compatibility
+ return ((IInformationProviderExtension2)hover).getInformationPresenterControlCreator();
+
+ if (hover instanceof AbstractJavaEditorTextHover) {
+ return ((AbstractJavaEditorTextHover) hover).getInformationPresenterControlCreator();
}
return null;
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaInformationProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaInformationProvider.java
index 0ecc6c7..e97447d 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaInformationProvider.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavaInformationProvider.java
@@ -64,7 +64,7 @@
public Object getInformation2(ITextViewer textViewer, IRegion subject) {
if (fImplementation == null)
return null;
- return fImplementation.getHoverInfo2(textViewer, subject);
+ return fImplementation.getHoverInfo2(textViewer, subject, true);
}
/*