I am looking into calculating the cyclomatic complexity of java methods using Rascal.
One approach to this would be:
- getting the AST from the method
- use visit pattern on this tree
- check for the following keywords which all increase the CC with one:
case
,catch
,do
,while
,if
,for
,foreach
Another one is using graph theory and using the formula e-n+2.
both e and n can be obtained quite easily using rascal functionality. My problem is how do I go about constructing the control flow graph, I found the following module:
analysis::flow::ControlFlow
which seems to be a step in the right direction but I am totally lost on where to go from there.