Groovy Documentation

groovy.org.codenarc.rule.formatting
[Groovy] Class BracesForIfElseRule

java.lang.Object
  org.codenarc.rule.AbstractAstVisitorRule
      groovy.org.codenarc.rule.formatting.BracesForIfElseRule

class BracesForIfElseRule
extends AbstractAstVisitorRule

Checks the location of the opening brace ({) for if statements and optionally closing and opening braces for else statements. By default, requires them on the same line, but the sameLine property can be set to false to override this. To enable else checking, set the validateElse property to true. For more fine grained control, use boolean properties elseOnSameLineAsClosingBrace and elseOnSameLineAsOpeningBrace Example:

 if (x) {     //A

 } else if (y) { //B

 } else {    //C

 }
 
A - checked and defaults to no errors since the brace is on the same line
B - checked if option validateElse is set to true. Validation result controlled by boolean options elseOnSameLineAsClosingBrace and elseOnSameLineAsOpeningBrace C - same as B
Authors:
Hamlet D'Arcy
Geli Crick
Matias Bjarland


Property Summary
Class astVisitorClass

Boolean elseOnSameLineAsClosingBrace

Boolean elseOnSameLineAsOpeningBrace

String name

int priority

boolean sameLine

boolean validateElse

 

Property Detail

astVisitorClass

Class astVisitorClass


elseOnSameLineAsClosingBrace

Boolean elseOnSameLineAsClosingBrace


elseOnSameLineAsOpeningBrace

Boolean elseOnSameLineAsOpeningBrace


name

String name


priority

int priority


sameLine

boolean sameLine


validateElse

boolean validateElse


 

Groovy Documentation