OpenjdkMethodParameterAlignment

Since Checkstyle 14.4.0

Description

Checks that the parameters of a wrapped method declaration follow one of the two forms allowed by the OpenJDK style guidelines.

The OpenJDK Java Style Guidelines allow a wrapped method declaration to be formatted either by listing the parameters vertically, one per line, or by breaking the line and indenting the continuation by eight extra spaces. This check validates a wrapped declaration against those two forms:

  • when every parameter that starts a new line is indented eight spaces past the declaration, the declaration uses the eight extra spaces form and any number of parameters may share a line;
  • otherwise the parameters are expected to be listed vertically, that is, every parameter that starts a new line is aligned with the first parameter and each line holds exactly one parameter.

A declaration whose parameter list fits on a single line is ignored. A wrapped declaration in which no parameter starts a new line, because it is wrapped inside a parameter type rather than between two parameters, is expected to be listed vertically, so a line that holds more than one parameter is reported.

Examples

To configure the check:


<module name="Checker">
  <module name="TreeWalker">
    <module name="OpenjdkMethodParameterAlignment"/>
  </module>
</module>

Example:


class Example1 {

  // violation below 'Only one parameter is allowed per line in a vertical list.'
  Example1(int a,
           int b, int c) {}

  void oneParameterPerLine(int a,
                           int b,
                           int c) {}

  // violation below 'Only one parameter is allowed per line in a vertical list.'
  void twoOnLastLine(int a,
                     int b, int c) {}

  // violation below 'Only one parameter is allowed per line in a vertical list.'
  void twoOnFirstLine(int a, int b,
                      int c) {}

  // violation 2 lines below """Parameter should be aligned vertically or
  //  indented 8 spaces relative to the method declaration."""
  void notAligned(int a,
      int b) {}

  void wrappedByEightSpaces(int a, int b,
          int c) {}
}

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Fully Qualified Name

com.puppycrawl.tools.checkstyle.checks.whitespace.OpenjdkMethodParameterAlignmentCheck

Use this fully qualified class name in configuration when an exact class reference is required.

Parent Module

TreeWalker