JavaStyle Plugin |
By Dirk Möbius (dmoebius@gmx.net)
Mike Atkinson (JavaStyle@ladyshot.demon.co.uk) And Chris Seguin (seguin@acm.org) |
Introduction
Usage
Bugs
Comparison JavaStyle vs. AStyle
Disclaimer
Change Log
License Information
The JavaStyle plugin has several different functions:
You need at least:
Note: The JRefactory library is already contained in JavaStyle. There is no need to download it separately!
This is done by using the PrettyPrinter from the
JRefactory library by Chris Seguin
(seguin@acm.org) and Mike Atkinson (JavaStyle@ladyshot.demon.co.uk).
Select
Plugins->JavaStyle->Reformat Buffer
The current buffer is reformated according to the current JavaStyle
settings. These settings may be different for each project in the
"Project Viewer" plugin.
The code will be indented according to the indentation settings of the Java mode, ie. the options Indent width and Soft tabs. You can configure these options for the Java mode under Utilities->Global Options->Editing.
You can change the style of the reformatted Java code with a myriad of options in the JavaStyle plugin options dialogs, available at Plugins->Plugin Options... look at the tabs under the JavaStyle tab. The dialogs have rich and self-explaining online help. Have a look!
You can also change the options by selecting Plugins->JavaStyle->Options...
The option pane will be shown (it might be a bit slow if there are
lots of projects defined in the "Project Viewer" plugin)
Select Plugins->JavaStyle->JRefactory... or click on the JavaStyle tab if the plugin is open.
Select the "Cut & Paste Detector" tab .
There are three options:
For the last two cases a file selection window will appear. Select the base directory you require.
After a few seconds (it should not be long even for a large amount of source code), a tree view of all the common sections of code will be shown. Selecting on these will show the Cut & Pasted sections of code highlighted.
Select Plugins->JavaStyle->JRefactory... or click on the JavaStyle tab if the plugin is open.
Select the "Coding standards" tab .
There are three options:
For the last two cases a file selection window will appear. Select the base directory you require.
At a rate few of files per second on average, a tree view of all the coding standard warnings will be shown. Any open buffers will also have the warnings shown in the gutter and the ErrorList plugin if loaded will also have the warnings. Selecting on these will go to the line with the warning.
It is possible to select which of the coding standards to check by selecting them in the Coding Standards tab of the JavaStyle options pane.
There are some other options available, but currently there is no fancy graphical configuration dialog for them available.
However, you can look at the file
$HOME/.jedit/javastyle/.Refactory/pretty.settingsfor a full set of configurable options.
(PS: The location of $HOME varies on the Windows platforms:)
Operating system Location of $HOME Windows 95,98,ME C:\WINDOWS Windows NT C:\WINNT\Profiles\<yourname> Windows 2000,XP C:\Documents And Settings
Click here for a commented version of the property file.
Note, that you can edit this file with jEdit. Saved changes will be used immediately.
There are other files in the .Refactory directory -- please leave them untouched!
C-style comments at end of lines
If you put a C-style comment /* */ at the end of a line, to keept them on that line you have to select the "Treat C-Style comments as single-line" and unselect "Put end-line comments on a new line". E.g., if you have this:String s = "hello"; /* this is a starred comment */it will get formatted like this:
System.out.println(s); // next lineString s = "hello";if either "Treat C-Style comments as single-line" is unticked or "Put end-line comments on a new line" is ticked.
/* this is a starred comment */
System.out.println(s); // next line
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!
--- That said, the number of known bugs in JavaStyle and the underlying JRefactory library is surprisingly small. They are listed below.
If you have found a bug in JavaStyle, please mail it to me. If you are technically skilled in issues of programming, and you get the vague impression that the bug is not in the plugin layer, but in the underlying PrettyPrinter library, please inform Mike Atkinson, the maintainer of the PrettyPrinter.
Remember, I provide only the plugin part of the PrettyPrinter, while Chris is responsible for the pretty printing itself.Mike Atkinson (JavaStyle@ladyshot.demon.co.uk)
Note: If you get the error
java.lang.NoSuchMethodError:
org.acm.seguin.util.FileSettings.getSettingsRoot()Ljava/io/File;
then you have an old version of jrefactory.jar installed. Remove it
from your jars directory.
Try updating to a newwer version of the plugin
jEdit - Plugin Bugs | |
746217 | JavaStyle reformatting exception |
588614 | JavaStyle: localized date |
JRefactory - Bugs | |
693738 | Non-ascii characters get replaced by '?' |
813879 | Rename field does not detect downcast |
693738 | Header re-inserted when imports re-ordered |
689870 | ExtractMethod produces wrong code on anonymous inner classes |
678029 | Pretty printer hotkey clashes |
658953 | No refactoring menu in NetBeans 3.4.1RC1 |
595863 | No handler for Access Denied expections |
547257 | Javadoc wordwrap doesn't handle tags |
547172 | Backup file loses date + time |
517495 | Don't cast (smart) block comment option |
516386 | Can't parse if throws not in description |
499682 | Move Class is eating code |
498619 | JBuilder designer missing events |
485536 | Window loosing it's content |
485535 | Exception on Refactoring |
484816 | Package & Library Problem |
465607 | JBuilder: UML blocks content pane |
456861 | Problem with extending inner classes |
AStyle 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 many 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.
This product includes software developed by the JRefactory ( http://www.sourceforge.org/projects/jrefactory).