FixStyle

FixStyle

FixStyle is a automatic code style improver for Java.

It acts much like a formatter. However currently it does no formatting.

What it does do is to sort modifiers into the order recommended in the Java language specification] - and [other documents].

Keeping a consistent modifier order helps improve clarity.

The order used is:

public, protected, private, abstract, static, final, transient, volatile, synchronized, native, strictfp.

Execution

The program has a command-line interface - use fixstyle.Fixstyle <infile> <outfile> to run it.

There's also a GUI. Here's a snapshot of it in action:

Recursion

Provide a directory and it will deal with it recursively, dealing with all the java source files it finds beneath it.

Misc

The program was constructed using JavaCC and JJTree. These are open source products.

However it does not contain them - and is itself in the public domain.

Jalopy

The formatter Jalopy also does the sorting described here: there's a description here.

Jalopy does many other things as well - but unfortunately not all of them can be turned off - and I don't currently feel able to run my code through it.

Aims

The aims here are to:

  • Build a foundation for a Java source formatter which allows all its features to be turned off - allowing it to be used uninvasively.

  • Build a tool to automatically fix lint various lint problems. Hopefully these fixes can be presented to the user of IDEs as "quick fixes" - as well as being applied to entire projects.

Unicode philosophy

Currently unicode characters are converted to characters on loading - and back to unicode on saving. This won't change the function of a program - but may change which characters are unicoded.

Preserving existing unicoding is on the wishlist.

Wishlist

What else is on the wishlist?

Currently it looks like this:

  • Add/remove final method parameters...
  • Remove unused modifiers from interfaces...
  • Move square brackets to the left in array type declarations...
  • Add braces onto if/do/while/for statements that lack them...
  • Expand code substantially to handle formatting and indentation...

Java Web Start

If you run using Java Web Start, the program will request access to your machine on the basis of my phony developer certificate.

It's signed because the program needs to read and write files in bulk from your hard drive to be much use.

The certificate is phony because I haven't paid up for an authenticated certificate yet.

Disclaimer

While I've tested this software - and it seems to work acceptably - you use it at your own risk - and I recommend you back things up before using it on a whole project.

It's been tested on Java 1.4 code. I make no claim that it will function correctly on Java 1.5 code (e.g. code using generics) without recompilation.

Download

Run using Java Web Start.

Download the executable Jar file.

Download the Java source code.


Index | Links


tim@tt1.org | http://mandala.co.uk/