use of org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Opens the specified file in an editor (or selects an already open
* editor) and highlights the specified line.
* @param result - result of performing source lookup with a org.eclipse.debug.core.model.ISourceLocator
* @param line - line number to select, 0 to not select a line
* @throws PartInitException - Failed to open editor
* @throws BadLocationException - Line number not valid in file
* @see DebugUITools#lookupSource(Object, org.eclipse.debug.core.model.ISourceLocator)
*/
public static void openEditorAndSelect(ISourceLookupResult result, int line) throws PartInitException, BadLocationException {
IEditorInput input = result.getEditorInput();
String editorID = result.getEditorId();
if (input == null || editorID == null) {
// Consult the CDT DebugModelPresentation
Object sourceElement = result.getSourceElement();
if (sourceElement != null) {
// Resolve IResource in case we get a LocalFileStorage object
if (sourceElement instanceof LocalFileStorage) {
IPath filePath = ((LocalFileStorage) sourceElement).getFullPath();
URI fileURI = URIUtil.toURI(filePath);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = root.findFilesForLocationURI(fileURI);
if (files.length > 0) {
// Take the first match
sourceElement = files[0];
}
}
IDebugModelPresentation pres = DebugUITools.newDebugModelPresentation(CDebugCorePlugin.getUniqueIdentifier());
input = pres.getEditorInput(sourceElement);
editorID = pres.getEditorId(input, sourceElement);
pres.dispose();
}
}
if (input != null && editorID != null) {
// Open the editor
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditor(activePage, input, editorID);
// Select the line
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
if (line > 0) {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
// zero-indexed
IRegion lineRegion = document.getLineInformation(line - 1);
textEditor.selectAndReveal(lineRegion.getOffset(), lineRegion.getLength());
}
}
}
}
use of org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage in project linuxtools by eclipse.
the class STLink2SourceSupport method findFileInCommonSourceLookup.
private static IEditorInput findFileInCommonSourceLookup(IPath path) {
try {
AbstractSourceLookupDirector director = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector();
ISourceContainer[] c = director.getSourceContainers();
for (ISourceContainer sourceContainer : c) {
Object[] o = sourceContainer.findSourceElements(path.toOSString());
for (Object object : o) {
if (object instanceof IFile) {
return new FileEditorInput((IFile) object);
} else if (object instanceof LocalFileStorage) {
LocalFileStorage storage = (LocalFileStorage) object;
IFileStore ifs = EFS.getStore(storage.getFile().toURI());
return new FileStoreEditorInput(ifs);
}
}
}
} catch (CoreException e) {
// do nothing
}
return null;
}
use of org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage in project linuxtools by eclipse.
the class ValgrindLaunchConfigurationDelegate method createMarkers.
private void createMarkers(IValgrindMessage[] messages) throws CoreException {
// find the topmost stack frame within the workspace to annotate with marker
// traverse nested errors as well
Stack<IValgrindMessage> messageStack = new Stack<>();
messageStack.addAll(Arrays.asList(messages));
while (!messageStack.isEmpty()) {
IValgrindMessage message = messageStack.pop();
IMarker marker = null;
IValgrindMessage[] children = message.getChildren();
for (int i = 0; i < children.length; i++) {
// if we've found our marker we don't care about any further frames in this stack
if (children[i] instanceof ValgrindStackFrame && marker == null) {
ValgrindStackFrame frame = (ValgrindStackFrame) children[i];
if (frame.getLine() > 0) {
ISourceLocator locator = frame.getSourceLocator();
ISourceLookupResult result = DebugUITools.lookupSource(frame.getFile(), locator);
Object sourceElement = result.getSourceElement();
if (sourceElement != null) {
// Resolve IResource in case we get a LocalFileStorage object
if (sourceElement instanceof LocalFileStorage) {
IPath filePath = ((LocalFileStorage) sourceElement).getFullPath();
URI fileURI = URIUtil.toURI(filePath);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = root.findFilesForLocationURI(fileURI);
if (files.length > 0) {
// Take the first match
sourceElement = files[0];
}
}
if (sourceElement instanceof IResource) {
IResource resource = (IResource) sourceElement;
marker = resource.createMarker(ValgrindLaunchPlugin.MARKER_TYPE);
marker.setAttribute(IMarker.MESSAGE, message.getText());
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.LINE_NUMBER, frame.getLine());
}
}
}
} else if (children[i] instanceof ValgrindError) {
// nested error
messageStack.push(children[i]);
}
}
}
}
use of org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage in project erlide_eclipse by erlang.
the class ErlDebugModelPresentation method getEditorInput.
@Override
public IEditorInput getEditorInput(final Object element) {
if (element instanceof IFile) {
return new FileEditorInput((IFile) element);
}
if (element instanceof ILineBreakpoint) {
return new FileEditorInput((IFile) ((ILineBreakpoint) element).getMarker().getResource());
}
if (element instanceof LocalFileStorage) {
final LocalFileStorage lfs = (LocalFileStorage) element;
try {
final IErlElementLocator model = ErlangEngine.getInstance().getModel();
final IErlModule module = ErlangEngine.getInstance().getModelFindService().findModule(model, null, null, lfs.getFullPath().toString(), IErlElementLocator.Scope.ALL_PROJECTS);
return EditorUtility.getEditorInput(module);
} catch (final CoreException e) {
ErlLogger.error(e);
}
}
return null;
}
Aggregations