Regrettably, some code in the current system does not follow any consistent coding style. This is an unfortunate residuum of the system's evolution. To alleviate this problem, we present this style guide for new Java™ code; it's just a small tweak of Sun®'s style guide. We also use checkstyle to support a gradually expanding subset of these conventions. The current set of enforced checkstyle rules are defined by $RVM_ROOT/build/checkstyle/rvm-checks.xml and are verified as part of the pre-commit test run. To check for violations of the coding style without running the tests, use buildit or run "ant checkstyle" from the command line.
Every file needs to have the license header.
A Java example of the notices follows.
Coding style description
The Jikes™ RVM coding style guidelines are defined with reference to the Sun® Microsystems "Code Conventions for the Java™ Programming Language", with a few exceptions listed below. Most of the style guide is intuitive; however, please read through the document (or at least look at its sample code).
We have adopted four modifications to the Sun code conventions:
- Two-space indenting The Sun coding convention suggests 4 space indenting; however with 80-column lines and four-space indenting, there is very little room left for code. Thus, we recommend using 2 space indenting. There are to be no tabs in the source files or trailing white space on any line.
- 132 column lines in exceptional cases The Sun coding convention is that lines be no longer than 80 columns. Several Jikes RVM contributors have found this constraining. Therefore, we allow 132 column lines for exceptional cases, such as to avoid bad line breaks.
if (VM.VerifyAssertions)As a special case, the condition
if (VM.VerifyAssertions)is usually immediately followed by the call to
VM._assert(), with a single space substituting for the normal newline-and-indentation. There's an example elsewhere in this document.
- Capitalized fields Under the Sun coding conventions, and as specified in The Java Language Specification, Second Edition, the names of fields begin with a lowercase letter. (The only exception they give is for some
final staticconstants, which have names ALL_IN_CAPITAL_LETTERS, with underscores separating them.) That convention reserves IdentifiersBeginningWithACapitalLetterFollowedByMixedCase for the names of classes and interfaces. However, most of the
finalfields in the
Configurationclass and the
Propertiesinterface also are in that format. Since the
VMclass inherits fields from both
Configuration, that's how we get
All files should contain descriptive comments in Javadoc™ form so that documentation can be generated automatically. Of course, additional non-Javadoc source code comments should appear as appropriate.
- All classes and methods should have a block comment describing them
- All methods contain a short description of their arguments (using
@param), the return value (using
@return) and the exceptions they may throw (using
- Each class should include
@linkreferences as appropriate.