类org.eclipse.jface.text.ITextHoverExtension2源码实例Demo

下面列出了怎么用org.eclipse.jface.text.ITextHoverExtension2的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xtext-xtend   文件: XtendHoverInEditorTest.java
private void hasHoverOver(final CharSequence it, final String textUnderHover, final Class<? extends BrowserInformationControlInput> expectedPopupType, final String expectedHoverContent) {
  try {
    final IFile fileFoo = this.helper.createFile("Foo.xtend", it.toString());
    this._syncUtil.waitForBuild(null);
    final XtextEditor editor = this.helper.openEditor(fileFoo);
    int _indexOf = it.toString().indexOf(textUnderHover);
    int _length = textUnderHover.length();
    final Region region = new Region(_indexOf, _length);
    final Object info = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(editor.getInternalSourceViewer(), region);
    Assert.assertTrue(expectedPopupType.isInstance(info));
    final String html = ((BrowserInformationControlInput) info).getHtml();
    Assert.assertTrue(html.contains(expectedHoverContent));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
源代码2 项目: xtext-eclipse   文件: XtextInformationProvider.java
@Override
public Object getInformation2(ITextViewer textViewer, IRegion subject) {
	if(hover != null && hover instanceof ITextHoverExtension2){
		return ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, subject);
	}
	return null;
}
 
源代码3 项目: xtext-eclipse   文件: XtextInformationProvider.java
/**
 * Just for compatibility reasons
 * {@link org.eclipse.jface.text.information.IInformationProvider#getInformation(ITextViewer, IRegion)}
 */
@Override
@Deprecated
public String getInformation(ITextViewer textViewer, IRegion subject) {
	if(hover instanceof ITextHoverExtension2){
		Object hoverInfo2 = ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, subject);
		return hoverInfo2!= null ? hoverInfo2.toString():null;
	}
	return null;
}
 
源代码4 项目: xtext-eclipse   文件: AbstractCompositeHover.java
@Override
@SuppressWarnings("deprecation")
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
	if (currentHover != null) {
		if (currentHover instanceof ITextHoverExtension2)
			return ((ITextHoverExtension2) currentHover).getHoverInfo2(textViewer, hoverRegion);
		else {
			return currentHover.getHoverInfo(textViewer, hoverRegion);
		}
	}
	return null;
}
 
源代码5 项目: xds-ide   文件: ModulaInformationProvider.java
public Object getInformation2(ITextViewer textViewer, IRegion subject) {
    createHover(textViewer);
    if (hover instanceof ITextHoverExtension2) {
        return ((ITextHoverExtension2)hover).getHoverInfo2(textViewer, subject);
    }
    return null;
}
 
源代码6 项目: xds-ide   文件: ModulaEditorTextHover.java
/**
   * {@inheritDoc}
   */
  @Override
  public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
// Overridden from ITextHoverExtension2. We try and return the richest
// help available; this
// means trying to call getHoverInfo2() on any contributors, and falling
// back on getHoverInfo().
lastReturnedHover = null;

// Check through the contributed hover providers.
for (ITextHover hoverContributer : hoverContributors) {
	if (hoverContributer instanceof ITextHoverExtension2) {
		Object hoverInfo = ((ITextHoverExtension2) hoverContributer)
				.getHoverInfo2(textViewer, hoverRegion);

		if (hoverInfo != null) {
			lastReturnedHover = hoverContributer;
			return hoverInfo;
		}
	} else {
		@SuppressWarnings("deprecation")
		String hoverText = hoverContributer.getHoverInfo(textViewer,
				hoverRegion);

		if (hoverText != null) {
			lastReturnedHover = hoverContributer;
			return hoverText;
		}
	}
}
      
      return getModulaDocHover(textViewer, hoverRegion);
  }
 
@SuppressWarnings("deprecation")
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion)
{
	if (activeTextHover != null)
	{
		Object info = null;
		if (activeTextHover instanceof AbstractCommonTextHover)
		{
			AbstractCommonTextHover commonHover = (AbstractCommonTextHover) activeTextHover;
			commonHover.setEditor(getEditor());
		}
		if (activeTextHover instanceof ITextHoverExtension2)
		{
			info = ((ITextHoverExtension2) activeTextHover).getHoverInfo2(textViewer, hoverRegion);
		}
		else
		{
			info = activeTextHover.getHoverInfo(textViewer, hoverRegion);
		}
		if (info != null)
		{
			return info;
		}
	}
	String defaultInfo = super.getHoverInfo(textViewer, hoverRegion);
	if (defaultInfo != null)
	{
		// wrap it in a SimpleTextHover so it will look the same as other hovers (i.e. use the theme colors,
		// etc.)
		return new SimpleTextHover(defaultInfo, null).getHoverInfo2(textViewer, hoverRegion);
	}
	return null;
}
 
@SuppressWarnings("deprecation")
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset)
{
	activeTextHover = null;
	List<TextHoverDescriptor> descriptors = getEnabledTextHoverDescriptors(textViewer, offset);
	for (TextHoverDescriptor descriptor : descriptors)
	{
		ITextHover textHover = descriptor.createTextHover();
		IRegion region = null;
		if (textHover != null)
		{
			region = textHover.getHoverRegion(textViewer, offset);
		}
		if (region != null)
		{
			if (descriptors.size() > 1)
			{
				if (textHover instanceof ITextHoverExtension2)
				{
					if (((ITextHoverExtension2) textHover).getHoverInfo2(textViewer, region) == null)
					{
						continue;
					}
				}
				else if (textHover.getHoverInfo(textViewer, region) == null)
				{
					continue;
				}
			}
			activeTextHover = textHover;
			return region;
		}
	}
	return super.getHoverRegion(textViewer, offset);
}
 
