/*
* Add action to support "F3" jump to definition
*/
{
Action action = new OpenAction(getEditorSite()) {
public void run(org.eclipse.jface.text.ITextSelection selection) {
try {
IDocument doc = getSourceViewer().getDocument();
int line = doc.getLineOfOffset(selection.getOffset());
List<IAnnotation> matches = scenarioAnnotationSearch.search(getSourceViewer(), line);
if (matches.size() > 0) {
IRegion lineRegion = doc.getLineInformation(line);
String currentLine = getSourceViewer().getDocument().get(lineRegion.getOffset(),
lineRegion.getLength());
String trimmedLine = currentLine.trim();
int firstSpaceIndex = trimmedLine.indexOf(" ");
String stepText = "";
if (firstSpaceIndex != -1) {
stepText = trimmedLine.substring(firstSpaceIndex).trim();
} else {
return;
}
for (IAnnotation annotation : matches) {
IMemberValuePair[] pair = annotation.getMemberValuePairs();
Pattern stepPattern = Pattern.compile((String) pair[0].getValue());
if (stepPattern.matcher(stepText).matches()) {
super.run(new Object[] {annotation});
break;
}
}
}
} catch (BadLocationException e) {
Activator.getLogservice().log(LogService.LOG_ERROR, e.getMessage());
} catch (JavaModelException e) {
Activator.getLogservice().log(LogService.LOG_ERROR, e.getMessage());
}
};
};
action.setActionDefinitionId("org.eclipse.jdt.ui.edit.text.java.open.editor");
setAction("OpenJavaElement", action);
markAsStateDependentAction("OpenJavaElement", true);
}
}