title: How to print all method declaration and invocation from ASTParser
body: <p>I want to print all the method invocations within all methods of a Class. I am using ASTParser. Following is my code</p>
  
  <pre><code>import org.eclipse.jdt.core.dom.AST;
  import org.eclipse.jdt.core.dom.ASTParser;
  import org.eclipse.jdt.core.dom.CompilationUnit;
  import java .io.*;
  
  public class ASTParserDemo {
  public static void main(String[] args) {
  
  
      ASTParserDemo demo = new ASTParserDemo();
      String rawContent = demo.readFile();
  
      //String rawContent = "public class HelloWorld { public String s = \"hello\"; public static void main(String[] args) { HelloWorld hw = new HelloWorld(); String s1 = hw.s; } }";
      ASTParser parser = ASTParser.newParser(AST.JLS3);
      parser.setSource(rawContent.toCharArray());
      parser.setKind(ASTParser.K_COMPILATION_UNIT);
      final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
      AST ast = cu.getAST();
      IdentifierVisitor iv = new IdentifierVisitor();
      cu.accept(iv);
  
  }
  
  public String readFile() {
      StringBuffer fileContent = new StringBuffer();
      BufferedReader br = null;
      try {
          String sCurrentLine;
          br = new BufferedReader(new FileReader("C:\\research\\android-projects\\AsyncSearch.java"));
  
          while ((sCurrentLine = br.readLine()) != null) {
              //System.out.println(sCurrentLine);
              fileContent.append(sCurrentLine);
          }
  
      } catch (IOException e) {
          e.printStackTrace();
      } finally {
          try {
              if (br != null)br.close();
          } catch (IOException ex) {
              ex.printStackTrace();
          }
      }
      return fileContent.toString();
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>import org.eclipse.jdt.core.dom.*;
  
  import java.util.*;
  
  public class IdentifierVisitor extends ASTVisitor {
  
  private Vector&lt;String&gt; identifiers = new Vector&lt;String&gt;();
  
  public Vector&lt;String&gt; getIdentifiers(){
      return identifiers; 
  }
  
  
  public boolean visit(MethodDeclaration m){
      System.out.println("METHOD DECLARATION : " + m);
      return true;
  }
  
  public boolean visit(MethodInvocation m){
      System.out.println("METHOD INVOCATION : " + m);
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>the output is showing only one method declaration. Please let me know how do I print all method invocations within all declared methods. Thanks</p>