mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Implementation of source locator.
This commit is contained in:
parent
941618eaca
commit
2e5306c7b2
6 changed files with 106 additions and 53 deletions
|
@ -6,19 +6,14 @@
|
|||
|
||||
package org.eclipse.cdt.debug.core;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISourceManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
||||
import org.eclipse.cdt.debug.internal.core.CSourceLocator;
|
||||
import org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint;
|
||||
import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint;
|
||||
import org.eclipse.cdt.debug.internal.core.model.CDebugElement;
|
||||
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
|
||||
import org.eclipse.cdt.debug.internal.core.model.CExpression;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
|
@ -98,17 +93,6 @@ public class CDebugModel
|
|||
{
|
||||
final IDebugTarget[] target = new IDebugTarget[1];
|
||||
|
||||
// Temporary
|
||||
try
|
||||
{
|
||||
ICDISourceManager mgr = cdiTarget.getSession().getSourceManager();
|
||||
mgr.addSourcePaths( new String[] { project.getLocation().toOSString() });
|
||||
}
|
||||
catch( CDIException e )
|
||||
{
|
||||
CDebugCorePlugin.log( e );
|
||||
}
|
||||
|
||||
IWorkspaceRunnable r = new IWorkspaceRunnable()
|
||||
{
|
||||
public void run( IProgressMonitor m )
|
||||
|
|
|
@ -116,20 +116,23 @@ public class CDirectorySourceLocation implements ICSourceLocation
|
|||
private Object findFileByRelativePath( String fileName )
|
||||
{
|
||||
IPath path = getDirectory();
|
||||
path.append( fileName );
|
||||
|
||||
// Try for a file in another workspace project
|
||||
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
|
||||
if ( f != null )
|
||||
if ( path != null )
|
||||
{
|
||||
return f;
|
||||
}
|
||||
|
||||
File file = path.toFile();
|
||||
if ( file.exists() )
|
||||
{
|
||||
return createExternalFileStorage( path );
|
||||
}
|
||||
path = path.append( fileName );
|
||||
|
||||
// Try for a file in another workspace project
|
||||
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path );
|
||||
if ( f != null )
|
||||
{
|
||||
return f;
|
||||
}
|
||||
|
||||
File file = path.toFile();
|
||||
if ( file.exists() )
|
||||
{
|
||||
return createExternalFileStorage( path );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -137,4 +140,12 @@ public class CDirectorySourceLocation implements ICSourceLocation
|
|||
{
|
||||
return new FileStorage( path );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getPaths()
|
||||
*/
|
||||
public IPath[] getPaths()
|
||||
{
|
||||
return new IPath[] { fDirectory };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
*/
|
||||
package org.eclipse.cdt.debug.core.sourcelookup;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -41,17 +43,11 @@ public class CProjectSourceLocation implements ICSourceLocation
|
|||
{
|
||||
if ( getProject() != null )
|
||||
{
|
||||
IPath path = new Path( name );
|
||||
String fileName = path.toOSString();
|
||||
|
||||
String pPath = new String( getProject().getLocation().toOSString() );
|
||||
int i = 0;
|
||||
if ( (i = fileName.indexOf( pPath )) >= 0 )
|
||||
{
|
||||
i += pPath.length() + 1;
|
||||
if ( fileName.length() > i )
|
||||
return getProject().getFile( fileName.substring( i ) );
|
||||
}
|
||||
File file = new File( name );
|
||||
if ( file.isAbsolute() )
|
||||
return findFileByAbsolutePath( name );
|
||||
else
|
||||
return findFileByRelativePath( name );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -112,4 +108,38 @@ public class CProjectSourceLocation implements ICSourceLocation
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object findFileByAbsolutePath( String name )
|
||||
{
|
||||
IPath path = new Path( name );
|
||||
String fileName = path.toOSString();
|
||||
|
||||
String pPath = new String( getProject().getLocation().toOSString() );
|
||||
int i = 0;
|
||||
if ( (i = fileName.indexOf( pPath )) >= 0 )
|
||||
{
|
||||
i += pPath.length() + 1;
|
||||
if ( fileName.length() > i )
|
||||
return getProject().getFile( fileName.substring( i ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object findFileByRelativePath( String fileName )
|
||||
{
|
||||
return getProject().getFile( fileName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation#getPaths()
|
||||
*/
|
||||
public IPath[] getPaths()
|
||||
{
|
||||
IPath[] result = new IPath[0];
|
||||
if ( getProject() != null )
|
||||
{
|
||||
result = new IPath[] { getProject().getLocation() };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.eclipse.cdt.debug.internal.core;
|
||||
package org.eclipse.cdt.debug.core.sourcelookup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||
import org.eclipse.cdt.debug.core.IStackFrameInfo;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.CProjectSourceLocation;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
|
||||
import org.eclipse.cdt.debug.internal.core.model.*;
|
||||
import org.eclipse.core.internal.resources.File;
|
||||
import org.eclipse.core.resources.IContainer;
|
|
@ -7,6 +7,7 @@ package org.eclipse.cdt.debug.core.sourcelookup;
|
|||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -35,4 +36,11 @@ public interface ICSourceLocation extends IAdaptable
|
|||
* @exception CoreException if an exception occurs while searching for the specified source element
|
||||
*/
|
||||
Object findSourceElement( String name ) throws CoreException;
|
||||
|
||||
/**
|
||||
* Returns the paths associated with this location.
|
||||
*
|
||||
* @return the paths associated with this location
|
||||
*/
|
||||
IPath[] getPaths();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.eclipse.cdt.debug.internal.core.model;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -35,6 +34,7 @@ import org.eclipse.cdt.debug.core.cdi.ICDILocation;
|
|||
import org.eclipse.cdt.debug.core.cdi.ICDIRegisterObject;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISessionObject;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISignal;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISourceManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointScope;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointTrigger;
|
||||
import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent;
|
||||
|
@ -53,16 +53,15 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
|
|||
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.CDirectorySourceLocation;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.CSourceLocator;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
|
||||
import org.eclipse.cdt.debug.internal.core.CSourceLocator;
|
||||
import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
|
||||
import org.eclipse.core.resources.IMarkerDelta;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.debug.core.DebugEvent;
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
|
@ -235,6 +234,7 @@ public class CDebugTarget extends CDebugElement
|
|||
protected void initialize()
|
||||
{
|
||||
initializeState();
|
||||
setSourceSearchPath();
|
||||
initializeBreakpoints();
|
||||
initializeRegisters();
|
||||
getLaunch().addDebugTarget( this );
|
||||
|
@ -1844,10 +1844,33 @@ public class CDebugTarget extends CDebugElement
|
|||
|
||||
protected ISourceLocator createSourceLocator( IProject project )
|
||||
{
|
||||
CSourceLocator locator = new CSourceLocator( project );
|
||||
List list = Arrays.asList( locator.getSourceLocations() );
|
||||
list.add( new CDirectorySourceLocation( new Path( project.getLocation().toOSString() ) ) );
|
||||
locator.setSourceLocations( (ICSourceLocation[])list.toArray( new ICSourceLocation[list.size()] ) );
|
||||
return locator;
|
||||
return new CSourceLocator( project );
|
||||
}
|
||||
|
||||
protected void setSourceSearchPath()
|
||||
{
|
||||
ICDISourceManager mgr = getCDISession().getSourceManager();
|
||||
ISourceLocator locator = getLaunch().getSourceLocator();
|
||||
ArrayList list = new ArrayList();
|
||||
if ( locator != null && locator instanceof ICSourceLocator )
|
||||
{
|
||||
ICSourceLocation[] locations = ((ICSourceLocator)locator).getSourceLocations();
|
||||
for ( int i = 0; i < locations.length; ++i )
|
||||
{
|
||||
IPath[] paths = locations[i].getPaths();
|
||||
for ( int j = 0; j < paths.length; ++j )
|
||||
{
|
||||
list.add( paths[j].toOSString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
mgr.addSourcePaths( (String[])list.toArray( new String[list.size()] ) );
|
||||
}
|
||||
catch( CDIException e )
|
||||
{
|
||||
CDebugCorePlugin.log( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue