File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Cyclomatic Complexity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

Cyclomatic Complexity

John Weir

Joined: Nov 20, 2004
Posts: 6
Having successfully coded a program that measures the Cyclomatic Complexity of a Java Source code file using the String Tokenizer class. I am in the middle of coding another using the Java Regex class for learning purposes.

Is it possible by using the Java Regex class to Ignore comments from a file being read without using the slashSlash from the StreamTokenizer? I tried COMMENTS in the Regex class but had no luck.

Pattern pattern = Pattern.compile("if|for|while|case|switch",Pattern.COMMENTS);

How can the line above get sorted so that my count will only count the keyWords and not be greedy and count the "If" in " I found out " .

Please help !

John Weir
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

Please don't post the same question in multiple forums. I'm closing this one and leaving the one in JiG (Intermediate) open.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Cyclomatic Complexity
jQuery in Action, 3rd edition