Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] CDT/IASTPreprocessorStatement/get all preprocessor statements of c file

Hello All,
I'd like to get all preprocessor statements in all C files in my C project. I used Google to try to find any answer on the Web. I tried to develop a Plug-in to get all preprocessor statements by using ITranslationUnit of CDT AST. My problem is that I don't get anything showing up when i run my Plug-in. I tried to get the active source file in C editor like this:
IWorkbenchPage actPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart actEditor = null;
if (actPage.isEditorAreaVisible()
&& actPage.getActiveEditor() != null
&& actPage.getActiveEditor() instanceof CEditor) {
actEditor = actPage.getActiveEditor();}
IEditorInput editorInput = actEditor.getEditorInput();
IFile aFile = null;
if (editorInput instanceof IEditorInput){
aFile = ((IFileEditorInput)editorInput).getFile();

And I tried to get the TranslationUnit of this source file like:
ITranslationUnit tu = CoreModelUtil.findTranslationUnit(aFile);
IASTTranslationUnit ast = tu.getAST();
List<IASTPreprocessorStatement> pps = new ArrayList<IASTPreprocessorStatement>();
IASTPreprocessorStatement[] preList = ast.getAllPreprocessorStatements();
for (IASTPreprocessorStatement iastPreprocessorStatement : preList) {

Please help me figure out what additional diagnostics I can run to achieve enlightenment.

Back to the top