JPP: The Java Pre-Processor
The Java Pre-Processor, or JPP for short, is a parsing preprocessor for
the Java programming language. Unlike its namesake (the C/C++ Pre-Processor,
cpp), JPP provides functionality above and beyond simple textual substitution.
JPP's capabilities include code beautification, code standard conformance
checking, class and interface specification and testing, and documentation
The Java Pre-Processor, referred to as JPP henceforth, is a parsing preprocessor
for the Java 1.X programming language. This document will describe the
design, development, and use of JPP.
JPP is primarily used as either a front-end for a Java compiler like
javac, espresso, or guavac, or as a verification and validation tool as
part of a configuration management system. We will describe both possibilities
here as well as provide a number of examples of innovative alternative
The default JPP configuration corresponds to the Infospheres Java Coding
Standard (this document). Any questions as to the details of code standards,
layout, beautification, and verification are addressed in that document.
This document only focuses on the tool JPP.
All aspects of JPP are user configurable. Configuration is accomplished
through the use of Java properties and command-line switches.
Briefly, JPP provides the following functionality:
Code Beautification. JPP can process any legal Java code and reorganize
it in an ordered, aesthetic manner. The rules used in the reformatting
of code are user configurable. JPP is used as a code beautifier to clean
up downloaded or otherwise adopted code before performing a code review.
It is also used in preparation for gaining and understanding of a codebase
before modifying and maintaining it. Finally, JPP can be used to process
code from multiple developers/teams regularly to enforce local coding standards.
Code Evaluation. JPP can also be used to take an existing piece of code
and ``grade'' it. Such a code evaluation comes in several forms:
Code Standard Conformance Checking. JPP is configured to a specific code
standard. Code standards give rules on how code is syntactically arranged,
field naming policies, feature access rules, etc. JPP can evaluate how
well a piece of code conforms to its current code standard. Such an evaluation
comes in the form of a short or long report which can be automatically
mailed to the appropriate parties and/or logged for review.
Code Complexity Analysis. JPP knows several standard code complexity algorithms.
JPP can evaluate Java classes, interfaces, and even whole packages and
provide complexity measures. These metrics can help guide a designer and
developer toward more readable, understandable, and maintainable code.
Metrics are also provided as short or long reports.
Documentation Analysis. JPP can evaluate the thoroughness of code documentation.
JPP knows what a ``real'' comment is and performs information theoretical
complexity measures (per-feature and per-entity entropy) of comments to
determine their completeness and usefulness. JPP will comment on your comments!
Object-Oriented Design Principles. JPP understands a core set of object-oriented
design principles: the Laws of Demeter, class/interface/inheritance dependency
graph analysis, JavaBean patterns, and component specification to name
a few. JPP can evaluate Java code and provide suggestions as to how to
improve design based upon these principles.
Class and Interface Specification. JPP's specification constructs are inspired
by Meyer's Design by Contract. The primary constructs used to specify a
contract for a component are method preconditions and postconditions, and
class invariants. JPP can enforce and/or encourage the specification of
contracts on the methods of classes and interfaces, and can test for the
validity of such clauses in subtyping relationships.
Class and Interface Testing. In addition to the aforementioned contract
specifications on methods, JPP supports the specification of loop invariants
and variants. All five of these constructs (the three specification clauses
and the two loop clauses) can be transformed by JPP into actual embedded
test harness code, inserted into a class's methods at the appropriate points.
The insertion of the test code at compile time, and the enabling and disabling
of test code at run-time, is completely under the control of the developer.
Documentation Generation. JPP can also transform Java code into HTML, XML,
or LaTeX for direct code documentation and reference. The resulting document
is properly formatted for pretty-printing, has the appropriate embedded
links for feature cross-referencing, and external language-specific links
can be embedded in the code with special directives to the preprocessor.
Return to Home
Last modified: Sun Jun 10 03:18:48 PDT 2001