Postby allistar » Fri Nov 27, 2009 9:46 am
What do you mean by "code complexity"? That could be defined in a number of ways. The number of lines in a single method, how an algorithm recurses, how much complicated mathematics is in it, the number of different objects touched by a method call, the number of distinct paths through a method.
A couple of years ago I developed a Jade code analyser (written in Jade) which allows you to analyse either metadata or code itself. It parses one or more Jade methods to give an abstract syntax tree (AST - essentially a hierarchical tree of objects representing the method) which you can then analyse. It can be used for simple code review, such as "does this method leak an iterator" which is a simple rule to implement. Once you had defined what is meant by "code complexity" you could then build some rules that takes the AST and determines the complexity of the code.