Eric Burke posed a challenge for next week to post the longest human-coded method.
I mentioned in his comments that you can use JavaNCSS for this. Just in case that wasn’t quite enough detail, here’s a brief sketch of how to do so. You’ll need to make some tweaks for your environment but I think you’ll get the idea.
- Go to the link above, download JavaNCSS and expand it
- export JAVA_HOME=…
- export JAVANCSS_HOME=…
- export PATH=$PATH:$JAVANCSS_HOME/bin
This is just to run some XSLT stylesheets on the output XML file.
- Download Xalan from Apache and expand it somewhere
- export XALAN_HOME=…
- export CLASSPATH=$XALAN_HOME/xalan.jar:\
$XALAN_HOME/xercesImpl.jar:\ $XALAN_HOME/xml-apis.jar:\ $XALAN_HOME/serializer.jar
Run JavaNCSS on your source tree
- cd …root of all source files…
- javancss -all -xml -out $JAVANCSS_HOME/ncss.xml -recursive *
Transform the output
- cd $JAVANCSS_HOME
- java org.apache.xalan.xslt.Process -in ncss.xml -xsl xslt/wfncss.xsl -out ncss.html
You will now have an ncss.html file generated from your output that you can use to look for huge methods (and other interesting bad stuff).
If you want to be more precise about including many source trees, more work is involved. I wrote an Ant task to make this easier (the referenced one didn’t work for me on modern Ant versions) but I don’t have the code anymore. Ant does such a nice job making it easy to collect source flexibly! I’ll leave this as an exercise for the reader….
There are a bunch of XSLT reports in $JAVANCSS_HOME/xslt. You might find others more interesting. The one I chose just outputs violations of the default warning levels. It doesn’t sort the output as nicely as you’d wish, but should cut it down enough to scan it by eye. Or, you can modify it to sort as desired. Another exercise for the reader…
Hope that helped. You might learn some other interesting stuff here as well if you’ve never looked at your source stats!
PS. 707 was the longest human-coded method I found in our source.