Stand-Alone Java Code Formatter/Beautifier/Pretty Printer

Stand-alone Java code formatter/beautifier/pretty printer?

JIndent (Commercial) does what you want:

http://www.jindent.com/

I've also used Jalopy in the past to do this, it's open source:

http://jalopy.sourceforge.net/

EDIT: I will note that Jalopy is fairly old and there doesn't seem to be any recent updates to it. I'm not quite sure if it will work with Java 5/6. You might want to look at Jacobe instead:

http://www.tiobe.com/index.php/content/products/jacobe/Jacobe.html

There's also a more complete list of formatters here on Roedy Green's site:

http://mindprod.com/jgloss/beautifier.html

Looking for Java code beautifier (or maybe not beautify, but something to make code more elegant)

Have a look at IntelliJ IDEA "Intentions":

  • http://blogs.jetbrains.com/idea/tag/intentions/
  • http://www.jetbrains.com/idea/documentation/intentions.jsp

Java Code Formatting

I guess i will use Eclipse's CodeFormatter, just like this guy: http://ssscripting.wordpress.com/2009/06/10/how-to-use-the-eclipse-code-formatter-from-your-code/

UPDATE:
ended up using jastyle ( http://sourceforge.net/projects/jastyle/ ).
here's an example:

public static String formatJavaCode(String code) throws Exception {
ASFormatter formatter = new ASFormatter();

// bug on lib's implementation. reported here: http://barenka.blogspot.com/2009/10/source-code-formatter-library-for-java.html
code.replace("{", "{\n");

Reader in = new BufferedReader(new StringReader(code));
formatter.setJavaStyle();
in.close();
return FormatterHelper.format(in,formatter);
}

Can the Eclipse Java formatter be used stand-alone

Apparently you can directly invoke Eclipse's code formatter from the command line.

Java program for code-formatting

There is an Ant external task for Jalopy.

  • http://ant.apache.org/external.html
  • http://jalopy.sourceforge.net/
  • http://ant.apache.org/faq.html#adding-external-tasks

Hope this helps

Automatically reformat long-lined Java code to 80 columns and still compile?

It's not as automated as you like, but in Eclipse you could define an 80-column profile (Preferences -> Java -> Code Style -> Formatter), then in the Package Explorer, right-click on your root package, and choose Source->Format.



Related Topics



Leave a reply



Submit