|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | PROPERTY | CONSTR | METHOD | DETAIL: FIELD | PROPERTY | CONSTR | METHOD | |||||||
java.lang.Objectorg.codenarc.rule.AbstractAstVisitorRule
groovy.org.codenarc.rule.unnecessary.UnnecessaryTernaryExpressionRule
class UnnecessaryTernaryExpressionRule extends AbstractAstVisitorRule
Rule that checks for ternary expressions where the conditional expression always evaluates to
a boolean and the true and false expressions are merely returning true and
false constants. These cases can be replaced by a simple boolean expression.
Examples include:
boolean result = x==99 ? true : false - can be replaced by boolean result = x==99boolean result = x && y ? true : false - can be replaced by boolean result = x && ydef result = x||y ? false : true - can be replaced by def result = !(x||y)boolean result = x >= 1 ? true: false - can be replaced by boolean result = x >= 1boolean result = x < 99 ? Boolean.TRUE : Boolean.FALSE - can be replaced by boolean result = x < 99def result = !x ? true : false - can be replaced by def result = !xdef result = x ? '123' : '123' - can be replaced by def result = '123'def result = x ? null : null - can be replaced by def result = nulldef result = x ? 23 : 23 - can be replaced by def result = 23def result = x ? MAX_VALUE : MAX_VALUE - can be replaced by def result = MAX_VALUE| Property Summary | |
|---|---|
Class |
astVisitorClass
|
String |
name
|
int |
priority
|
| Property Detail |
|---|
Class astVisitorClass
String name
int priority
Groovy Documentation