LeftCurly

Since Checkstyle 3.0

Description

Checks for the placement of left curly braces ('{') for code blocks.

Properties

Examples

To configure the check:

<module name="LeftCurly"/>
        
class Test
{ // Violation - '{' should be on the previous line
  private interface TestInterface
  { // Violation - '{' should be on the previous line
  }

  private
  class
  MyClass { // OK
  }

  enum Colors {RED, // OK
    BLUE,
    GREEN;
  }
}
        

To configure the check to apply the nl policy to type blocks:

<module name="LeftCurly">
  <property name="option" value="nl"/>
  <property name="tokens" value="CLASS_DEF,INTERFACE_DEF"/>
</module>
        
class Test
{ // OK
  private interface TestInterface
  { // OK
  }

  private
  class
  MyClass { // Violation - '{' should be on a new line
  }

  enum Colors {RED, // OK
    BLUE,
    GREEN;
  }
}
        

To configure the check to apply the nlow policy to type blocks:

<module name="LeftCurly">
  <property name="option" value="nlow"/>
  <property name="tokens" value="CLASS_DEF,INTERFACE_DEF"/>
</module>
        
class Test
{ // Violation - '{' should be on the previous line
  private interface TestInterface { // OK
  }

  private
  class
  MyClass { // Violation - '{' should be on a new line
  }

  enum Colors {RED, // OK
    BLUE,
    GREEN;
  }
}
        

An example of how to configure the check to validate enum definitions:

<module name="LeftCurly">
  <property name="ignoreEnums" value="false"/>
</module>
        
class Test
{ // Violation - '{' should be on the previous line
  private interface TestInterface
  { // Violation - '{' should be on the previous line
  }

  private
  class
  MyClass { // OK
  }

  enum Colors {RED, // Violation - '{' should have line break after
  BLUE,
  GREEN;
  }
}
        

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.

Package

com.puppycrawl.tools.checkstyle.checks.blocks

Parent Module

TreeWalker