User Manual

User Manual for FixStyle

April 28, 2008

CPE 309-01

1. How To Use FixStyle

1.1 Style Options

Description

FixStyle comes with different style options for the user to choose from. FixStyle defaults to the Sun Java Standard (see Fixstyle Profiles) if the user leaves the options unchanged. To see the list of options, click here.

1.2 Set FixStyle Preferences

There are two ways to set the preferences. The first way is to select the Tools Menu and click "FixStyle Preferences". The other way is to select the Tools Menu and click Preferences... Then click the Extensions tab in the BlueJ Preference window. Finally click the Edit Style Conventions button in the Fixstyle box.
From there each of the options offered by FixStyle can be found in the subdirectories.

1.3 Run FixStyle

Right click on the file needing to be formated. Select "FixStyle" and Click "Format".
Note: This will only work on compile code. This option will be disabled if the file is not compiled.

1.4 Undo in FixStyle

Description

After using FixStyle to format a file, it is possible to undo the formatting that was just done if the changes were not what the user wanted.

How To Use This Feature

Right click on the file that was just formatted. Select "FixStyle" and Click "Undo".
Note: This will only work on a file immediately after formatting it. If two files are formatted, only the latest file to be formatted will have the ability to undo its formatting.

1.5 FixStyle Profiles

Description

The user may save FixStyle configurations as profiles and load for quick use to change back any modified settings. Users may create a new profile, save over an existing profile, load a saved profile, or delete an unwanted profile. FixStyle also comes loaded with profiles for popular coding standards. If the user makes changes to the FixStyle options without saving, FixStyle will automatically prompts user to save or discard unsaved profile changes. FixStyle provides the following standard styles (see Curly Braces):

  1. Sun Java Standard
  2. Ansi C Standard
  3. GNU Coding Standard

How To Use Access This Feature

Access the FixtStyle preference pane by using the procedure in section 1.2.

Initial Default Profile

Without changing any options in the FixStyle options menu the extension will be set to standard Sun Java Standard profile. If the desire is to change to a pre-defined convention, go to the General label in the Jalopy settings box, select the desired default from the combo box in pre-defined conventions, click use, and then ok at the bottom of the panel.

Create A New Profile

Go to the General label in the Jalopy settings box, type in a new name and description for this convention, click export, click browse on the box that pops up, and finally name and place the profile in a folder of your choosing. Click ok on that menu to save the profile.

Creating a New Profile from An Existing Profile

Click the General label in the Jalopy settings box. Click import, click browse in the box that pops up, locate the profile, click ok in that box to load that profile. Then type in a new name and description for this convention. Then click export, click browse on the box that pops up, and finally name and place the profile in a folder of your choosing. Click ok on that menu to save the profile.

Editing An Existing Profile

Click the General label in the Jalopy settings box. Click import, click browse in the box that pops up, locate the profile, click ok in that box to load that profile. Change the desired settings and click ok on the Jalopy settings panel.

Load A Profile

Click the General label in the Jalopy settings box. Click import, click browse in the box that pops up, locate the profile, click ok in that box to load that profile. Then click ok on the Jalopy setting panel.


2.0 Options

2.1 Array Type Style

Description

This feature checks a source code file to see if array declaration follows either the Java standard or the C style standard. If an array is declared using a style other than the one specified by the user, FixStyle changes it to the desired format.

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Misc". (4.) In the corresponding panel that appears on the right side of the window click or unclick the "Array Brackets after identifier" check box. (5.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example: Changing To Java Style

Before:

int a[];Ok.

After:

int[] a;

2.2 Inline Conditionals

Description

This feature checks a source code file for any inline conditionals. If FixStyle finds any it replaces them with an if-else statement, maintaining the same logic and making the code easier to read.

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Misc". (4.) In the corresponding panel that appears on the right side of the window click "Remove Inline Conditionals" check box. (5.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example

Before:

    String b= (a==null || a.length<1) ? null : a.substring(1));

After:

    String b;
    if (a==null || a.length<1)
    {
	b=null;
    }
    else
    {
	b=a.substring(1);
    }

2.3 Curly Braces

Description

This feature checks a source code file to see if the curly brace positions meet the style for the situation set by the user. The user may specify where to place the left curly brace with one of the following:

  1. C style

Left curly under statement declaration and right curly on its own line.

  1. GNU style

Left curly under statement declaration and indented 2 extra spaces and right curly on its own line.

  1. Sun Java style

Left curly on same line as statement declaration and right curly on its own line (except with do-while loops).

  1. Custom style

With each of these options, the user may specify two special cases:

  1. Treat class/method blocks different
  2. Treat class/method blocks different if wrapped

Also under Custom style, the user may choose between the following:

  1. Newline before left brace
  2. Newline after right brace

Along with choosing whether or not to use the new lines, Custom style allows the user to state how much white space to use in these situations:

  1. Before left brace
  2. Before right brace
  3. After right brace

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Braces". (4.) In the corresponding panel that appears on the right side of the window, click the check box next to the desired style. (5.) Under wrapping, choose options you wish !Fixstyle to implement. (6.) Set the white space as needed. (7.) Click Ok. (8.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example: C style

