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]);
}
}
}
}
Aggregations