Class MultipleVariableDeclarationsCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class MultipleVariableDeclarationsCheck
    extends AbstractCheck

    Checks that each variable declaration is in its own statement and on its own line.

    Rationale: the Java code conventions chapter 6.1 recommends that declarations should be one per line/statement.

    To configure the check:

     <module name="MultipleVariableDeclarations"/>
     

    Example:

     public class Test {
       public void myTest() {
         int mid;
         int high;
         // ...
    
         int lower, higher; // violation
         // ...
    
         int value,
             index; // violation
         // ...
    
         int place = mid, number = high;  // violation
       }
     }
     

    Parent is com.puppycrawl.tools.checkstyle.TreeWalker

    Violation Message Keys:

    • multiple.variable.declarations
    • multiple.variable.declarations.comma
    Since:
    3.4