Вот что я использовал, чтобы найти все c файлы в текущем проекте:
public static ArrayList<IResource> getAllCFilesInProject(){
ArrayList<IResource> allCFiles = new ArrayList<IResource>();
IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IProject project = FileParaviserUtils.getCurrentProject();
IPath path = project.getLocation();
recursiveFindCFiles(allCFiles,path,myWorkspaceRoot);
return allCFiles;
}
private static void recursiveFindCFiles(ArrayList<IResource> allCFiles,IPath path, IWorkspaceRoot myWorkspaceRoot){
IContainer container = myWorkspaceRoot.getContainerForLocation(path);
try {
IResource[] iResources;
iResources = container.members();
for (IResource iR : iResources){
// for c files
if ("c".equalsIgnoreCase(iR.getFileExtension()))
allCFiles.add(iR);
if (iR.getType() == IResource.FOLDER){
IPath tempPath = iR.getLocation();
recursiveFindCFiles(allCFiles,tempPath,myWorkspaceRoot);
}
}
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static IProject getCurrentProject(){
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null)
{
IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IAdaptable)
{
IProject project = (IProject)((IAdaptable)firstElement).getAdapter(IProject.class);
return project;
}
}
return null;
}