BlueJ LOC Counter
Goal
Enhance the BlueJ IDE so it provides a metric for lines of code
for each class in the current package.
Counting Rules
The number of lines is computed as the number of terminal
semicolons and right braces.
(Semicolons within a for statement are not counted)
For example, the following code has a line count of 6.
void Snoopy()
{
int x = 0, y = 1;
x = x + 1; y = y + 3;
if (x == 10)
{
y = 0;
}
}
There are four semicolons and two right braces, resulting in 6
lines.
Note that the program does not actually parse the Java code, it does
a simple text search to find semicolons and braces. Consequently the
file does not have to be valid Java code in order to produce a
count.
Implementation
You will be writing a BlueJ "extension". Here is the reference
"Writing
Extensions For BlueJ".
You must design your solution so the logic for line counting
is in a separate class from the extension entry point and can be
tested with JUnit. Here is the method specification:
public class LocCounter
{
public static int getCount(Reader reader)
}
Design Quality Priorities
Maintainability, Correctness, Usability, Efficiency
Extra Credit
Enhance the LOC counter so it ignores comments (all varieties)
and String literals.
Grading
This is an individual assignment, no collaboration is
permitted. You may not even mention the name of the
assignment to another student.
50% Maintainability. Uses encapsulation appropriately. Avoids common
algorithm design flaws. Conforms to class coding standard. You
will demo your finished product during lab on a Unix lab
workstation. (Note: The installed BlueJ is version 3.1).
50% Usability and Correctness. The program provides a simple,
convenient, robust solution to the problem.
Submission
- Upload a zip file containing LocCounter.java and LocCounterTest.java (your unit tests) to Web-CAT for Project 1.
- Have the getName() method of your extension return
"LOC counter - username" where username is your
Cal Poly username.
- Place your name in the @author tag in the class javadoc
header.
- Rename the Jar file containing your extension to LOCextension.jar.
- Create a zip file containing the Java source files, the Jar
file, and a README.TXT file with usage instructions
and known defects or limitations. Name the zip Project1.zip.
- Submit the zip file to PolyLearn for Project 1.
FAQ
Q: May we assume that the "for" statement will be on the same line as the loop conditions? For instance:
for (int i = 0; i < 10; i++)
{
j = i;
}
Versus:
for
(int i = 0;
i < 10;
i++)
{
j =
1;
}
A: No.
Solution to "Manifest does not contain Main-Class attribute".
In the BlueJ guide to writing extensions, in the part where the
author says, "The simplest way to do this is to create a file
(called, say,manifest.txt) containing the single line: Main-Class:
SimpleExtension"
Importantly, this line must end with a newline.
Otherwise, the last line will not be parsed correctly resulting in
(for the SimpleExtension example) "Manifest does not contain
Main-Class attribute."