Search in sources :

Example 1 with ISourceLookupResult

use of org.eclipse.debug.ui.sourcelookup.ISourceLookupResult 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)

Aggregations

URI (java.net.URI)1 Stack (java.util.Stack)1 IFile (org.eclipse.core.resources.IFile)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IPath (org.eclipse.core.runtime.IPath)1 ISourceLocator (org.eclipse.debug.core.model.ISourceLocator)1 LocalFileStorage (org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage)1 ISourceLookupResult (org.eclipse.debug.ui.sourcelookup.ISourceLookupResult)1 ValgrindError (org.eclipse.linuxtools.internal.valgrind.core.ValgrindError)1 ValgrindStackFrame (org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame)1 IValgrindMessage (org.eclipse.linuxtools.valgrind.core.IValgrindMessage)1