Writing Sample:
Solution Spotlight Column from SeS Solutions Magazine in 2003

Teamstudio’s Teamstudio Analyzer for Java

“The 9000 series is the most reliable computer ever made. No 9000 computer has ever made a mistake or distorted information. We are all, by any practical definition of the words, foolproof and incapable of error.”
  --- HAL 9000 in 2001: A Space Odyssey

HAL 9000s might think it was incapable of error, but unless any of us are in serious denial, we are all certainly very capable of making Java programming errors. Fortunately, we have the option of using automated companions to analyze your code and note probable errors. Teamstudio Analyzer for Java is one such companion.

Teamstudio Analyzer for Java is a Windows-based utility that integrates into either IBM’s Eclipse or Borland’s JBuilder. Analyzer can also be called in as an Ant task in an Ant build procedure.

After Analyzer is installed in Windows, it appears under Preferences in Eclipse, and in the Tools menu in JBuilder. It is here that you configure Analyzer, which is a straightforward process of selecting which of the 142 rules you want to use to analyze your source code. The Analyzer designers used three sources to generate the rules, "The Java Language Specification (2nd ed.)", "The Elements of Java Style" by Scott Ambler, and "Effective Java". The rules are grouped under four headings, “Code Documentation (javadoc)”, “Source Code Formatting”, “Strict”, and “General”.

The code documentation rules detect missing or inconsistent documentation comments that are written to the specifications needed for the Javadoc tool. The rules detect, for example, a missing @param tag in the documentation, or alternatively, flag a @param tag as erroneous if the parameter doesn’t exist.

The source code formatting rules detect when code, comment, and Javadoc lines exceed a specified number of characters in length. It will also detect if tab characters are used in the source.

So far, there’s only one rule available under the “Strict” heading, and that is the one detecting a messing “else” after an “else if” statement.

The bulk of the rules fit under the “General” heading. Many of these rules are designed to enforce coding standards that help to simplify program maintenance at a later time. For example, there are rules that detect missing enclosed braces in “for” and “while” loops consisting of a single statement. Although Java doesn’t require braces for a single statement, it can lead to problems if a maintenance programmer later expands the loop to multiple statements and forgets to add the required braces.

Other rules include those that flag unused private fields and methods, local variables, and method parameters. There are also rules that detect incorrect string and floating point comparisons, non-terminated cases in switch statements, and local variables hiding visible fields.

Running Analyzer from within Eclipse or JBuilder is a straightforward process. In Eclipse, you simply right-click your project in the Packages/Navigator view and select Teamstudio Analyzer in the popup menu. Analyzer messages will appear in the Tasks pane. In the Editing pane, Analyzer will display yellow information icons to the left of each message and beside each questionable line or area of code. When you click on a message in the Tasks pane, Eclipse will display the appropriate line of source code in the Editing pane. A sample screen is shown below.

Additional information is available for each Analyzer rule by selecting the Task pane message and pressing F1.

You can disable rules globally by unchecking them in the Analyzer preferences window. If you need to disable rules just for a specific file, you can place a special comment before the type declaration in the file. When Analyzer sees the comment, it will automatically disable the rule specified in the comment.

You can see for yourself if Analyzer works to help make your code “foolproof and incapable of error,” as a 30-day trail is available for download. The product sells for $595, which includes one year of maintenance, $700 getting the product and a second year of maintenance.

Teamstudio’s Teamstudio Analyzer for Java
Teamstudio, Inc.
(800) 632-9787

IDE Integration: Eclipse 2.0, JBuilder 5, 6 and 7
Full JDK 1.3 and 1.4 support
Operates on Windows 98, 2000, XP, NT 4.0, and ME

$595/developer (includes 1 year maintenance); $700 (2 year maintenance)