title: Include header file in abstract syntax tree CDT
body: <p>Problem: I want generate function prototype if it doesn't exists, in the C file, I have done this, but in case if the prototype already exists in a header file it doesn't feel it, BTW I used CDT IIndex </p>
  
  <pre><code>//C Code
  #include "test.h" //where it have bar prototype
  void bar(void)
  {
      //function body
  }
  
  
  //Obtaining the AST [JAVA CDT CHECKER]
  ITranslationUnit tu = (ITranslationUnit) CDTUITools.getEditorInputCElement(editor.getEditorInput());
  String cFilePath = tu.getResource().getFullPath().toString();
  ICProject[] allProjects = CoreModel.getDefault().getCModel().getCProjects();
  IIndex **index** = CCorePlugin.getIndexManager().getIndex(allProjects);
  IASTTranslationUnit ast = null;
  try {
      index.acquireReadLock(); // we need a read-lock on the index
      ast = tu.getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
  } finally {
      index.releaseReadLock();
      ast = null; // don't use the ast after releasing the read-lock
  }
  
  
  //In the AST visitor class
  /**
   * extract prototype and store them into 'prototypes' hash set and then rewrite the AST.
   */
  @Override
  protected int visit(IASTSimpleDeclaration simpleDeclaration) {
      IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();  
      boolean isProtoFuncDeclaration = false;
      for (IASTDeclarator declarator: declarators) {
          if( declarator instanceof IASTFunctionDeclarator)
          {
              isProtoFuncDeclaration = true;
          }
      }   
      if(isProtoFuncDeclaration)
      {
          prototypes.add(simpleDeclaration);
      }
      return super.visit(simpleDeclaration);
  }
  </code></pre>
  
  <p>The output of the new C Code</p>
  
  <pre><code>#include "test.h" //where it have bar prototype
  void bar(void) &lt;=== I shouldn't be inserted as it is already in the header
  
  void bar(void)
  {
      //function body
  }
  </code></pre>