依赖CDT版本为5.0
导入org.eclipse.cdt.core插件
导入org.eclipse.cdt.core插件
//获取编译单元.file为IFile类型,tu是一个树结构,记录了C++/C代码的各种语法元素
ITranslationUnit tu = CoreModelUtil.findTranslationUnit(file);
//获取C++的文件的元素.ICElement是CDT CoreModel的核心接口,是C++/C代码的各种
//元素的父接口
ICElement[] elements = tu.getChildren();
//这时elements有INameSpace,IStructure等元素
//遍历获得一个IStructure元素(C++的类定义)
IStructure structure = (IStructure) element;
//获取类定义的方法声明
IMethodDeclaration[] methods = structure.getMethods();
//获取类成员
IField[] field = structure.getFields();
//对ICElement调用getElementName方法就获得类名.方法名,字段名等信息