CSC 103 Laboratory Activity
Checkstyle Lab
Part 1
- Login to your account on a CSL workstation.
- If you haven't setup your account to run BlueJ, then make
a launcher for BlueJ.
- Download the
Checkstyle extension for BlueJ
that contains the custom checks for our class coding standard.
The extension is installed by placing the extension jar file into an extensions directory. /home/yourusername/.bluej/extensions
(In the file manager, View -> Show hidden files will reveal "dot" folders.
You should create the extensions directory if it doesn't exist.
)
Restart BlueJ.
-
From the Tools menu, select Preferences. The preferences dialog
appears.
Click on the Extensions tab. Locate the Checkstyle panel. For
Configuration
File enter the location of the class configuration XML file: /home/graderjd/bin/bluej/lib/extensions/easystyleBlueJ.xml
- From the "Project" menu select "New Project". (You may name it
"Lab1".)
- Click the "New Class" button to create a new Java class named
GridGuess.
- Right-click on the newly created GridGuess class in
the
diagram and select "Open Editor". Observe that BlueJ creates
the skeleton code for a class. You may select all (Ctrl-A) and
delete
the skeleton code.
- Copy and paste the source code for GridGuess.java
into the editor window.
- Click the "Compile" button. In the status window you
should
see the message "Class compiled - no syntax errors."
- In BlueJ's main window, right click on the GridGuess class in
the
diagram and select "Run Applet". In the dialog which appears,
select
the radio button
for "Run Applet in appletviewer" and click "OK".
- The applet should execute, displaying a 5 by 5 grid. You may
may play the game, clicking on cells trying to discover the
green one.
Quit the Applet when you are finished.
Part 2
- From the main window (not the editor) open the Tools menu
and select Checkstyle. In the window that appears, click on
"GridGuess"
in the left-hand panel. A list of checkstyle violations appears
along with the corresponding line number.
(You might want to turn on line numbering in BlueJ: Tools -> Preferences -> Editor -> Display line numbers.)
- Your assignment is to learn about the class coding standard by
correcting the errors that Checkstyle has identified. Leave both
the Checkstyle window and the editor window open. When you make
a change in the editor and click "Compile" the Checkstyle window
will automatically refresh itself. The following strategy
is suggested:
- Look for errors whose message is immediately obvious. For
example,
on line 15, "'{' should
be on a
new line" needs no further explanation.
- From the Edit menu, select Auto-Layout to fix indentation errors.
- Where comments are required, provide a meaningful comment.
- Consult the
coding standard checklist
or coding
standard
definition
if you aren't sure how to fix the error or what
the correct standard requires.
- Read an explanation for a few of the most
common errors.
- If the error message doesn't make sense to you, consult the
Checkstyle documentation
for an explanation of the error message.
- As a last resort, consult the instructor.
- Review the
coding standard checklist and study the GridGuess code to
see if
there are any violations of our class
standard that Checkstyle does not catch. (Checkstyle is
not
perfect). Correct any violations you discover.
Part 3
- Make sure the program compiles and executes correctly.
- Add a javadoc @author tag in the class header with your
name.
- Print out your finished source code (as described in the syllabus) and bring it to
the next class meeting.
- Both partners should configure their CSL account with the BlueJ launcher.
- Buy a blank lab notebook and prepare it for use according to
the lab notebook guidelines.
For the first lab entry in your notebook, make any notes about
Checkstyle and the coding standard that you will want to refer
to during future programming assignments.
Notes
-
BlueJ FAQ
- Also, on Unix, Checkstyle is installed in the grader account and can be run from the command line:
~graderjd/bin/stylechecker myprogram.java
- Look under the Edit menu for Indent more/Indent less, Comment/Uncomment, and Auto-layout.
- Here are some directions
for installing BlueJ and Checkstyle on your personal
workstation.
- There is a draft version of a layout formatter extension for Bluej
which will auto-format the layout of your source code.
View website.
It's a student project; if you find errors please inform the instructor.
Summary
Since maintenance accounts for
80% of most organizations software
budget, writing readable code can produce significant cost savings
for
a software team.
You may find that correcting Checkstyle violations is somewhat
tedious. To avoid this, familiarize yourself with the class coding standard
and
write your code in the correct style at the outset. That will
save a lot of time because you won't have to go back and correct it
when you are finished.
Instructor