Skip to content

Commit 266a087

Browse files
authored
Merge pull request github#11284 from tamasvajk/kotlin-complex-bool-expr
Kotlin: Exclude .kt files from `java/complex-boolean-expression`
2 parents 91b7798 + ac85d2e commit 266a087

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

java/ql/src/Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ class ComparisonOrEquality extends BinaryExpr {
9292

9393
from Expr e, string pattern, string rewrite
9494
where
95-
e.(BoolCompare).simplify(pattern, rewrite)
96-
or
97-
conditionalWithBool(e, pattern, rewrite)
98-
or
99-
e.(LogNotExpr).getExpr().(ComparisonOrEquality).negate(pattern, rewrite)
100-
or
101-
e.(LogNotExpr).getExpr() instanceof LogNotExpr and
102-
pattern = "!!A" and
103-
rewrite = "A"
95+
e.getFile().isJavaSourceFile() and
96+
(
97+
e.(BoolCompare).simplify(pattern, rewrite)
98+
or
99+
conditionalWithBool(e, pattern, rewrite)
100+
or
101+
e.(LogNotExpr).getExpr().(ComparisonOrEquality).negate(pattern, rewrite)
102+
or
103+
e.(LogNotExpr).getExpr() instanceof LogNotExpr and
104+
pattern = "!!A" and
105+
rewrite = "A"
106+
)
104107
select e, "Expressions of the form \"" + pattern + "\" can be simplified to \"" + rewrite + "\"."

java/ql/test/kotlin/query-tests/SimplifyBoolExpr/SimplifyBoolExpr.expected

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fun main() {
2+
f(null)
3+
f(true)
4+
f(false)
5+
}
6+
7+
fun f(x: Boolean?) {
8+
if(x == true) {
9+
println("Yes")
10+
} else {
11+
println("No")
12+
}
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql

0 commit comments

Comments
 (0)