Author:  Mike Atkinson Software
Release Notes
Download
Contributors

Previous Page

Software::IDE::Netbeans - JavaStyle

Next Page


Supported versions:

  • Netbeans 3.5 - use JavaStyle-netbeans 2.8 final
  • This version includes not only an improved pretty printer, but also refactoring, metrics, cut&paste detection, bug finding, coding standards support and an AST viewer. Unfortunately it is not yet well integrated and so should be considered Alpha level software JavaStyle has been tested on Netbeans 3.5.1 with J2SDK1.4.2_01 on Windows XP.

Running JavaStyle in Netbeans.

Development versions may be obtained from http://sourceforge.net/projects/jrefactory/. After downloading JavaStyle appears as a directory which may be obtainedfrom the Tools menu.

Tools
  • JavaStyle
    • Coding Standards
      • Check current buffer
        If the current buffer (i.e. the one that contains the cursor) contains Java source code then check it. 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. 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. 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. If the JavaStyle dockable window is open coding standards breaches are also shown in its Coding Standards tab.
    • 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 all open buffers
        Look for duplicated code in all buffer buffers containing Java code. Sections of duplicated code may be seen in the JavaStyle dockable window Cut&Paste detector tab.
      • In Directorybr/> 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)
    • 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.

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 Tools->JavaStyle->Options... This allows the options for particular projects to be set seperately (not yet implemented at present 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!).

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

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 forthat project.

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-netbeans-2.8.x-source.zip and unzip directly into a clean directory. You should have a directory structure something like this:

Editorial: provide instructions

Alternatively download the whole JRefactory-2.8.x-full.zip distribution, unzip it into a clean directory.

Editorial: provide instructions

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

About Netbeans

Editorial: provide description

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, Elixir, and JBuilder 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