Before:

public class Aclass {
    public void method(int x, int y){
    }
}

After:

public class Aclass
{
    public void method(int x, int y)
    {
    }
}

Example: GNU style

Before:

public class Aclass {
    public void method(int x, int y){
    }
}

After:

public class Aclass
  {
    public void method(int x, int y)
      {
      }
  }

Example: Sun Java style

Before:

public class Aclass
{
    public void method(int x, int y)
    {
    }
}

After:

public class Aclass {
    public void method(int x, int y) {
    }
}

Example: Newline before left brace

Before:

if(a==b){ a= b+3; }
else{ b++; }				

After:

if(a==b)
{ a= b+3; }
else
{ b++; }					

Example: Newline after right brace

Before:

if(a==b){ a= b+3; }else{ b++; }				

After:

if(a==b){ a= b+3; }
else{ b++; }

Example: Treat class/method blocks different without newline before left brace

Before:

public class Aclass {
    public void method(int a,
     int b){
        if(a==b){ a= b+3; }
        else{ b++; }
    }
}

After:

public class Aclass
{
    public void method(int a,
     int b)
    {
        if(a==b){ a= b+3; }
        else{ b++; }
    }
}	

Example: Treat class/method blocks different if wrapped without newline before left brace

Before:

public class Aclass {
    public void method(int a,
     int b){
        if(a==b){ a= b+3; }
        else{ b++; }
    }
}	

After:

public class Aclass {
    public void method(int a,
     int b)
    {
        if(a==b){ a= b+3; }
        else{ b++; }
    }
}	

2.4 Line Length

Description

This feature checks a source code file to see if any lines exceed a set number of characters. By default FixStyle limits the max number of characters on a line at 80. If a line exceeds the set max, then FixStyle breaks up the line at a logically sound place.

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Wrapping". (4.) In the corresponding panel that appears on the right side of the window select the "General" tab. (5.) Click the "Wrap Line" check box and select a number from the "Line length:" drop down menu, or double click on the text box and enter your own number. (6.) In the Policy box check all options, except "Wrap before operators". (7.) Click OK. (8.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example: Default Of 80 Characters

