Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009 itemis AG ( and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at /
 package org.eclipse.xtext.ui.editor.hyperlinking;
import  org.eclipse.core.commands.AbstractHandler;
import  org.eclipse.core.commands.ExecutionEvent;
import  org.eclipse.core.commands.ExecutionException;
import  org.eclipse.jface.text.IRegion;
import  org.eclipse.jface.text.ITextSelection;
import  org.eclipse.jface.text.Region;
import  org.eclipse.jface.text.hyperlink.IHyperlink;
import  org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import  org.eclipse.jface.text.source.ISourceViewer;

Peter Friese - Initial contribution and API
public class OpenDeclarationHandler extends AbstractHandler {
	private IHyperlinkDetector detector;
	public Object execute(ExecutionEvent eventthrows ExecutionException {
		XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
		if (xtextEditor != null) {
			ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection();
			IRegion region = new Region(selection.getOffset(), selection.getLength());
			ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer();
			IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewerregionfalse);
			if (hyperlinks != null && hyperlinks.length > 0) {
				IHyperlink hyperlink = hyperlinks[0];;
		return null;
	public void setDetector(IHyperlinkDetector detector) {
		this. = detector;
	public IHyperlinkDetector getDetector() {
		return ;
New to GrepCode? Check out our FAQ X