AStyle Beautifier Plugin |
By Dirk Möbius
(dmoebius@gmx.net)
|
The AStyle Beautifier Plugin reformats and beautifies Java and C/C++ code.
This is done by using Artistic Style (also known as astyle)
by Tal Davidson (davidsont@bigfoot.com).
See http://astyle.sf.net for more
information.
The version currently used is Artistic Style 1.14.1.
You need at least JDK 1.1.6 and jEdit 3.2pre9.
Artistic Style is already contained in the AStyle Beautifier Plugin. There is no need to download it separately!
After installation, there is a new menu entry
Plugins>Beautify Buffer. If you invoke this action, the
current buffer will by reformatted. The internal action name of this action
is beautify
. (This gets used in macros.)
If the current buffer is in Java mode, AStyle assumes that the buffer
contains Java source code, and uses Java formatting routines.
If the current buffer is in C++ or C mode, AStyle assumes that
the buffer contains C/C++ source code, and uses C/C++ formatting routines.
The code will be indented according to the indentation settings of the current mode, ie. the options Indent width and Soft tabs. You can configure these options under Utilities>Global Options>Mode-Specific. Note that local Buffer Options override Mode-Specific default options.
You can change the style of the reformatted code with a myriad of options in the AStyle Plugin options dialog, available at Utilities>Global Options>Plugin Options>AStyle Beautifier. The dialogs have rich and self-explaining online help. Have a look!
JavaStyle is another source code beautifier plugin for jEdit. You might wonder why there are two beautifiers, and in what features they differ. Here's a short comparison:
The main difference is complexity.
AStyle is a line-by-line beautifier, that looks for certain keywords and structure characters like '{', remembers the current indent level and indents each line one a one-by-one basis. This is a fast and simple approach, but you cannot do certain things, like sorting methods etc.
JavaStyle is much more complex. It contains a full blown Java parser, similar to the javac compiler. It reads in the Java source code as a whole, builds an object tree, and effectively "redraws" the whole source code from scratch. The advantage is that you can to a lot more to the object tree before it is written out, for example sort methods by access modifier (public methods first), automatically generate JavaDoc tags etc. (You'll notice that JavaStyle has much more options than AStyle.) The disadvantage is that the source needs to be compilable before you can beautify it. AStyle does not have this requirement.
AStyle | JavaStyle | |
Advantages |
|
|
Disadvantages |
|
|
So, if you want simply to reindent your code with tabs or spaces, I would go for AStyle. But if you want to enforce a certain structure on your code, I would use JavaStyle. Some users complained, that sometimes JavaStyle does "too much", and that it cannot be switched off. For them, the AStyle plugin should be more suitable.
Attention! These software contains bugs! Use it at your own risk. I have no responsibility for whatever happens to your code, if you use this plugin on it. You may even loose all of your code! You have been warned.
--- That said, the AStyle Beautfier Plugin runs pretty well. This is because of the good quality of the underlying code beautifier Artistic Style, developed by Tal Davidson. Artistic Style is out for three years now and has undergone lots of release cycles, so it is pretty stabilized right now.
It is, however, written in C++, so I had to port it to Java to make it run inside jEdit. (Backport actually, because Artistic Style was originally written in Java three years ago.) This porting process may have introduced some new errors.
If you think you have found a bug in AStyle Plugin, please try to find out whether this is a bug in the Artistic Style code beautifier, or in the AStyle Plugin itself. You can check this by comparing the formatted results of your file with the output of the native version of Artistic Style (available at http://astyle.sf.net).
If you are sure the bug lies in the Artistic Style code beautifier, please inform Tal Davidson (davidsont@bigfoot.com).
If you are sure the bug lies in the AStyle Plugin itself, please inform me, that is, Dirk Möbius (dmoebius@gmx.net).
If you are too unskilled, or too lazy, or otherwise unable to tell the difference ;-), please inform me, that is, Dirk Möbius (dmoebius@gmx.net).
This plugin is licensed under the GNU General Public License (GPL), either version 2 or any later version. A copy of the license may be retrieved from http://www.fsf.org/copyleft/gpl.html.