mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Fixed search algorithm for nested folders.
This commit is contained in:
parent
4579380b9a
commit
d0ea6cb06e
1 changed files with 53 additions and 12 deletions
|
@ -9,6 +9,7 @@ import java.io.File;
|
||||||
|
|
||||||
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.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -112,23 +113,35 @@ public class CProjectSourceLocation implements ICSourceLocation
|
||||||
private Object findFileByAbsolutePath( String name )
|
private Object findFileByAbsolutePath( String name )
|
||||||
{
|
{
|
||||||
IPath path = new Path( name );
|
IPath path = new Path( name );
|
||||||
String fileName = path.toOSString();
|
return findFile( getProject(), 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 )
|
private Object findFileByRelativePath( String fileName )
|
||||||
{
|
{
|
||||||
IPath path = getProject().getLocation().append( fileName );
|
IPath path = getProject().getLocation().append( fileName );
|
||||||
return findFileByAbsolutePath( path.toOSString() );
|
Object result = findFileByAbsolutePath( path.toOSString() );
|
||||||
|
if ( result == null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IResource[] members = getProject().members();
|
||||||
|
for ( int i = 0; i < members.length; ++i )
|
||||||
|
{
|
||||||
|
if ( members[i] instanceof IFolder )
|
||||||
|
{
|
||||||
|
path = members[i].getLocation().append( fileName );
|
||||||
|
result = findFile( (IContainer)members[i], path.toOSString() );
|
||||||
|
if ( result != null )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( CoreException e )
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,4 +156,32 @@ public class CProjectSourceLocation implements ICSourceLocation
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object findFile( IContainer container, String fileName )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IResource[] members = container.members();
|
||||||
|
for ( int i = 0; i < members.length; ++i )
|
||||||
|
{
|
||||||
|
if ( members[i] instanceof IFile )
|
||||||
|
{
|
||||||
|
if ( members[i].getLocation().toOSString().equals( fileName ) )
|
||||||
|
return members[i];
|
||||||
|
}
|
||||||
|
else if ( members[i] instanceof IFolder )
|
||||||
|
{
|
||||||
|
Object result = findFile( (IContainer)members[i], fileName );
|
||||||
|
if ( result != null )
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( CoreException e )
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue