Author:  Mike Atkinson Software
Release Notes
Download
Contributors

Previous Page

Software::IDE::jEdit - JavaStyle

Next Page


Supported versions:

  • jEdit 4.1 - use JRefactory 2.6.40

    This version is rather old but works well for pretty printing

  • jEdit 4.2 - use JavaStyle-jedit 2.8 final

    The new version is all-singing-all-dancing including not only an improved pretty printer, but also refactoring, metrics, cut&paste detection, bug finding, coding standards support and an AST viewer. JavaStyle has been tested on jEdit 4.2pre5 with J2SDK1.4.2_01 on Windows XP.

Running JavaStyle in jEdit.

Download JavaStyle from plugin central by using the Plugin Manager.

Development versions may be obtained from http://sourceforge.net/projects/jrefactory/. They should be unzipped into the jEdit jars directory (in either the jEdit settings directory or the jEdit application directory). Current versions of JavaStyle use the following library jars:

  • findbugs.jar
  • findbugsGUI.jar
  • coreplugin.jar
  • saxpath-1.0-fcs.jar
  • jaxen-core-1.0-fcs.jar
  • dom4j-full.jar
  • bcel.jar

care should be taken to ensure that only one version of these jars is present. A future version of JavaStyle will package all these jars in a single jar and compress them to take up less space.

After downloading JavaStyle appears as a plugin which may be obtained from the Plugins menu.

Plugins
  • JavaStyle
    • Reformat buffer reformats the current buffer using the appropriate pretty printer settings
    • JRefactory... opens the dockable window to allow refactoring, coding standards checking, cut&paste detection, AST viewer and bug finding.

    • Coding Standards
      • Check current buffer If the current buffer (i.e. the one that contains the cursor) contains Java source code then check it. The warnings get shown on the ErrorList plugin and on the margin of the buffer as well as being underlined in the text. If the JavaStyle dockable window is open coding standards breaches are also shown in its Coding Standards tab.
      • Check all open buffers For all open buffers that contain Java source code check them. The warnings get shown on the ErrorList plugin and on the margin of the visible buffers as well as being underlined in the text. If the JavaStyle dockable window is open coding standards breaches are also shown in its Coding Standards tab.
      • Check files in current directory Check for coding standards in the current directory and all sub-directories. The warnings get shown on the ErrorList plugin and on the margin of the visible buffers as well as being underlined in the text. If the JavaStyle dockable window is open coding standards breaches are also shown in its Coding Standards tab.
      • Check directory recursively Check for coding standards in the current directory and all sub-directories. The warnings get shown on the ErrorList plugin and on the margin of the visible buffers as well as being underlined in the text. If the JavaStyle dockable window is open coding standards breaches are also shown in its Coding Standards tab.
      • Clear ErrorList Clear the warnings/errors from the ErrorList plugin.
    • Detect Duplicate Code
      • In current buffer
      • Look for duplicated code in the current buffer. Sections of duplicated code may be seen in the JavaStyle dockable window Cut&Paste detector tab.
      • In Directory
      • Look for duplicated code in the selected directory. Sections of duplicated code may be seen in the JavaStyle dockable window Cut&Paste detector tab.
      • In Directory Recursively
      • Look for duplicated code in the selected directory and all its sub-directories. Sections of duplicated code may be seen in the JavaStyle dockable window Cut&Paste detector tab.

    • Options... Open the options selection dialog box (see below)

Selecting the Options

JavaStyle has many options for pretty printing and others for controlling the coding standards checking. These may be accessed either from the menu Plugins->JavaStyle->Options... or from Plugin->Plugin Options... the second option only allows acces to the default options, whereas the first option allows the options for particular projects to be set seperately. The JavaStyle plugin finds out what projects are available from the ProjectViewer plugin, if its not loaded then you just get the default options.

The option system is quite complex, it will allow almost any style of pretty printing you could desire, don't be afraid to experiment, copy a complex Java source file to a temporary location and see the results on that. You will almost certainly need to change the Author in the JavaDoc Tags tab (its currently set to me!).

Perhaps the two most important options are on the General tab Reformat when buffer is saved when ticked causes JavaStyle to reformat the buffer whenever it is saved (i.e just before it is saved) and this could change how your code looks considerably (sorting the methods for example). The other Perform coding standards check when buffer is saved is very useful on fast machines as it notifies you of problems immediately, it is however quite slow and so most appropriate for fast machines (2GHz Pentium 4 equivalent or faster)

Each Project may have its own values of any of the options, they are stored as changes to the default options. Tick the left hand box on a project option pane and then select the desired state of the option for that project.

If you need to look at the pretty.settings options file look in <user.home>/.jedit/javastyle/.JRefactory for the default settings, settings for the projects are contained in subdirectories from here.


Note: the current version of JavaStyle is not very efficient at creating the Options dialog box. It may take several seconds to load if there are lots of  projects.

Building the JavaStyle plugin yourself

There are three ways of building JavaStyle for jEdit.

Its Easiest, to download the JavaStyle-jedit-2.8.x-source.zip and unzip directly into the jEdit jar directory. You should have a directory structure something like this:

jEdit 4.2/
jars/
ErrorList.jar
ProjectViewer.jar
JRefactory/
ant.build/
classes/
lib/
docs/
jedit files/
rulesets/
settings/
src/
test/
build.xml

Open the build.xml with AntFarm and execute the jEdit.JavaStyle.jar target. The resulting jar file is copied into the ant.build/lib/ directory, use the Plugin Manager to unload the JavaStyle plugin (uncheck it in the manage tab) copy the JavaStyle.jar from ant.build/lib/ to jEdit4.2/jars/ and reload it using the Plugin Manager.

Alternatively download the whole JRefactory-2.8.x-full.zip distribution, unzip it into a clean directory and again execute the jEdit.JavaStyle.jar target. You will need to copy the jedit.jar, ErrorList.jar and ProjectViewer.jar from the jEdit application into the JRefactory/jar/ directory first.

Alternatively use anonymous CVS to download the current version of JReafactory and build it. It is found on sourceforge.

About jEdit

The open source JEdit is an editor first and an IDE second. There are a large number of plugins available for it covering most aspects of development. Version 4.2 has much faster start-up performance and lazy loading of plugins. JavaStyle fully supports jEdit 4.2 features.

The tools

Pretty Printer/Beautifier is a tool that allows you to clean up the indenting and formatting of your java source code.

This tool has a powerful feature of being able to insert the appropriate javadoc comments so that the javadoc program does not generate error messages for missing fields. To simplify writing javadoc comments, some methods have javadoc comments automatically generated based on the name of the method.

JRefactory is a tool that allows you to perform the following refactorings:

  • Move class between packages (repackage)
  • Rename class
  • Add abstract parent class
  • Add child class
  • Remove empty class
  • Extract interface
  • Push up field
  • Push down field
  • Rename Field
  • Push up method
  • Push up abstract method
  • Push down method
  • Move method
  • Extract method
  • Rename Parameter

It updates the java source files as appropriate.

This tool comes as a command line option with GUI or without, and as a plugin for the JEdit (still under development), JBuilder, NetBeans, and Elixir IDEs.

For JBuilder and Elixir you can switch from the UML diagram to the source code.

Printing provides the ability to print UML diagrams.

BugFinding uses the findbugs tool to find many common sources of bugs in code.

UML Diagrams come as part of the Refactoring support, they can be resized are useful for navigating round lots of code.

Cut & Paste detection looks for similar sections of source code throughout a set of files.

AST Viewer shows the result of the Java parser as an Abstract Syntax Tree. XPath queries may be performed on the tree.

Metrics gathers metrics about your java source code.

Stub Generator creates a file that allows the refactory tool to display Java JDK library classes (or other applications where you have access to the source code, but you don't intend to change the source code). This facility is used for the refactoring tool to show classes from 3rd party vendors in the refactoring GUI. (This has been tested on JDK 1.4.2_01, but should work with other Java 2 JDKs)

Previous Page

Last Modified: October 7, 2003

Previous Page