/**
 * 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;

	if (fInstantiatedTextHovers == null)
		return null;

	for (Iterator<IJavaEditorTextHover> iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) {
		ITextHover hover= iterator.next();
		if (hover == null)
			continue;

		if (hover instanceof ITextHoverExtension2) {
			Object info= ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, hoverRegion);
			if (info != null && !(forInformationProvider && getInformationPresenterControlCreator(hover) == null)) {
				fBestHover= hover;
				return info;
			}
		} else {
			String s= hover.getHoverInfo(textViewer, hoverRegion);
			if (s != null && s.trim().length() > 0) {
				fBestHover= hover;
				return s;
			}
		}
	}

	return null;
}
 
@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
	if (ensureHoverCreated()) {
		if (fHover instanceof ITextHoverExtension2)
			return ((ITextHoverExtension2) fHover).getHoverInfo2(textViewer, hoverRegion);
		else
			return fHover.getHoverInfo(textViewer, hoverRegion);
	}

	return null;
}
 
源代码11 项目: goclipse   文件: DelegatingDebugTextHover.java
@SuppressWarnings("deprecation")
@Override
public Object getHoverInfo(ISourceBuffer sourceBuffer, IRegion hoverRegion, ITextViewer textViewer) {
       
	fDelegate = getDelegate();
       if (fDelegate instanceof ITextHoverExtension2) {
		return ((ITextHoverExtension2) fDelegate).getHoverInfo2(textViewer, hoverRegion);
       }
       // fall back to legacy method
       if (fDelegate != null) {
           return fDelegate.getHoverInfo(textViewer, hoverRegion);
       }
       return null;
   }
 
源代码12 项目: xtext-eclipse   文件: AbstractHoverTest.java
protected BrowserInformationControlInput hoveringOver(IFile dslFile, IRegion hoverRegion) {
	XtextEditor editor = openInEditor(dslFile);
	Object hoverInfo = ((ITextHoverExtension2) eObjectHover).getHoverInfo2(editor.getInternalSourceViewer(), hoverRegion);
	return (BrowserInformationControlInput) hoverInfo;
}
 
源代码13 项目: gef   文件: DotHtmlLabelAdaptingTextHover.java
@Override
public Object getHoverInfo(EObject eObject, ITextViewer textViewer,
		IRegion hoverRegion) {
	if (textViewer == null || hoverRegion == null) {
		return null;
	}

	HtmlOffsetPair html = htmlOffsetPair(hoverRegion.getOffset(),
			textViewer);
	if (html == null) {
		return null;
	}

	synchronized (sourceViewer) {
		try {
			sourceViewer.setDocument(
					DotEditorUtils.getDocument(injector, html.code));
		} catch (Exception e) {
			return null;
		}

		Object hoverInfo = null;

		if (hover instanceof DotHtmlLabelSubgrammarEObjectHover
				&& eObject instanceof Attribute) {
			((DotHtmlLabelSubgrammarEObjectHover) hover)
					.setContainingAttribute((Attribute) eObject);
		}

		if (hover instanceof ITextHoverExtension2) {
			hoverInfo = ((ITextHoverExtension2) hover).getHoverInfo2(
					sourceViewer,
					new Region(hoverRegion.getOffset() - html.offset,
							hoverRegion.getLength()));
		}

		if (hover instanceof DotHtmlLabelSubgrammarEObjectHover) {
			lastCreatorProvider = ((DotHtmlLabelSubgrammarEObjectHover) hover)
					.getLastCreatorProvider();
		}

		return hoverInfo;
	}
}
 
源代码14 项目: xtext-xtend   文件: XtendHoverInEditorTest.java
@Test
public void testHoverOfReferencedElement() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* Hello Foo");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("class Foo {}");
    _builder.newLine();
    final String contentFoo = _builder.toString();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("class Bar extends Foo {}");
    _builder_1.newLine();
    final String contentBar = _builder_1.toString();
    final IFile fileFoo = this.helper.createFile("Foo.xtend", contentFoo);
    final IFile fileBar = this.helper.createFile("Bar.xtend", contentBar);
    this._syncUtil.waitForBuild(null);
    final XtextEditor editor = this.helper.openEditor(fileBar);
    ISourceViewer _internalSourceViewer = editor.getInternalSourceViewer();
    Region _region = new Region(19, 1);
    Object _hoverInfo2 = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(((ITextViewer) _internalSourceViewer), _region);
    final XtextBrowserInformationControlInput info = ((XtextBrowserInformationControlInput) _hoverInfo2);
    Assert.assertTrue(info.getHtml().contains("Hello Foo"));
    final XtextEditor fooEditor = this.helper.openEditor(fileFoo);
    IXtextDocument _document = fooEditor.getDocument();
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("/**");
    _builder_2.newLine();
    _builder_2.append(" ");
    _builder_2.append("* Hello BAZ");
    _builder_2.newLine();
    _builder_2.append(" ");
    _builder_2.append("*/");
    _builder_2.newLine();
    _builder_2.append("class Foo {}");
    _builder_2.newLine();
    _document.set(_builder_2.toString());
    this._syncUtil.waitForReconciler(fooEditor);
    this._syncUtil.waitForReconciler(editor);
    ISourceViewer _internalSourceViewer_1 = editor.getInternalSourceViewer();
    Region _region_1 = new Region(19, 1);
    Object _hoverInfo2_1 = ((ITextHoverExtension2) this.hoverer).getHoverInfo2(((ITextViewer) _internalSourceViewer_1), _region_1);
    final XtextBrowserInformationControlInput info2 = ((XtextBrowserInformationControlInput) _hoverInfo2_1);
    Assert.assertFalse(info2.getHtml().contains("Hello Foo"));
    Assert.assertTrue(info2.getHtml().contains("Hello BAZ"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
 类所在包
 同包方法