1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Added persistency to the source locator.

This commit is contained in:
Mikhail Khodjaiants 2003-02-18 19:24:08 +00:00
parent 90de4d7222
commit d7b288068e
10 changed files with 564 additions and 3 deletions

View file

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src/"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="schema"/>
<classpathentry kind="src" path="/org.eclipse.core.resources"/> <classpathentry kind="src" path="/org.eclipse.core.resources"/>
<classpathentry kind="src" path="/org.eclipse.debug.core"/> <classpathentry kind="src" path="/org.eclipse.debug.core"/>
<classpathentry kind="src" path="/org.eclipse.cdt.core"/> <classpathentry kind="src" path="/org.eclipse.cdt.core"/>
<classpathentry exported="true" kind="src" path="/org.eclipse.cdt.core.win32"/>
<classpathentry kind="src" path="/org.apache.xerces"/>
<classpathentry kind="src" path="/org.eclipse.core.runtime"/> <classpathentry kind="src" path="/org.eclipse.core.runtime"/>
<classpathentry kind="src" path="/org.eclipse.core.boot"/> <classpathentry kind="src" path="/org.eclipse.core.boot"/>
<classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>

View file

@ -3,7 +3,9 @@
<name>org.eclipse.cdt.debug.core</name> <name>org.eclipse.cdt.debug.core</name>
<comment></comment> <comment></comment>
<projects> <projects>
<project>org.apache.xerces</project>
<project>org.eclipse.cdt.core</project> <project>org.eclipse.cdt.core</project>
<project>org.eclipse.cdt.core.win32</project>
<project>org.eclipse.core.boot</project> <project>org.eclipse.core.boot</project>
<project>org.eclipse.core.resources</project> <project>org.eclipse.core.resources</project>
<project>org.eclipse.core.runtime</project> <project>org.eclipse.core.runtime</project>

View file

@ -1,3 +1,13 @@
2003-02-18 Mikhail Khodjaiants
Added persistency to the source locator.
* plugin.xml: added dependency on the 'org.apache.xerces' plugin
* ICSourceLocation.java
* CDebugUtils.java
* CDirectorySourceLocation.java
* CProjectSourceLocation.java
* CSourceLocator.java
* CSourceManager.java
2003-02-13 Mikhail Khodjaiants 2003-02-13 Mikhail Khodjaiants
Undo changes because the 'asyncExec' method of the 'DebugPlugin' class has added since version 2.1. Undo changes because the 'asyncExec' method of the 'DebugPlugin' class has added since version 2.1.
* IAsyncExecutor.java: removed * IAsyncExecutor.java: removed

View file

@ -15,6 +15,7 @@
<import plugin="org.eclipse.core.resources"/> <import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.debug.core"/> <import plugin="org.eclipse.debug.core"/>
<import plugin="org.eclipse.cdt.core"/> <import plugin="org.eclipse.cdt.core"/>
<import plugin="org.apache.xerces"/>
</requires> </requires>

View file

@ -43,4 +43,22 @@ public interface ICSourceLocation extends IAdaptable
* @return the paths associated with this location * @return the paths associated with this location
*/ */
IPath[] getPaths(); IPath[] getPaths();
/**
* Returns a memento for this source location from which this
* source location can be reconstructed.
*
* @return a memento for this source location
* @exception CoreException if unable to create a memento
*/
public String getMemento() throws CoreException;
/**
* Initializes this source location from the given memento.
*
* @param memento a memento generated by this source location
* @exception CoreException if unable to initialize this source
* location
*/
public void initializeFrom( String memento ) throws CoreException;
} }

View file

@ -5,13 +5,21 @@
*/ */
package org.eclipse.cdt.debug.internal.core; package org.eclipse.cdt.debug.internal.core;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays; import java.util.Arrays;
import org.apache.xml.serialize.Method;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.SerializerFactory;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IStatusHandler; import org.eclipse.debug.core.IStatusHandler;
import org.w3c.dom.Document;
/** /**
* *
@ -244,4 +252,41 @@ public class CDebugUtils
} }
return false; return false;
} }
/**
* Serializes a XML document into a string - encoded in UTF8 format,
* with given line separators.
*
* @param doc document to serialize
* @param lineSeparator line separator
* @return the document as a string
*/
public static String serializeDocument( Document doc, String lineSeparator ) throws IOException
{
ByteArrayOutputStream s = new ByteArrayOutputStream();
OutputFormat format = new OutputFormat();
format.setIndenting( true );
format.setLineSeparator( lineSeparator ); //$NON-NLS-1$
Serializer serializer = SerializerFactory.getSerializerFactory( Method.XML ).makeSerializer( new OutputStreamWriter( s, "UTF8" ), format );
serializer.asDOMSerializer().serialize( doc );
return s.toString( "UTF8" ); //$NON-NLS-1$
}
/**
* Serializes a XML document into a string - encoded in UTF8 format,
* with platform line separators.
*
* @param doc document to serialize
* @return the document as a string
*/
public static String serializeDocument( Document doc) throws IOException
{
ByteArrayOutputStream s = new ByteArrayOutputStream();
OutputFormat format = new OutputFormat();
format.setIndenting( true );
format.setLineSeparator( System.getProperty( "line.separator" ) ); //$NON-NLS-1$
Serializer serializer = SerializerFactory.getSerializerFactory( Method.XML ).makeSerializer( new OutputStreamWriter( s, "UTF8" ), format );
serializer.asDOMSerializer().serialize( doc );
return s.toString( "UTF8" ); //$NON-NLS-1$
}
} }

