title: Getting total operators from Java file
body: <p>I am using the ASTParser in Java and am trying to find the number of operators in a sample java file.</p>
  
  <p>for example in this sample file</p>
  
  <pre><code>public class ArithmeticOperatorsExample {
  
          public static void main(String[] args) {
  
                  System.out.println("Arithmetic operators example :");
  
                  int i = 50 + 20;
                  int j = i - 10;
                  int k = j * 2;
                  double l = k / 6;
  
  
  
          }
  }
  </code></pre>
  
  <p>I should get an answer of 4. How would I use the ASTParser to get the total number of operators?</p>
  
  <p>This is what  I have so far, this just tracks the variables</p>
  
  <pre><code>import java.awt.List;
  import java.awt.print.Printable;
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  
  import org.eclipse.jdt.core.dom.AST;
  import org.eclipse.jdt.core.dom.ASTNode;
  import org.eclipse.jdt.core.dom.ASTParser;
  import org.eclipse.jdt.core.dom.ASTVisitor;
  import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
  import org.eclipse.jdt.core.dom.ChildPropertyDescriptor;
  import org.eclipse.jdt.core.dom.CompilationUnit;
  import org.eclipse.jdt.core.dom.SimpleName;
  import org.eclipse.jdt.core.dom.SimplePropertyDescriptor;
  import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
  
  public class Main {
  
      static StringBuffer buffer;
      static ASTParser parser;
  
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          readFile();
  
          runAstParser();
  
  
  
  }
  
      private static void runAstParser() {
          // TODO Auto-generated method stub
          parser=ASTParser.newParser(AST.JLS3);
          parser.setSource(buffer.toString().toCharArray());
          parser.setKind(ASTParser.K_COMPILATION_UNIT);
  
          final CompilationUnit cu=(CompilationUnit) parser.createAST(null);
          ASTVisitor c;
  
  
          cu.accept(new ASTVisitor() {
              Set names= new HashSet();
  
              public boolean visit(VariableDeclarationFragment node){
                  SimpleName name=node.getName();
  
  
                  this.names .add(name.getIdentifier());
                  System.out.println("Declaration of '" + name + "' at line "
                          + cu.getLineNumber(name.getStartPosition()));
  
                  return false;
              }
          });
  
  
  
      }
  
      private static void readFile() {
          // TODO Auto-generated method stub
          File javaFile=new File("C:/Users/Jacob_2/Eclipse/java-neon/eclipse/sampleJava.java");
          try {
              BufferedReader reader=new BufferedReader(new FileReader(javaFile));
              buffer=new StringBuffer();
              String line=null;
  
              while(null!=(line=reader.readLine())){
                  buffer.append(line).append("\n");
              }
          } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
  
  
  
  
      }
  }
  </code></pre>
  
  <p>anyone have any ideas on how to use ASTParser to get operators in a java file?</p>