我想我会像这个人一样使用Eclipse的CodeFormatter:http
://ssscripting.wordpress.com/2009/06/10/how-to-use-the-eclipse-pre-formatter-
from-your-pre/
更新:
最终使用jastyle(http://sourceforge.net/projects/jastyle/)。这是一个例子:
public static String formatJavaCode(String pre) throws Exception { ASFormatter formatter = new ASFormatter(); // bug on lib's implementation. reported here: http://barenka.blogspot.com/2009/10/source-pre-formatter-library-for-java.html pre.replace("{", "{n"); Reader in = new BufferedReader(new StringReader(pre)); formatter.setJavaStyle(); in.close(); return FormatterHelper.format(in,formatter);}


