0

Is there any way to count all if() (or else()) instructions without using BufferedReader to search for distinguish words ? If there isn't - how can I guess if the if() instruction inside the /* comment:

/*
if(*condition*){
*do something*
}
*/

is just a comment, not an instruction?

1 Answers1

0

Have a look at this answer: https://stackoverflow.com/a/22760693/981828

What you are trying to achieve is far from trivial,

You would have to use a parser such as ANTLR or JavaCC

edit:

alternativly you could run this perl one-liner from the command line, this should strip the file from all of its comments. If you are running windows, install cygwin.

perl -0pe 's#/\*(.|\n)*?\*/##g; s|//.*?\n|\n|g' test.java >> newfile.java

and then count if( and else( inside the newfile.java with a BufferedReader and Tokenizer

Community
  • 1
  • 1
Kristian Nissen
  • 1,153
  • 2
  • 11
  • 29