CSSE 230
Colorize Programming Assignment

Overview

In this project you will write a Java application that reads a Java source code file and outputs an HTML file that will display a “Colorized” version of the code when viewed in a web browser.

This is a pair programming assignment. You are to work with the partner you identified, or that I assigned to you. You must use pair programming techniques. That is, you cannot simply divide the work and program independently. Developing the ability to create software in pairs is vital to your success, both in this course and professionally.

I suggest that you quickly read this entire document once to get an overview, then read it again slowly a couple of times to get the details.

Learning Objectives

Requirements

From using Eclipse, you have seen that displaying different features of a program in different colors can make the program easier to read.

You are to write a Java application that reads a Java source code file and outputs an HTML file that (when viewed in a web browser)

For example:

// Opening comment.  Note that a "string" is ignored here because it is inside a comment.
class /* Bad name */  Stupid { int x;
    String t = "A string with a /* in it";
    String p = "A string with a \" in it";
    boolean b = t.compareTo(p) < 0;
   
    public static void main(String [] args) {
        System.out.println("" + t + " " + p);
        System.out.println("Can you think of other interesting cases that your program should handle?");
    }
    /* Notice that comments /* do not "nest" in Java // */  
}

It is also important that you write your program in such a way that no possible input can cause the program to get into an infinite loop. The Major Hint below may help you to avoid that pitfall. Our unit tests are configured to stop any run that takes longer the 5,000 ms. You may increase the time limit by editing the @Test(timeout=5000) lines, but hopefully you won't need to do that.

Getting Started

For this pair programming project, you’ll use the same SVN repository that you used for PascalChristmesTree

Once you’ve connected to the repository, checkout the Colorize project. Remember to follow the cardinal rules of multi-person SVN projects:

Because you will be pair programming, only one person should be typing at a time. So, SVN conflicts shouldn’t be a problem on this project. But do seek help if you get stuck.

Your Program’s Interface

Each unit test will call the Colorize.colorize method with a String argument that is the prefix of a filename (no extension at the end).  For example,  If the argument is "XYZ", your program must read the file XYZ.java and create the file XYZ.html. For example,

Colorize.colorize("MyClass"); 

should read the input file MyClass.java, and produce the output file MyClass.html.

Eclipse includes a simple web browser. After you run the program, if you right-click on your project in Eclipse and choose Refresh, any generated HTML files should be listed. You can double click on the files to view them in the web browser. You can also right-click an HTML file and choose Open With... to view them in a text editor; this will let you check the actual text that you are outputting.

We have also provided unit tests. The unit tests simply run your program on each of the sample inputs provided in the Eclipse project.   Getting the "Green bar" for this program does not mean correct output, it only means that your program did not get into an infinite loop.  We will check the output files by hand.

It is vital that your program not use any graphical user interface objects, such as those in java.awt or javax.swing. We will compile and run everyone's programs with a script, and your program will break that script if you use classes like JFrame, JOptionPane, JWindow, etc.

Detailed Suggestions

Learning HTML

You do not have to become an HTML expert in order to do this problem. The Stupid.html file has examples of the small number of HTML tags that you need to know to complete this assignment. To see the code, either open the file in an editor (like WordPad) or open it in a web browser and choose View Page Source (or whatever it is called in your browser) fPay special attention to the HTML code that generates the “less than” sign.

General Approach

I suggest developing and enhancing this program incrementally, doing the most basic and easiest parts first. First, plan your program framework (mainly this means implementing a basic FSM) and get colorized comments working. Then add new FSM states for colorizing strings. Finally, add the mechanism for recognizing and colorizing keywords. Most of the correctness credit will be for colorizing comments and strings. Including colorized keywords is more difficult; can you see why?

Hint on Recognizing Keywords

All Java keywords contain only lowercase letters. When you see a lowercase letter, begin saving the letters in a String variable. When you get to the first non-letter, check to see if your saved string matches one of the keywords. If so, output the “word” in blue, otherwise output it in black. The declaration and code in this keywords.txt file may be helpful here. Of course, you should not colorize any keywords that are inside a comment or a string constant.

Major Hint

I strongly suggest that the main part of your code be a loop of the form "read a character, process that character". If you try to use nested loops or try to read and process multiple characters in a single time through the loop, it can get very complicated and involve many special cases.

The following code illustrates the process:

 

Other Information Sources

In class, we will introduce Finite State Machines, begin drawing a FSM diagram for the colorizer, and discuss possible approaches to FSM implementation. Here are some more resources that you may find helpful:

Turnin

Test your code by running the included JUnit tests and carefully examining the output files. Submit your code by committing it to your Subversion repository. Be sure that all partners fully understand the code before committing it.

 

After you submit your code, complete the survey to evaluate of you and your partner on ANGEL.

Grading Rubric

The rubric is here.