Search in sources :

Example 1 with IPersistableSourceLocator2

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

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 IPersistableSourceLocator (org.eclipse.debug.core.model.IPersistableSourceLocator)1 ISourceLocator (org.eclipse.debug.core.model.ISourceLocator)1 IPersistableSourceLocator2 (org.eclipse.debug.core.sourcelookup.IPersistableSourceLocator2)1 ISourceLookupDirector (org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)1