/** * Creates and returns new {@link IPersistableSourceLocator} of the specified type and with the provided configuration. */ public static IPersistableSourceLocator createSourceLocator(String type, ILaunchConfiguration configuration) throws CoreException { ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); IPersistableSourceLocator locator = launchManager.newSourceLocator(type); String memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null); if (memento == null) { locator.initializeDefaults(configuration); } else { if (locator instanceof IPersistableSourceLocator2) { ((IPersistableSourceLocator2) locator).initializeFromMemento(memento, configuration); } else { locator.initializeFromMemento(memento); } } return locator; }
/** * Set the source locator to use with the launch, if specified * by this configuration. * * @param launch the launch on which to set the source locator * @throws CoreException if a problem is encountered */ protected void initializeSourceLocator(ILaunch launch) throws CoreException { if (launch.getSourceLocator() == null) { String type = getAttribute(ATTR_SOURCE_LOCATOR_ID, (String)null); if (type == null) { type = getType().getSourceLocatorId(); } if (type != null) { IPersistableSourceLocator locator = getLaunchManager().newSourceLocator(type); String memento = getAttribute(ATTR_SOURCE_LOCATOR_MEMENTO, (String)null); if (memento == null) { locator.initializeDefaults(this); } else { if(locator instanceof IPersistableSourceLocator2) { ((IPersistableSourceLocator2)locator).initializeFromMemento(memento, this); } else { locator.initializeFromMemento(memento); } } launch.setSourceLocator(locator); } } }