[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] ITranslanUnits/IASTTranslationUnits from ICProject
|
Thanks for pointing out the error with the call to getCModel().
Walking the IResource tree seems to be several orders of magnitude faster. For anyone else that is trying to do the same thing:
private List<ITranslationUnit> GetTranslationUnitsForWorkspace()
{
final List<ITranslationUnit> translationUnits = new ArrayList<ITranslationUnit>();
translationUnits.clear();
try
{
ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor()
{
@Override
public boolean visit(IResource resource) throws CoreException
{
if (resource instanceof IFile)
{
IFile file = (IFile) resource;
ITranslationUnit tu = CoreModelUtil.findTranslationUnit(file);
if(tu!=null)
translationUnits.add(tu);
}
return true;
}
});
}
catch (CoreException e)
{e.printStackTrace();}
return translationUnits;
}
Thanks again, I really appreciate the help.
Chris
On Mon, May 9, 2011 at 2:48 PM, Schaefer, Doug
<Doug.Schaefer@xxxxxxxxxxxxx> wrote:
There’s no flat list of translation units of that’s what you are asking. What’s probably slowing you down is that we need to figure out whether a file actually is a translation unit or not, as opposed to a binary file for example. I’m not sure what’s all involved in that check but it might be doing a parse of your file. You might want to walk the IResource tree looking for files of the C content types. I don’t know all the details on how to do that.
BTW, note that getCModel() jumps up a level in the hierarchy and you are actually getting the translation units for all projects here. Just call accept on the ICProject.
Doug.
From your response, here is what I came up with:
private List<ITranslationUnit> GetTranslationUnitsForProject(ICProject iCProject)
{
final List<ITranslationUnit> translationUnits = new ArrayList<ITranslationUnit>();
try
{
iCProject.getCModel().accept(new ICElementVisitor()
{
@Override
public boolean visit(ICElement element) throws CoreException
{
if (element instanceof ICContainer)
{
ICContainer container = (ICContainer) element;
translationUnits.addAll(Arrays.asList(container.getTranslationUnits()));
}
return true;
}
});
}
catch (CoreException e)
{ e.printStackTrace(); }
return translationUnits;
}
The problem is that with my very large project this takes a while. Is this the most optimal way of getting the ITranslationUnits for a given project?
On Mon, May 9, 2011 at 10:58 AM, Schaefer, Doug <Doug.Schaefer@xxxxxxxxxxxxx> wrote:
CDOM was deprecated since we have better ways of getting the same information. The best place to start is with the CModel starting at ICProject, going through the ICContainers to find the ITranslationUnits and then from there get the AST.
Been a while since I worked in that area, though. Do others have other approaches?
Doug
Given and ICProject, what is the best way to get all of the ITranslanUnits/IASTTranslationUnits for all files contained in the project? Most of the examples I see are from CDT 3.0 and I also noticed that the CDOM class was deprecated.
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev
--
Chris Andrews
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev
--
Chris Andrews