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| Fields inherited from class | Fields |
|---|---|
class AbstractAstVisitorRule |
CLOSURE_TEXT, DEFAULT_CONST_NAME, DEFAULT_FIELD_NAME, DEFAULT_TEST_CLASS_NAMES, DEFAULT_TEST_FILES, DEFAULT_VAR_NAME |
| Type | Name and description |
|---|---|
java.lang.Class |
astVisitorClass |
java.lang.String |
name |
int |
priority |