Before:

    public static int veryLongMethodName (int veryLongParameterA, int veryLongParameterB, int veryLongParameterC )
    {

After:

    public static int veryLongMethodName (int veryLongParameterA, 
                                          int veryLongParameterB, 
                                          int veryLongParameterC )
    {

2.5 Method Parameter Pad

Description

This feature checks a source code file to see if any method's parameter spacing differs from the style selected. FixStyle provides three different styles:

  1. No Space
  2. One Space (default)
  3. New Line.

How To Use This Feature

To enable this feature:

No Space: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "White Space". (4.) In the corresponding panel that appears on the right side of the window unclick "Method declaration parentheses" check box and unclick "Method call parentheses" checkbox. (5.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.
One Space: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "White Space". (4.) In the corresponding panel that appears on the right side of the window unclick "Method declaration parentheses" check box and unclick "Method call parentheses" checkbox. (5.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.
New Line: (1.) Select the Tools Menu and click "FixStylePreferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Wrapping". (4.) In the corresponding panel that appears on the right side of the window select the "Always" tab. (5.) In the section Wrap always click "Method left parentheses" checkbox. (6.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example: No Space

Before:

int method   (int a, int b)
{
}

After:

int method(int a, int b)
{
}

Example: One Space

Before:

int method    (int a, int b)
{
}

After:

int method (int a, int b)
{
}

Example: New Line

Before:

int method    (int a, int b)
{
}

After:

int method
    (int a, int b)
{
}

2.6 Single Line Braces

Description

This feature checks a source code file for optional braces in control statements. If they are not used, FixStyle adds braces according to the style specified under "Left Curly Brace" and "Right Curly Brace".

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Braces". (4.) In the corresponding panel that appears on the right side of the window select the Misc Tab. (5.) Under the Insert braces section click the "if...else" check box, the "for" check box, the "while" check box, and the "do...while" check box. (6.) Click OK. (7.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example

Before:

if(a<b)
    a=b*2;
else
    b--;

After:

if(a<b)
{
    a=b*2;
}
else 
{
    b--;
}

2.7 Paren Pad

Description

This feature checks if the whitespace around parenthesis matches the selected style. FixStyle provides two styles:

  1. Spaces. FixStyle places one space after the left parenthesis and one space before the right
  2. No spaces. FixStyle sets the default the padding to no spaces

If the whitespace does not match the selected style, it changes so that it does.

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Braces". (4.) In the corresponding panel that appears on the right side of the window select the "General" tab. (5.) In the Styles box click "Custom style" check box. (6.) In the "White Space" box select '1' from the "Before left brace:" drop down menu and select the number of spaces from the "Before right brace:" drop down menu.(7.) Click OK. (8.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example: Spaces

Before:

int method(   int a,   int b)

After:

int method( int a, int b )

Example: No Spaces

Before:

int method(    int a,   int b)

After:

int method(int a, int b)

2.8 Tab To Spaces

Description

This feature checks for groups of space characters and any tab characters in the code. The user can convert groups of spaces into tab characters or tab characters into spaces. FixStyle sets the default number of spaces at 4.

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Indentation". (4.) In the corresponding panel that appears on the right side of the window select the "Misc" tab. (5.) Unclick "Use tabs to indent" check box. (5.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example: Tab To 3 Spaces

Before:

	int a;

After:

   int a;

Example: 3 Spaces To Tab

Before:

   int a;

After:

	int a;

2.9 Whitespace Around

Description

This feature checks a source code file to see if the desired amount of whitespace surrounds the tokens. If FixStyle cannot find the proper amount of whitespace around the tokens, then it adds the necessary spaces.

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "White Space". (4.) In the corresponding panel that appears on the right side of the window click the check boxes labeled: "Assignment operators", "Bitwise Operators", "Logical operators", "Mathematical operators", "Relational operators", "Shift Operators" and "Type cast parentheses". (5.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example

Before:

a=b+c;

After:

a = b + c;

2.10 Newline At End Of File

Description

This feature checks to see if the file ends with a newline character. If the file does not end with a newline character, this feature adds a newline character to the end of the file.

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Misc". (4.) In the corresponding panel that appears on the right side of the window click "Insert trailing newline" check box. (5.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example

Before:

    ...
    myObject.cleanUp();
    return;
}[EOF]

After:

    ...
    myObject.cleanUp();
    return;
}
[EOF]

2.11 Enforce Javadocs

Description

This feature checks for javadocs above every method or class. If FixStyle does not find the proper javadoc tags, this feature adds the missing javadoc tags.

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Javadoc". (4.) In the corresponding panel that appears on the right side of the window select the "General" tab. (5.) In the "Generation" box click all of the check boxes for each of the Classes/Interface, Constructors, Methods, and Variables. (6.) Click the "Include inner classes" check box. (7.) Click OK. (8.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example

Before:

}

public int getNum ()
{

After:

}

/**
 * Write a description of method getNum here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public int getNum ()
{

2.12 Set Indent Width

Description

This feature indents all logical blocks of code a specified number of characters (spaces).

How To Use This Feature

To enable this feature: (1.) Select the Tools Menu and click "FixStyle Preferences". (2.) In the Preferences window expand "Printer" from the list in the left hand window. (3.) In the subdirectory of Printer choose "Indentation". (4.) In the corresponding panel that appears on the right side of the window click "Use tabs to indent" check box. (5.) Click OK. (6.) FixStyle activates this feature and reconfigures the next time the user runs it.

Example: Indent 6 Spaces

Before:

public int getNum ()
{
   if ( 5 > 4 )
      return 5;
   else
      return 4;
}

After:

public int getNum ()
{
      if ( 5 > 4 )
            return 5;
      else
            return 4;
}

3.0 Other Jalopy Features Available

Each option is found under the "Printer" menu in the Preferences window.

Braces
Insert empty statement: An empty statement is added to empty braces to improve source code clarity
Cuddle braces: Empty braces will be put right next to the control statement.

Wrapping
Always: Choose to wrap the line after each option always:

Before extends keyword
After extends types
Before implements keyword
After implements keyword
Before throws keyword
After throws keyword
Method declaration parameters
Method call chains
Method call parameters
Method call parameters if nested Ternary expression ?
Ternary expression :
Labels

Always when exceed: wrap when the line will exceed maximum length

After extends types
After implements types
After throws types
After parameters/expressions



Blank Lines
Blank lines after:

Package statement
Last import statement
Classes
Interfaces
Methods
Left curly brace

Blank lines before and after:

Blocks
Declarations

Blank lines before:

Case blocks
Control statements
Single-line comments
Multi-line comments
Javadoc comments
Right curly brace

Keep up to ā€˜n’ blank lines: Choose a number upt to

Comments
Removal of Single-line comments
Removal of Multi-line comments
Removal of Javadoc comments

Imports
Sort import statements: Sorts all imports lexicographically
Expand on-demand imports: Removes wild card imports (ones with '.*') and replaces with single-type imports used in the source code
Collapse single-type imports: Tries to collapse single-type imports to on-demand or wild card imports

Header
Insert Header: Inserts the given header template
Delete Header: Choose a header to delete with the given key
Blank Lines: Insert number of blank lines to separate header

Footer
Insert Footer: Inserts the given footer template
Delete Footer: Choose a footer to delete with the given key
Blank Lines: Insert number of blank lines to separate footer

Sorting
Declarations: can set declarations to be ordered as well as setting the order
Modifiers: can set modifiers to be ordered as well as setting the order

Misc
Insert expression parenthesis: Breaks up expressions using parenthesis by operation precedence
Insert serial version UID: a unique serial UID is given to the classes
Insert logging conditional: Checks if debugger is enabled before writing to it
Force formatting: If the history switch is enabled, will allow for all copies to be changed
Use history file: History saved in history.dat instead of the header
Use history comments: A small comment line is added every time the file is formatted
Set number of backups and location: Set the number of backups (up to 30) default is 0 and where to save them
Set number of threads: Set number of threads, should be equal to number of processors