Both the NetBeans IDE and Eclipse JDT projects have considerable Java code analysis/generation logic. I don't know what their dependencies are (i.e., can you use them as standalone libs), but other than that, I would take a good look at those two: it's unlikely there's a java code analysis library under more intensive development and more up to date.
Update:
PMD might be of interest as well:
PMD scans Java source code and looks for potential problems like:
* Possible bugs - empty try/catch/finally/switch statements
* Dead code - unused local variables, parameters and private methods
* Suboptimal code - wasteful String/StringBuffer usage
* Overcomplicated expressions - unnecessary if statements, for loops that could be while loops
* Duplicate code - copied/pasted code means copied/pasted bugs
Additionally, this blog entry discusses various static code analysis tools.