Modify the rule to meet the missing case

This commit is contained in:
HoshiNoMei
2022-04-24 23:36:46 +08:00
parent 24f4b2ecb6
commit 996f81ccce

View File

@ -1289,7 +1289,8 @@ public void foo() throws Exception {
<description> <description>
<![CDATA[ <![CDATA[
Look for ternary operators with the form `condition ? literalBoolean : foo` Look for ternary operators with the form `condition ? literalBoolean : foo`
or `condition ? foo : literalBoolean`. or `condition ? foo : literalBoolean`
or `condition ? literalBoolean1 : literalBoolean2`.
These expressions can be simplified respectively to These expressions can be simplified respectively to
`condition || foo` when the literalBoolean is true `condition || foo` when the literalBoolean is true
@ -1297,6 +1298,11 @@ These expressions can be simplified respectively to
or or
`!condition || foo` when the literalBoolean is true `!condition || foo` when the literalBoolean is true
`condition && foo` when the literalBoolean is false `condition && foo` when the literalBoolean is false
or
`true` when the literalBoolean are both true
`false` when the literalBoolean are both false
`condition` when the literalBoolean1 is true and the literalBoolean2 is false
`!condition` when the literalBoolean1 is false and the literalBoolean2 is true
]]> ]]>
</description> </description>
<priority>3</priority> <priority>3</priority>
@ -1308,6 +1314,8 @@ or
//ConditionalExpression[not(PrimaryExpression/*/Literal) and (Expression/PrimaryExpression/*/Literal/BooleanLiteral)] //ConditionalExpression[not(PrimaryExpression/*/Literal) and (Expression/PrimaryExpression/*/Literal/BooleanLiteral)]
| |
//ConditionalExpression[not(Expression/PrimaryExpression/*/Literal) and (PrimaryExpression/*/Literal/BooleanLiteral)] //ConditionalExpression[not(Expression/PrimaryExpression/*/Literal) and (PrimaryExpression/*/Literal/BooleanLiteral)]
|
//ConditionalExpression[(PrimaryExpression/*/Literal/BooleanLiteral) and (Expression/PrimaryExpression/*/Literal/BooleanLiteral)]
]]> ]]>
</value> </value>
</property> </property>
@ -1330,6 +1338,10 @@ public class Foo {
public void test4() { public void test4() {
final boolean otherValue = condition ? something() : false; // can be as simple as condition && something(); final boolean otherValue = condition ? something() : false; // can be as simple as condition && something();
} }
public boolean test5() {
return condition ? true : false; // can be as simple as return condition;
}
} }
]]> ]]>
</example> </example>