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==99
boolean result = x && y ? true : false
- can be replaced by boolean result = x && y
def 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 >= 1
boolean result = x < 99 ? Boolean.TRUE : Boolean.FALSE
- can be replaced by boolean result = x < 99
def result = !x ? true : false
- can be replaced by def result = !x
def result = x ? '123' : '123'
- can be replaced by def result = '123'
def result = x ? null : null
- can be replaced by def result = null
def result = x ? 23 : 23
- can be replaced by def result = 23
def result = x ? MAX_VALUE : MAX_VALUE
- can be replaced by def result = MAX_VALUE
Type | Name and description |
---|---|
Class |
astVisitorClass |
String |
name |
int |
priority |