}
ISourceLookupDirector director = (ISourceLookupDirector) sourceLocator;
SourcePositionMap positionMap = connectedTargetData.getSourcePositionMap();
SourcePosition userPosition;
{
// First get VM positions.
Script script = jsFunction.getScript();
if (script == null) {
return;
}
TextStreamPosition functionOpenParenPosition = jsFunction.getOpenParenPosition();
if (functionOpenParenPosition == null) {
return;
}
// Convert them to user positions.
userPosition = positionMap.translatePosition(
VmResourceId.forScript(script), functionOpenParenPosition.getLine(),
functionOpenParenPosition.getColumn(), TranslateDirection.VM_TO_USER);
}
Object sourceObject = director.getSourceElement(userPosition.getId());
if (sourceObject instanceof IFile == false) {
return;
}
IFile resource = (IFile) sourceObject;
IEditorPart editor;
try {
editor= IDE.openEditor(activeWorkbenchWindow.getActivePage(), resource, true);
} catch (PartInitException e) {
throw new RuntimeException(e);
}
if (editor instanceof ITextEditor == false) {
return;
}
ITextEditor textEditor = (ITextEditor) editor;
int offset = calculateOffset(textEditor, userPosition);
textEditor.selectAndReveal(offset, 0);
}
private int calculateOffset(ITextEditor editor, SourcePosition userPosition) {
IDocumentProvider provider = editor.getDocumentProvider();
IDocument document = provider.getDocument(editor.getEditorInput());
int lineStartOffset;
try {
lineStartOffset = document.getLineOffset(userPosition.getLine());
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
return lineStartOffset + userPosition.getColumn();
}
};
}