diff options
author | Mikhail Khodjaiants | 2005-03-22 00:11:28 +0000 |
---|---|---|
committer | Mikhail Khodjaiants | 2005-03-22 00:11:28 +0000 |
commit | 4bc76bbea7a9ceab68a613f1e125c01794f644d7 (patch) | |
tree | 739273c6b5f059e74c701995ad47495cb297c1e5 /debug/org.eclipse.cdt.debug.core | |
parent | ec85b24cb74c0931fbb930008fb30a27f7f7fd73 (diff) | |
download | org.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')
11 files changed, 657 insertions, 8 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 60a42785dd4..ffdb76b8f6d 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,16 @@ +2005-03-21 Mikhail Khodjaiants
+ Bug 80175: Replace the CDT source lookup by the source lookup provided by Eclipse platform.
+ * MappingSourceContainer.java: new
+ * DisassemblyBlock.java
+ * CSourceLookupDirector.java: new
+ * CSourceLookupParticipant.java: new
+ * CSourcePathComputerDelegate.java: new
+ * MapEntrySourceContainer.java: new
+ * MapEntrySourceContainerType.java: new
+ * MappingSourceContainerType.java: new
+ * plugin.properties
+ * plugin.xml
+
2005-03-17 Mikhail Khodjaiants
If casting of variable to a type or array causes an error, the status
of the variable is set to "error" and it can't be reset by subsequent castings.
diff --git a/debug/org.eclipse.cdt.debug.core/plugin.properties b/debug/org.eclipse.cdt.debug.core/plugin.properties index 64bb71bb2d2..9081fdc6313 100644 --- a/debug/org.eclipse.cdt.debug.core/plugin.properties +++ b/debug/org.eclipse.cdt.debug.core/plugin.properties @@ -16,4 +16,9 @@ CDebugger.name=C/C++ Development Tools Core Debugger Extension cLineBreakpoints.name=C/C++ Line Breakpoints cAddressBreakpoints.name=C/C++ Address Breakpoints cFunctionBreakpoints.name=C/C++ Function Breakpoints -cWatchpoints.name=C/C++ Watchpoints
\ No newline at end of file +cWatchpoints.name=C/C++ Watchpoints + +containerName.mapping=Path Mapping +containerDescription.mapping=A path mapping. +containerName.mapEntry=Path Map Entry +containerDescription.mapEntry=An entry in a path mapping.
\ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.core/plugin.xml b/debug/org.eclipse.cdt.debug.core/plugin.xml index e86efcd0ace..6743a70ff96 100644 --- a/debug/org.eclipse.cdt.debug.core/plugin.xml +++ b/debug/org.eclipse.cdt.debug.core/plugin.xml @@ -146,5 +146,31 @@ point="org.eclipse.core.runtime.preferences"> <initializer class="org.eclipse.cdt.debug.internal.core.CDebugCorePreferenceInitializer"/> </extension> + <extension + point="org.eclipse.debug.core.sourcePathComputers"> + <sourcePathComputer + class="org.eclipse.cdt.debug.internal.core.sourcelookup.CSourcePathComputerDelegate" + id="org.eclipse.cdt.debug.core.sourcePathComputer"/> + </extension> + <extension + point="org.eclipse.debug.core.sourceLocators"> + <sourceLocator + class="org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector" + name="C/C++ Source Locator" + id="org.eclipse.cdt.debug.core.sourceLocator"/> + </extension> + <extension + point="org.eclipse.debug.core.sourceContainerTypes"> + <sourceContainerType + class="org.eclipse.cdt.debug.internal.core.sourcelookup.MappingSourceContainerType" + description="%containerDescription.mapping" + id="org.eclipse.cdt.debug.core.containerType.mapping" + name="%containerName.mapping"/> + <sourceContainerType + class="org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainerType" + description="%containerDescription.mapEntry" + id="org.eclipse.cdt.debug.core.containerType.mapEntry" + name="%containerName.mapEntry"/> + </extension> </plugin> diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/MappingSourceContainer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/MappingSourceContainer.java new file mode 100644 index 00000000000..5efd225be44 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/sourcelookup/MappingSourceContainer.java @@ -0,0 +1,175 @@ +/********************************************************************** + * 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.core.sourcelookup; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +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.AbstractSourceContainer; +import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages; + +/** + * The source container for path mappings. + */ +public class MappingSourceContainer extends AbstractSourceContainer { + + /** + * Unique identifier for the mapping source container type + * (value <code>org.eclipse.cdt.debug.core.containerType.mapping</code>). + */ + public static final String TYPE_ID = CDebugCorePlugin.getUniqueIdentifier() + ".containerType.mapping"; //$NON-NLS-1$ + + private ArrayList fContainers; + + /** + * Constructor for MappingSourceContainer. + */ + public MappingSourceContainer() { + fContainers = new ArrayList(); + } + + /** + * Constructor for MappingSourceContainer. + */ + public MappingSourceContainer( MapEntrySourceContainer[] entries ) { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName() + */ + public String getName() { + return "Path Mappings"; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType() + */ + public ISourceContainerType getType() { + return getSourceContainerType( TYPE_ID ); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#isComposite() + */ + public boolean isComposite() { + return !fContainers.isEmpty(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String) + */ + public Object[] findSourceElements( String name ) throws CoreException { + return findSourceElements( name, getSourceContainers() ); + } + + protected Object[] findSourceElements( String name, ISourceContainer[] containers ) throws CoreException { + List results = null; + CoreException single = null; + MultiStatus multiStatus = null; + if ( isFindDuplicates() ) { + results = new ArrayList(); + } + for( int i = 0; i < containers.length; i++ ) { + ISourceContainer container = containers[i]; + try { + Object[] objects = container.findSourceElements( name ); + if ( objects.length > 0 ) { + if ( isFindDuplicates() ) { + for( int j = 0; j < objects.length; j++ ) { + results.add( objects[j] ); + } + } + else { + if ( objects.length == 1 ) { + return objects; + } + return new Object[]{ objects[0] }; + } + } + } + catch( CoreException e ) { + if ( single == null ) { + single = e; + } + else if ( multiStatus == null ) { + multiStatus = new MultiStatus( DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, new IStatus[]{ single.getStatus() }, SourceLookupMessages.getString( "CompositeSourceContainer.0" ), null ); //$NON-NLS-1$ + multiStatus.add( e.getStatus() ); + } + else { + multiStatus.add( e.getStatus() ); + } + } + } + if ( results == null ) { + if ( multiStatus != null ) { + throw new CoreException( multiStatus ); + } + else if ( single != null ) { + throw single; + } + return EMPTY; + } + return results.toArray(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer#getSourceContainers() + */ + public ISourceContainer[] getSourceContainers() throws CoreException { + return (MapEntrySourceContainer[])fContainers.toArray( new MapEntrySourceContainer[fContainers.size()] ); + } + + public void addMapEntry( MapEntrySourceContainer entry ) { + fContainers.add( entry ); + } + + public void addMapEntries( MapEntrySourceContainer[] entries ) { + fContainers.addAll( Arrays.asList( entries ) ); + } + + public void removeMapEntry( MapEntrySourceContainer entry ) { + fContainers.remove( entry ); + } + + public void removeMapEntries( MapEntrySourceContainer[] entries ) { + fContainers.removeAll( Arrays.asList( entries ) ); + } + + public void clear() { + Iterator it = fContainers.iterator(); + while( it.hasNext() ) { + ((ISourceContainer)it.next()).dispose(); + } + fContainers.clear(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.sourcelookup.ISourceContainer#dispose() + */ + public void dispose() { + super.dispose(); + Iterator it = fContainers.iterator(); + while( it.hasNext() ) { + ((ISourceContainer)it.next()).dispose(); + } + fContainers.clear(); + } +} 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 ); + } +} |