引入org.eclipse.cdt.core的插件包后.通过如下代码则可获得某个C++源文件的解析结果
- public static IASTTranslationUnit getAST( IFile file) {
- ITranslationUnit tu = CoreModelUtil.findTranslationUnit(file);
- ICProject project= tu.getCProject();
- IASTTranslationUnit ast=null;
- try {
- IIndex index = CCorePlugin.getIndexManager().getIndex(project,
- IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
- index.acquireReadLock();
- try {
- ast=tu.getAST(index,