Count Number of Statements in a Java Method By Using Eclipse JDT ASTParser

This tutorial belongs to Eclipse JDT Tutorial Series.

Given a method, we may want a count of the number of statements in the method (for ex: to gauge the complexity of the method). We can use eclipse JDT ASTParser to get this job done.

One approximate way to count the number of statements in a method is to count the number of lines ending with the semi-colon along with lines that contain the words “if/for/while/”.

Read more