View file

@ -6,16 +6,32 @@
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xerces.dom.DocumentImpl;
import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.IDirectorySourceLocation;
import org.eclipse.cdt.debug.internal.core.CDebugUtils;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage; import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/** /**
* *
@ -26,6 +42,10 @@ import org.eclipse.core.runtime.Path;
*/ */
public class CDirectorySourceLocation implements IDirectorySourceLocation public class CDirectorySourceLocation implements IDirectorySourceLocation
{ {
private static final String ELEMENT_NAME = "cDirectorySourceLocation";
private static final String ATTR_DIRECTORY = "directory";
private static final String ATTR_ASSOCIATION = "association";
/** /**
* The root directory of this source location * The root directory of this source location
*/ */
@ -36,6 +56,13 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
*/ */
private IPath fAssociation = null; private IPath fAssociation = null;
/**
* Constructor for CDirectorySourceLocation.
*/
public CDirectorySourceLocation()
{
}
/** /**
* Constructor for CDirectorySourceLocation. * Constructor for CDirectorySourceLocation.
*/ */
@ -103,6 +130,11 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
return fDirectory; return fDirectory;
} }
public void getDirectory( IPath path )
{
fDirectory = path;
}
private void setAssociation( IPath association ) private void setAssociation( IPath association )
{ {
fAssociation = association; fAssociation = association;
@ -177,4 +209,110 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
{ {
return new IPath[] { fDirectory }; return new IPath[] { fDirectory };
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getMemento()
*/
public String getMemento() throws CoreException
{
Document doc = new DocumentImpl();
Element node = doc.createElement( ELEMENT_NAME );
doc.appendChild( node );
node.setAttribute( ATTR_DIRECTORY, getDirectory().toOSString() );
if ( getAssociation() != null )
node.setAttribute( ATTR_ASSOCIATION, getAssociation().toOSString() );
try
{
return CDebugUtils.serializeDocument( doc, " " );
}
catch( IOException e )
{
abort( MessageFormat.format( "Unable to create memento for C/C++ directory source location {0}", new String[] { getDirectory().toOSString() } ), e );
}
// execution will not reach here
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#initializeFrom(java.lang.String)
*/
public void initializeFrom( String memento ) throws CoreException
{
Exception ex = null;
try
{
Element root = null;
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento );
InputSource source = new InputSource( reader );
root = parser.parse( source ).getDocumentElement();
String dir = root.getAttribute( ATTR_DIRECTORY );
if ( isEmpty( dir ) )
{
abort( "Unable to initialize source location - missing directory path", null );
}
else
{
IPath path = new Path( dir );
if ( path.isValidPath( dir ) && path.toFile().isDirectory() )
{
setDirectory( path );
}
else
{
abort( MessageFormat.format( "Unable to initialize source location - invalid directory path {0}", new String[] { dir } ), null );
}
}
dir = root.getAttribute( ATTR_ASSOCIATION );
if ( isEmpty( dir ) )
{
setAssociation( null );
}
else
{
IPath path = new Path( dir );
if ( path.isValidPath( dir ) )
{
setAssociation( path );
}
else
{
setAssociation( null );
}
}
return;
}
catch( ParserConfigurationException e )
{
ex = e;
}
catch( SAXException e )
{
ex = e;
}
catch( IOException e )
{
ex = e;
}
abort( "Exception occurred initializing source location.", ex );
}
/**
* Throws an internal error exception
*/
private void abort( String message, Throwable e ) throws CoreException
{
IStatus s = new Status( IStatus.ERROR,
CDebugCorePlugin.getUniqueIdentifier(),
CDebugCorePlugin.INTERNAL_ERROR,
message,
e );
throw new CoreException( s );
}
private boolean isEmpty( String string )
{
return string == null || string.length() == 0;
}
} }

View file

@ -6,19 +6,36 @@
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xerces.dom.DocumentImpl;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.IProjectSourceLocation;
import org.eclipse.cdt.debug.internal.core.CDebugUtils;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/** /**
* *
@ -28,6 +45,9 @@ import org.eclipse.core.runtime.Path;
*/ */
public class CProjectSourceLocation implements IProjectSourceLocation public class CProjectSourceLocation implements IProjectSourceLocation
{ {
private static final String ELEMENT_NAME = "cProjectSourceLocation";
private static final String ATTR_PROJECT = "project";
/** /**
* The project associated with this source location * The project associated with this source location
*/ */
@ -37,6 +57,13 @@ public class CProjectSourceLocation implements IProjectSourceLocation
private HashSet fNotFoundCache = new HashSet( 20 ); private HashSet fNotFoundCache = new HashSet( 20 );
/**
* Constructor for CProjectSourceLocation.
*/
public CProjectSourceLocation()
{
}
/** /**
* Constructor for CProjectSourceLocation. * Constructor for CProjectSourceLocation.
*/ */
@ -220,4 +247,85 @@ public class CProjectSourceLocation implements IProjectSourceLocation
fCache.clear(); fCache.clear();
fNotFoundCache.clear(); fNotFoundCache.clear();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getMemento()
*/
public String getMemento() throws CoreException
{
Document doc = new DocumentImpl();
Element node = doc.createElement( ELEMENT_NAME );
doc.appendChild( node );
node.setAttribute( ATTR_PROJECT, getProject().getName() );
try
{
return CDebugUtils.serializeDocument( doc, " " );
}
catch( IOException e )
{
abort( MessageFormat.format( "Unable to create memento for C/C++ project source location {0}.", new String[] { getProject().getName() } ), e );
}
// execution will not reach here
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#initializeFrom(java.lang.String)
*/
public void initializeFrom( String memento ) throws CoreException
{
Exception ex = null;
try
{
Element root = null;
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento );
InputSource source = new InputSource( reader );
root = parser.parse( source ).getDocumentElement();
String name = root.getAttribute( ATTR_PROJECT );
if ( isEmpty( name ) )
{
abort( "Unable to initialize source location - missing project name", null );
}
else
{
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( name );
setProject( project );
}
return;
}
catch( ParserConfigurationException e )
{
ex = e;
}
catch( SAXException e )
{
ex = e;
}
catch( IOException e )
{
ex = e;
}
abort( "Exception occurred initializing source location.", ex );
}
/**
* Throws an internal error exception
*/
private void abort( String message, Throwable e ) throws CoreException
{
IStatus s = new Status( IStatus.ERROR,
CDebugCorePlugin.getUniqueIdentifier(),
CDebugCorePlugin.INTERNAL_ERROR,
message,
e );
throw new CoreException( s );
}
private boolean isEmpty( String string )
{
return string == null || string.length() == 0;
}
} }

View file

@ -6,20 +6,41 @@
package org.eclipse.cdt.debug.internal.core.sourcelookup; package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xerces.dom.DocumentImpl;
import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.model.IStackFrameInfo; import org.eclipse.cdt.debug.core.model.IStackFrameInfo;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.internal.core.CDebugUtils;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IStackFrame;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/** /**
* *
@ -27,8 +48,14 @@ import org.eclipse.debug.core.model.IStackFrame;
* *
* @since Aug 19, 2002 * @since Aug 19, 2002
*/ */
public class CSourceLocator implements ICSourceLocator
public class CSourceLocator implements ICSourceLocator, IPersistableSourceLocator
{ {
private static final String ELEMENT_NAME = "cSourceLocator";
private static final String CHILD_NAME = "cSourceLocation";
private static final String ATTR_CLASS = "class";
private static final String ATTR_MEMENTO = "memento";
/** /**
* The array of source locations associated with this locator. * The array of source locations associated with this locator.
*/ */
@ -246,4 +273,172 @@ public class CSourceLocator implements ICSourceLocator
} }
return result; return result;
} }
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
*/
public String getMemento() throws CoreException
{
Document doc = new DocumentImpl();
Element node = doc.createElement( ELEMENT_NAME );
doc.appendChild( node );
ICSourceLocation[] locations = getSourceLocations();
for ( int i = 0; i < locations.length; i++ )
{
Element child = doc.createElement( CHILD_NAME );
child.setAttribute( ATTR_CLASS, locations[i].getClass().getName() );
child.setAttribute( ATTR_MEMENTO, locations[i].getMemento() );
node.appendChild( child );
}
try
{
return CDebugUtils.serializeDocument( doc, " " );
}
catch( IOException e )
{
abort( "Unable to create memento for C/C++ source locator.", e );
}
// execution will not reach here
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException
{
IProject project = getProject( configuration );
if ( project != null )
{
setSourceLocations( getDefaultSourceLocations( project ) );
}
else
{
setSourceLocations( new ICSourceLocation[0] );
}
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String)
*/
public void initializeFromMemento( String memento ) throws CoreException
{
Exception ex = null;
try
{
Element root = null;
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
StringReader reader = new StringReader( memento );
InputSource source = new InputSource( reader );
root = parser.parse( source ).getDocumentElement();
if ( !root.getNodeName().equalsIgnoreCase( ELEMENT_NAME ) )
{
abort( "Unable to restore C/C++ source locator - invalid format.", null );
}
List sourceLocations = new ArrayList();
ClassLoader classLoader = CDebugCorePlugin.getDefault() .getDescriptor().getPluginClassLoader();
NodeList list = root.getChildNodes();
int length = list.getLength();
for ( int i = 0; i < length; ++i )
{
Node node = list.item( i );
short type = node.getNodeType();
if ( type == Node.ELEMENT_NODE )
{
Element entry = (Element)node;
if ( entry.getNodeName().equalsIgnoreCase( CHILD_NAME ) )
{
String className = entry.getAttribute( ATTR_CLASS );
String data = entry.getAttribute( ATTR_MEMENTO );
if ( isEmpty( className ) )
{
abort( "Unable to restore C/C++ source locator - invalid format.", null );
}
Class clazz = null;
try
{
clazz = classLoader.loadClass( className );
}
catch( ClassNotFoundException e )
{
abort( MessageFormat.format( "Unable to restore source location - class not found {0}", new String[] { className } ), e );
}
ICSourceLocation location = null;
try
{
location = (ICSourceLocation)clazz.newInstance();
}
catch( IllegalAccessException e )
{
abort( "Unable to restore source location.", e );
}
catch( InstantiationException e )
{
abort( "Unable to restore source location.", e );
}
location.initializeFrom( data );
sourceLocations.add( location );
}
else
{
abort( "Unable to restore C/C++ source locator - invalid format.", null );
}
}
}
setSourceLocations( (ICSourceLocation[])sourceLocations.toArray( new ICSourceLocation[sourceLocations.size()] ) );
return;
}
catch( ParserConfigurationException e )
{
ex = e;
}
catch( SAXException e )
{
ex = e;
}
catch( IOException e )
{
ex = e;
}
abort( "Exception occurred initializing source locator.", ex );
}
/**
* Throws an internal error exception
*/
private void abort( String message, Throwable e ) throws CoreException
{
IStatus s = new Status( IStatus.ERROR,
CDebugCorePlugin.getUniqueIdentifier(),
CDebugCorePlugin.INTERNAL_ERROR,
message,
e );
throw new CoreException( s );
}
private boolean isEmpty( String string )
{
return string == null || string.length() == 0;
}
private IProject getProject( ILaunchConfiguration configuration )
{
IProject project = null;
try
{
String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "" );
if ( !isEmpty( projectName ) )
project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
}
catch( CoreException e )
{
}
return project;
}
} }

