Skip to main content

Java Highlighter

Posted by evanx on May 8, 2007 at 2:10 AM PDT

In the Hyper Text Processor prequel, we processed half-baked HTML for this "Foundation Beans" series of articles.

Now let's meet the QHyperJavaProcessor, which highlights Java code in HTML pre blocks.

Java Highlighter: A part of the "Hyper Beans" part of a trilogy in 42 parts"

We split up the Java text into an array of string tokens, using the following delimiter tokens, which include Java keywords to be highlighted.

public class QHyperJavaProcessor {
    static final String[] keywords = new String[] {
        "package", "import",
        "static", "final", "abstract", "synchronized", "transient",
        "default",
        "class", "interface", "@interface", "enum",
        "extends", "implements",
        "public", "private", "protected",
        "true", "false", "null",
        "instanceof",
        "void", "boolean", "int", "char", "long",
        "throws", "throw", "try", "catch", "finally",
        "new", "this", "super",
        "if", "else", "for", "while",
        "continue", "break",
        "return"
    };
    ...
}       

Resources

https://code.google.com/p/vellum/ - where i will collate these articles and their code.