Search in sources :

Example 1 with LocalFileStorage

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());
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IPath(org.eclipse.core.runtime.IPath) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) IRegion(org.eclipse.jface.text.IRegion) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with LocalFileStorage

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;
}
Also used : AbstractSourceLookupDirector(org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IFileStore(org.eclipse.core.filesystem.IFileStore) IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 3 with LocalFileStorage

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]);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) IPath(org.eclipse.core.runtime.IPath) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) URI(java.net.URI) Stack(java.util.Stack) ValgrindError(org.eclipse.linuxtools.internal.valgrind.core.ValgrindError) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ISourceLookupResult(org.eclipse.debug.ui.sourcelookup.ISourceLookupResult) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IMarker(org.eclipse.core.resources.IMarker) ISourceLocator(org.eclipse.debug.core.model.ISourceLocator) IResource(org.eclipse.core.resources.IResource)

Example 4 with LocalFileStorage

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IErlModule(org.erlide.engine.model.root.IErlModule) ILineBreakpoint(org.eclipse.debug.core.model.ILineBreakpoint) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator)

Aggregations

IFile (org.eclipse.core.resources.IFile)4 LocalFileStorage (org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage)4 URI (java.net.URI)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 Stack (java.util.Stack)1 IBinaryObject (org.eclipse.cdt.core.IBinaryParser.IBinaryObject)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 ILineBreakpoint (org.eclipse.debug.core.model.ILineBreakpoint)1 ISourceLocator (org.eclipse.debug.core.model.ISourceLocator)1 AbstractSourceLookupDirector (org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector)1 ISourceContainer (org.eclipse.debug.core.sourcelookup.ISourceContainer)1 IDebugModelPresentation (org.eclipse.debug.ui.IDebugModelPresentation)1 ISourceLookupResult (org.eclipse.debug.ui.sourcelookup.ISourceLookupResult)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1