/**
 * CS139 - Programming Fundamentals
 * Department of Computer Science
 * James Madison University
 * @version Spring 2016
 */

CS139 Checkstyle Instructions

Background


checkstyle.sourceforge.net

Checkstyle is a tool that can be used to determine if your source code follows a set of formatting rules. It also checks for common programming mistakes, such as empty statements and shadow variables.

Checkstyle can be executed from the command-line or through jGRASP. Either way, you will need to download the Checkstyle executable:

As well as a configuration file that describes the CS139 formatting requirements:

If you apply Checkstyle to your source code regularly, you will likely internalize good style habits over time. However, you should note that Checkstyle only evaluates low-level formatting. It cannot evaluate the quality of comments, meaning of variable names, etc.

Running Checkstyle In the Terminal

Copy the Checkstyle .jar file and the .xml configuration file into the same directory as your Java code.

Open a terminal and use the following command to run Checkstyle:

java -jar checkstyle-*-all.jar -c cs139.xml *.java

Note the * characters are wildcards that match whatever version of Checkstyle you have and whatever java source files are present. The output indicates the file and line number of each problem. This example refers to a method beginning on line 93, column 5 of Hello.java:

Hello.java:93:5: Missing a Javadoc comment

Running Checkstyle Through jGRASP

After you have downloaded the Checkstyle .jar file and the .xml configuration file, open jGRASP and select Tools -> Checkstyle -> Configure. In the "Checkstyle Tool Settings" dialog box set "Checkstyle Home" to be the folder containing the .jar file, and "Checks File" to be the cs139.xml file, then click "OK".

If all went well, you should see two new buttons on the jGRASP toolbar: and . Clicking the first button will run Checkstyle on the current file in the editor window. Clicking the second button will run Checkstyle on all of the Java files in the current directory.