Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Khodjaiants2005-03-22 00:11:28 +0000
committerMikhail Khodjaiants2005-03-22 00:11:28 +0000
commit4bc76bbea7a9ceab68a613f1e125c01794f644d7 (patch)
tree739273c6b5f059e74c701995ad47495cb297c1e5 /debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core
parentec85b24cb74c0931fbb930008fb30a27f7f7fd73 (diff)
downloadorg.eclipse.cdt-4bc76bbea7a9ceab68a613f1e125c01794f644d7.tar.gz
org.eclipse.cdt-4bc76bbea7a9ceab68a613f1e125c01794f644d7.tar.xz
org.eclipse.cdt-4bc76bbea7a9ceab68a613f1e125c01794f644d7.zip
Bug 80175: Replace the CDT source lookup by the source lookup provided by Eclipse platform.
Diffstat (limited to 'debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core')
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java17
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java52
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java60
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourcePathComputerDelegate.java48
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainer.java110
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainerType.java69
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MappingSourceContainerType.java88
7 files changed, 437 insertions, 7 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java
index 32c5220ae86..2b9d87855b9 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java
@@ -31,6 +31,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.model.ISourceLocator;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
/**
* CDI-based implementation of <code>IDisassemblyBlock</code>.
@@ -57,11 +58,7 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable {
public static DisassemblyBlock create( IDisassembly disassembly, ICDIMixedInstruction[] instructions ) {
DisassemblyBlock block = new DisassemblyBlock( disassembly );
block.setMixedMode( true );
- ISourceLocator adapter = disassembly.getDebugTarget().getLaunch().getSourceLocator();
- ICSourceLocator locator = null;
- if ( adapter instanceof IAdaptable ) {
- locator = (ICSourceLocator)((IAdaptable)adapter).getAdapter( ICSourceLocator.class );
- }
+ ISourceLocator locator = disassembly.getDebugTarget().getLaunch().getSourceLocator();
IAddressFactory factory = ((CDebugTarget)disassembly.getDebugTarget()).getAddressFactory();
block.setSourceLines( createSourceLines( factory, locator, instructions ) );
block.initializeAddresses();
@@ -136,12 +133,18 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable {
public void dispose() {
}
- private static IAsmSourceLine[] createSourceLines( IAddressFactory factory, ICSourceLocator locator, ICDIMixedInstruction[] mi ) {
+ private static IAsmSourceLine[] createSourceLines( IAddressFactory factory, ISourceLocator locator, ICDIMixedInstruction[] mi ) {
IAsmSourceLine[] result = new IAsmSourceLine[mi.length];
LineNumberReader reader = null;
if ( result.length > 0 && locator != null ) {
String fileName = mi[0].getFileName();
- Object element = locator.findSourceElement( fileName );
+ Object element = null;
+ if ( locator instanceof ISourceLookupDirector ) {
+ element = ((ISourceLookupDirector)locator).getSourceElement( fileName );
+ }
+ if ( locator instanceof ICSourceLocator ) {
+ element = ((ICSourceLocator)locator).findSourceElement( fileName );
+ }
File file= null;
if ( element instanceof IFile ) {
file = ((IFile)element).getLocation().toFile();
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java
new file mode 100644
index 00000000000..fba9b45caca
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupDirector.java
@@ -0,0 +1,52 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.sourcelookup;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
+import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
+import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
+import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer;
+import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer;
+import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
+import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer;
+
+/**
+ * C/C++ source lookup director.
+ */
+public class CSourceLookupDirector extends AbstractSourceLookupDirector {
+
+ private static Set fFilteredTypes;
+
+ static {
+ fFilteredTypes = new HashSet();
+ fFilteredTypes.add( WorkspaceSourceContainer.TYPE_ID );
+ fFilteredTypes.add( ProjectSourceContainer.TYPE_ID );
+ fFilteredTypes.add( FolderSourceContainer.TYPE_ID );
+ fFilteredTypes.add( DirectorySourceContainer.TYPE_ID );
+ fFilteredTypes.add( MappingSourceContainer.TYPE_ID );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceLookupDirector#initializeParticipants()
+ */
+ public void initializeParticipants() {
+ addParticipants( new ISourceLookupParticipant[]{ new CSourceLookupParticipant() } );
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceLookupDirector#supportsSourceContainerType(org.eclipse.debug.core.sourcelookup.ISourceContainerType)
+ */
+ public boolean supportsSourceContainerType( ISourceContainerType type ) {
+ return fFilteredTypes.contains( type.getId() );
+ }
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java
new file mode 100644
index 00000000000..32ab818afbf
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java
@@ -0,0 +1,60 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.sourcelookup;
+
+import org.eclipse.cdt.debug.core.model.ICStackFrame;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
+
+/**
+ * A source lookup participant that searches for C/C++ source code.
+ */
+public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
+
+ static private class NoSourceElement {
+ }
+
+ private static final NoSourceElement gfNoSource = new NoSourceElement();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#getSourceName(java.lang.Object)
+ */
+ public String getSourceName( Object object ) throws CoreException {
+ if ( object instanceof String ) {
+ return (String)object;
+ }
+ if ( object instanceof IAdaptable ) {
+ ICStackFrame frame = (ICStackFrame)((IAdaptable)object).getAdapter( ICStackFrame.class );
+ if ( frame != null ) {
+ String name = frame.getFile();
+ return ( name != null && name.trim().length() > 0 ) ? name : null;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant#findSourceElements(java.lang.Object)
+ */
+ public Object[] findSourceElements( Object object ) throws CoreException {
+ // Workaround for cases when the stack frame doesn't contain the source file name
+ if ( object instanceof IAdaptable ) {
+ ICStackFrame frame = (ICStackFrame)((IAdaptable)object).getAdapter( ICStackFrame.class );
+ if ( frame != null ) {
+ String name = frame.getFile();
+ if ( name == null || name.trim().length() == 0 )
+ return new Object[] { gfNoSource };
+ }
+ }
+ return super.findSourceElements( object );
+ }
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourcePathComputerDelegate.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourcePathComputerDelegate.java
new file mode 100644
index 00000000000..e98eeb1f8e2
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourcePathComputerDelegate.java
@@ -0,0 +1,48 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.sourcelookup;
+
+import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.sourcelookup.ISourceContainer;
+import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate;
+import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
+
+/**
+ * Computes the default source lookup path for a launch configuration.
+ */
+public class CSourcePathComputerDelegate implements ISourcePathComputerDelegate {
+
+ /**
+ * Constructor for CSourcePathComputerDelegate.
+ */
+ public CSourcePathComputerDelegate() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public ISourceContainer[] computeSourceContainers( ILaunchConfiguration configuration, IProgressMonitor monitor ) throws CoreException {
+ String projectName = configuration.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null );
+ if ( projectName != null ) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( projectName );
+ if ( project.exists() ) {
+ return new ISourceContainer[] { new ProjectSourceContainer( project, true ) };
+ }
+ }
+ return new ISourceContainer[0];
+ }
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainer.java
new file mode 100644
index 00000000000..cd02c9a398c
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainer.java
@@ -0,0 +1,110 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.sourcelookup;
+
+import java.io.File;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import org.eclipse.cdt.debug.core.CDebugCorePlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
+import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
+import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
+
+/**
+ * The source container that maps a backend path to the local filesystem path.
+ */
+public class MapEntrySourceContainer extends AbstractSourceContainer {
+
+ /**
+ * Unique identifier for the map entry source container type
+ * (value <code>org.eclipse.cdt.debug.core.containerType.mapEntry</code>).
+ */
+ public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapEntry"; //$NON-NLS-1$
+
+ private IPath fLocalPath;
+
+ private IPath fBackendPath;
+
+ /**
+ * Constructor for MapEntrySourceContainer.
+ */
+ public MapEntrySourceContainer( IPath backend, IPath local ) {
+ fBackendPath = backend;
+ fLocalPath = local;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
+ */
+ public Object[] findSourceElements( String name ) throws CoreException {
+ IPath path = new Path( name );
+ if ( getBackendPath().isPrefixOf( path ) ) {
+ path = path.removeFirstSegments( getBackendPath().segmentCount() );
+ path = getLocalPath().append( path );
+
+ IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path );
+ ArrayList list = new ArrayList();
+ for( int j = 0; j < wsFiles.length; ++j ) {
+ if ( wsFiles[j].exists() ) {
+ list.add( wsFiles[j] );
+ if ( !isFindDuplicates() )
+ break;
+ }
+ }
+ if ( list.size() > 0 )
+ return list.toArray();
+
+ File file = path.toFile();
+ if ( file.exists() && file.isFile() ) {
+ return new Object[] { new LocalFileStorage( file ) };
+ }
+ }
+ return EMPTY;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
+ */
+ public String getName() {
+ return MessageFormat.format( "{0} - {1}", new String[] { getBackendPath().toString(), getLocalPath().toOSString() } ); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
+ */
+ public ISourceContainerType getType() {
+ return getSourceContainerType( TYPE_ID );
+ }
+
+ protected IPath getLocalPath() {
+ return fLocalPath;
+ }
+
+ protected IPath getBackendPath() {
+ return fBackendPath;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals( Object o ) {
+ if ( !(o instanceof MapEntrySourceContainer ) )
+ return false;
+ MapEntrySourceContainer entry = (MapEntrySourceContainer)o;
+ return ( entry.getBackendPath().equals( getBackendPath() ) && entry.getLocalPath().equals( getLocalPath() ) );
+ }
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainerType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainerType.java
new file mode 100644
index 00000000000..c4af1e769c9
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MapEntrySourceContainerType.java
@@ -0,0 +1,69 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.sourcelookup;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.sourcelookup.ISourceContainer;
+import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * The map entry container type.
+ */
+public class MapEntrySourceContainerType extends AbstractSourceContainerTypeDelegate {
+
+ private final static String ELEMENT_NAME = "mapEntry"; //$NON-NLS-1$
+ private final static String BACKEND_PATH = "backendPath"; //$NON-NLS-1$
+ private final static String LOCAL_PATH = "localPath"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#createSourceContainer(java.lang.String)
+ */
+ public ISourceContainer createSourceContainer( String memento ) throws CoreException {
+ Node node = parseDocument( memento );
+ if ( node.getNodeType() == Node.ELEMENT_NODE ) {
+ Element element = (Element)node;
+ if ( ELEMENT_NAME.equals( element.getNodeName() ) ) {
+ String path = element.getAttribute( BACKEND_PATH );
+ IPath backend = new Path( path );
+ if ( !backend.isValidPath( path ) ) {
+ abort( "Source lookup: unable to restore map entry - missing backend path attribute.", null );
+ }
+ path = element.getAttribute( LOCAL_PATH );
+ IPath local = new Path( path );
+ if ( !local.isValidPath( path ) ) {
+ abort( "Source lookup: unable to restore map entry - missing local path attribute.", null );
+ }
+ return new MapEntrySourceContainer( backend, local );
+ }
+ abort( "Source lookup: unable to restore map entry - expecting map entry element.", null );
+ }
+ abort( "Source lookup: unable to restore map entry - invalid memento.", null );
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer)
+ */
+ public String getMemento( ISourceContainer container ) throws CoreException {
+ MapEntrySourceContainer entry = (MapEntrySourceContainer)container;
+ Document document = newDocument();
+ Element element = document.createElement( ELEMENT_NAME );
+ element.setAttribute( BACKEND_PATH, entry.getBackendPath().toOSString() );
+ element.setAttribute( LOCAL_PATH, entry.getLocalPath().toOSString() );
+ document.appendChild( element );
+ return serializeDocument( document );
+ }
+}
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MappingSourceContainerType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MappingSourceContainerType.java
new file mode 100644
index 00000000000..c597df2704a
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/MappingSourceContainerType.java
@@ -0,0 +1,88 @@
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
+package org.eclipse.cdt.debug.internal.core.sourcelookup;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.sourcelookup.ISourceContainer;
+import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
+import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainerTypeDelegate;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * The mapping container type.
+ */
+public class MappingSourceContainerType extends AbstractSourceContainerTypeDelegate {
+
+ private final static String ELEMENT_MAPPING = "mapping"; //$NON-NLS-1$
+ private final static String ELEMENT_MAP_ENTRY = "mapEntry"; //$NON-NLS-1$
+ private final static String ATTR_MEMENTO = "memento"; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#createSourceContainer(java.lang.String)
+ */
+ public ISourceContainer createSourceContainer( String memento ) throws CoreException {
+ Node node = parseDocument( memento );
+ if ( node.getNodeType() == Node.ELEMENT_NODE ) {
+ Element element = (Element)node;
+ if ( ELEMENT_MAPPING.equals( element.getNodeName() ) ) {
+ List entries = new ArrayList();
+ Node childNode = element.getFirstChild();
+ while( childNode != null ) {
+ if ( childNode.getNodeType() == Node.ELEMENT_NODE ) {
+ Element child = (Element)childNode;
+ if ( ELEMENT_MAP_ENTRY.equals( child.getNodeName() ) ) {
+ String childMemento = child.getAttribute( ATTR_MEMENTO );
+ if ( childMemento == null || childMemento.length() == 0 ) {
+ abort( "Source lookup: unable to restore map entry - expecting memnto attribute.", null );
+ }
+ ISourceContainerType type = DebugPlugin.getDefault().getLaunchManager().getSourceContainerType( MapEntrySourceContainer.TYPE_ID );
+ MapEntrySourceContainer entry = (MapEntrySourceContainer)type.createSourceContainer( childMemento );
+ entries.add( entry );
+ }
+ }
+ childNode = childNode.getNextSibling();
+ }
+ MappingSourceContainer container = new MappingSourceContainer();
+ Iterator it = entries.iterator();
+ while( it.hasNext() ) {
+ container.addMapEntry( (MapEntrySourceContainer)it.next() );
+ }
+ return container;
+ }
+ abort( "Source lookup: unable to restore mapping - expecting mapping element.", null );
+ }
+ abort( "Source lookup: unable to restore mapping - invalid memento.", null );
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate#getMemento(org.eclipse.debug.core.sourcelookup.ISourceContainer)
+ */
+ public String getMemento( ISourceContainer container ) throws CoreException {
+ Document document = newDocument();
+ Element element = document.createElement( ELEMENT_MAPPING );
+ ISourceContainer[] entries = ((MappingSourceContainer)container).getSourceContainers();
+ for ( int i = 0; i < entries.length; ++i ) {
+ Element child = document.createElement( ELEMENT_MAP_ENTRY );
+ child.setAttribute( ATTR_MEMENTO, entries[i].getType().getMemento( entries[i] ) );
+ element.appendChild( child );
+ }
+ document.appendChild( element );
+ return serializeDocument( document );
+ }
+}

Back to the top