Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] CDT DOM Usage

On Wed, 2005-09-28 at 14:39 -0400, Nick Allen wrote:
> BTW, for now I am simply trying to parse a file and determine the C++
> classes which have been declared in that file.

At this point, I have found that I can do the following.  Any criticisms
on the following code would be appreciated.  

IFile file = ...
IASTTranslationUnit ast = CDOM.getInstance().getTranslationUnit(file);
CPPNameCollector col = new CPPNameCollector();
ast.accept(col);
	        
Iterator i = col.nameList.iterator();
while (i.hasNext()) {
	IASTName n = (IASTName) i.next();
	IBinding binding = n.resolveBinding();
	
	if(binding instanceof CPPClassType) {
		// do something with the class
	}
}

Small code examples like this would certainly help those unfamaliar with
the new CDT DOM become familiar.

Thanks
Nick


Nick Allen <nwa@xxxxxxxxxxxxxxxx>



Back to the top