Search in sources :

Example 1 with IHyperlinkHelper

use of org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper in project n4js by eclipse.

the class N4JSHyperlinkDetector method detectHyperlinks.

/**
 * Method copied from super class with only a minor change: call to "readOnly" changed to "tryReadOnly".
 */
@Override
public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion region, final boolean canShowMultipleHyperlinks) {
    final IDocument xtextDocument = textViewer.getDocument();
    if (!(xtextDocument instanceof N4JSDocument)) {
        return super.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
    }
    final IHyperlinkHelper helper = getHelper();
    return ((N4JSDocument) xtextDocument).tryReadOnly(new IUnitOfWork<IHyperlink[], XtextResource>() {

        @Override
        public IHyperlink[] exec(XtextResource resource) throws Exception {
            if (resource == null) {
                return null;
            }
            if (helper instanceof ISourceViewerAware && textViewer instanceof ISourceViewer) {
                ((ISourceViewerAware) helper).setSourceViewer((ISourceViewer) textViewer);
            }
            return helper.createHyperlinksByOffset(resource, region.getOffset(), canShowMultipleHyperlinks);
        }
    }, null);
}
Also used : IHyperlinkHelper(org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper) ISourceViewerAware(org.eclipse.xtext.ui.editor.ISourceViewerAware) XtextResource(org.eclipse.xtext.resource.XtextResource) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 ISourceViewerAware (org.eclipse.xtext.ui.editor.ISourceViewerAware)1 IHyperlinkHelper (org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper)1