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

Fixed search algorithm for nested folders.

This commit is contained in:
Mikhail Khodjaiants 2002-09-25 22:24:17 +00:00
parent 4579380b9a
commit d0ea6cb06e

View file

@ -9,6 +9,7 @@ import java.io.File;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@ -112,23 +113,35 @@ public class CProjectSourceLocation implements ICSourceLocation
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;
return findFile( getProject(), path.toOSString() );
}
private Object findFileByRelativePath( String 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;
}
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;
}
}