Search in sources :

Example 1 with ISourceLocator

use of org.eclipse.debug.core.model.ISourceLocator in project xtext-xtend by eclipse.

the class XtendFileHyperlink method linkActivated.

@Override
public void linkActivated() {
    try {
        try {
            ISourceLocator _sourceLocator = this.getLaunch().getSourceLocator();
            final ISourceLocator l = _sourceLocator;
            boolean _matched = false;
            if (l instanceof AbstractSourceLookupDirector) {
                _matched = true;
                final Object result = ((AbstractSourceLookupDirector) l).getSourceElement(this.fileName);
                boolean _matched_1 = false;
                if (result instanceof IFile) {
                    _matched_1 = true;
                    final IEditorPart editor = IDE.openEditor(this.workbench.getActiveWorkbenchWindow().getActivePage(), ((IFile) result));
                    boolean _matched_2 = false;
                    if (editor instanceof XtextEditor) {
                        _matched_2 = true;
                        final IRegion region = ((XtextEditor) editor).getDocument().getLineInformation((this.lineNumber - 1));
                        ((XtextEditor) editor).selectAndReveal(region.getOffset(), region.getLength());
                    }
                }
            }
        } catch (final Throwable _t) {
            if (_t instanceof NumberFormatException) {
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : AbstractSourceLookupDirector(org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector) IFile(org.eclipse.core.resources.IFile) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IEditorPart(org.eclipse.ui.IEditorPart) ISourceLocator(org.eclipse.debug.core.model.ISourceLocator) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with ISourceLocator

use of org.eclipse.debug.core.model.ISourceLocator in project linuxtools by eclipse.

the class ValgrindCoreParser method copyLaunchSourceLocator.

/**
 * Return a safe source locator from launch object which won't be disposed if launch object is disposed
 * @param launch - launch object
 * @return source locator
 */
public static ISourceLocator copyLaunchSourceLocator(ILaunch launch) {
    if (launch == null)
        return null;
    ISourceLocator sourceLocator = launch.getSourceLocator();
    ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
    // since we want to use it later we need to create a copy of it
    if (sourceLocator instanceof ISourceLookupDirector) {
        try {
            ISourceLookupDirector director = (ISourceLookupDirector) sourceLocator;
            String id = director.getId();
            String memento = director.getMemento();
            IPersistableSourceLocator sourceLocatorCopy = DebugPlugin.getDefault().getLaunchManager().newSourceLocator(id);
            if (sourceLocatorCopy instanceof IPersistableSourceLocator2) {
                ((IPersistableSourceLocator2) sourceLocatorCopy).initializeFromMemento(memento, launchConfiguration);
            } else
                sourceLocatorCopy.initializeFromMemento(memento);
            return sourceLocatorCopy;
        } catch (CoreException e) {
        // ignore
        }
    }
    return sourceLocator;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ISourceLookupDirector(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) IPersistableSourceLocator(org.eclipse.debug.core.model.IPersistableSourceLocator) IPersistableSourceLocator2(org.eclipse.debug.core.sourcelookup.IPersistableSourceLocator2) ISourceLocator(org.eclipse.debug.core.model.ISourceLocator)

Example 3 with ISourceLocator

use of org.eclipse.debug.core.model.ISourceLocator in project linuxtools by eclipse.

the class LinkedResourceMarkerTest method isWorkspaceFrame.

private boolean isWorkspaceFrame(ValgrindStackFrame frame) {
    ISourceLocator locator = frame.getSourceLocator();
    Object result = DebugUITools.lookupSource(frame.getFile(), locator).getSourceElement();
    return result != null && result instanceof IResource;
}
Also used : ISourceLocator(org.eclipse.debug.core.model.ISourceLocator) IResource(org.eclipse.core.resources.IResource)

Example 4 with ISourceLocator

use of org.eclipse.debug.core.model.ISourceLocator in project linuxtools by eclipse.

the class MarkerTest method isWorkspaceFrame.

private boolean isWorkspaceFrame(ValgrindStackFrame frame) {
    ISourceLocator locator = frame.getSourceLocator();
    Object result = DebugUITools.lookupSource(frame.getFile(), locator).getSourceElement();
    return result != null && result instanceof IResource;
}
Also used : ISourceLocator(org.eclipse.debug.core.model.ISourceLocator) IResource(org.eclipse.core.resources.IResource)

Example 5 with ISourceLocator

use of org.eclipse.debug.core.model.ISourceLocator 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

ISourceLocator (org.eclipse.debug.core.model.ISourceLocator)5 IResource (org.eclipse.core.resources.IResource)3 IFile (org.eclipse.core.resources.IFile)2 URI (java.net.URI)1 Stack (java.util.Stack)1 IMarker (org.eclipse.core.resources.IMarker)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 IPersistableSourceLocator (org.eclipse.debug.core.model.IPersistableSourceLocator)1 AbstractSourceLookupDirector (org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector)1 IPersistableSourceLocator2 (org.eclipse.debug.core.sourcelookup.IPersistableSourceLocator2)1 ISourceLookupDirector (org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)1 LocalFileStorage (org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage)1 ISourceLookupResult (org.eclipse.debug.ui.sourcelookup.ISourceLookupResult)1 IRegion (org.eclipse.jface.text.IRegion)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