1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

Directory source locations:

- search only in the parent folders if the given file path is absolute.
- return a list only if the number of resulting files is > 1.
This commit is contained in:
Mikhail Khodjaiants 2003-10-28 22:38:31 +00:00
parent d95e065915
commit e87a867fe3
2 changed files with 26 additions and 15 deletions

View file

@ -1,3 +1,8 @@
2003-10-28 Mikhail Khodjaiants
Search only in the parent folders if the given file path is absolute.
Return a list only if the number of resulting files is > 1.
* CDirectorySourceLocation.java
2003-10-27 Mikhail Khodjaiants 2003-10-27 Mikhail Khodjaiants
Renamed 'SourceLocationFactory' to 'SourceLookupFactory'. Renamed 'SourceLocationFactory' to 'SourceLookupFactory'.
Added the 'createSourceLocator' method to 'SourceLookupFactory'. Added the 'createSourceLocator' method to 'SourceLookupFactory'.

View file

@ -91,7 +91,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
public Object findSourceElement( String name ) throws CoreException public Object findSourceElement( String name ) throws CoreException
{ {
Object result = null; Object result = null;
if ( getDirectory() != null ) if ( !isEmpty( name ) && getDirectory() != null )
{ {
File file = new File( name ); File file = new File( name );
if ( file.isAbsolute() ) if ( file.isAbsolute() )
@ -187,7 +187,8 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
return result; return result;
} }
} }
return list; if ( list.size() > 0 )
return ( list.size() == 1 ) ? list.getFirst() : list;
} }
return null; return null;
} }
@ -200,17 +201,12 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
IPath filePath = new Path( name ); IPath filePath = new Path( name );
IPath path = new Path( folder.getAbsolutePath() ); IPath path = new Path( folder.getAbsolutePath() );
IPath association = getAssociation(); IPath association = getAssociation();
if ( isPrefix( path, filePath ) ) if ( !isPrefix( path, filePath ) || path.segmentCount() + 1 != filePath.segmentCount() )
{ {
filePath = path.append( filePath.removeFirstSegments( path.segmentCount() ) ); if ( association != null && isPrefix( association, filePath ) && association.segmentCount() + 1 == filePath.segmentCount() )
} filePath = path.append( filePath.removeFirstSegments( association.segmentCount() ) );
else if ( association != null && isPrefix( association, filePath ) ) else
{ return null;
filePath = path.append( filePath.removeFirstSegments( association.segmentCount() ) );
}
else
{
return null;
} }
// Try for a file in another workspace project // Try for a file in another workspace project
@ -226,7 +222,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
return ( list.size() == 1 ) ? list.getFirst() : list; return ( list.size() == 1 ) ? list.getFirst() : list;
file = filePath.toFile(); file = filePath.toFile();
if ( file.exists() ) if ( file.exists() && file.isFile() )
{ {
return createExternalFileStorage( filePath ); return createExternalFileStorage( filePath );
} }
@ -257,7 +253,8 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
return result; return result;
} }
} }
return list; if ( list.size() > 0 )
return ( list.size() == 1 ) ? list.getFirst() : list;
} }
return null; return null;
} }
@ -267,7 +264,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
IPath path = new Path( folder.getAbsolutePath() ); IPath path = new Path( folder.getAbsolutePath() );
path = path.append( fileName ); path = path.append( fileName );
File file = path.toFile(); File file = path.toFile();
if ( file.exists() ) if ( file.exists() && file.isFile() )
{ {
path = new Path( file.getAbsolutePath() ); path = new Path( file.getAbsolutePath() );
IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path ); IFile[] wsFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path );
@ -458,6 +455,7 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
public void setSearchSubfolders( boolean search ) public void setSearchSubfolders( boolean search )
{ {
resetFolders();
fSearchSubfolders = search; fSearchSubfolders = search;
} }
@ -502,4 +500,12 @@ public class CDirectorySourceLocation implements IDirectorySourceLocation
list.addAll( getFileFolders( folders[i] ) ); list.addAll( getFileFolders( folders[i] ) );
return list; return list;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
return ( getDirectory() != null ) ? getDirectory().toOSString() : "";
}
} }