View file

@ -16,8 +16,11 @@ import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode; import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IPersistableSourceLocator;
import org.eclipse.debug.core.model.ISourceLocator; import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IStackFrame;
@ -26,7 +29,10 @@ import org.eclipse.debug.core.model.IStackFrame;
* *
* @since: Oct 8, 2002 * @since: Oct 8, 2002
*/ */
public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable public class CSourceManager implements ICSourceLocator,
IPersistableSourceLocator,
ISourceMode,
IAdaptable
{ {
private ISourceLocator fSourceLocator = null; private ISourceLocator fSourceLocator = null;
private int fMode = ISourceMode.MODE_SOURCE; private int fMode = ISourceMode.MODE_SOURCE;
@ -202,4 +208,39 @@ public class CSourceManager implements ICSourceLocator, ISourceMode, IAdaptable
} }
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
*/
public String getMemento() throws CoreException
{
if ( getPersistableSourceLocator() != null )
return getPersistableSourceLocator().getMemento();
return null;
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeDefaults(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeDefaults( ILaunchConfiguration configuration ) throws CoreException
{
if ( getPersistableSourceLocator() != null )
getPersistableSourceLocator().initializeDefaults( configuration );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.model.IPersistableSourceLocator#initializeFromMemento(java.lang.String)
*/
public void initializeFromMemento( String memento ) throws CoreException
{
if ( getPersistableSourceLocator() != null )
getPersistableSourceLocator().initializeFromMemento( memento );
}
private IPersistableSourceLocator getPersistableSourceLocator()
{
if ( fSourceLocator instanceof IPersistableSourceLocator )
return (IPersistableSourceLocator)fSourceLocator;
return null;
}
} }