JetBrains/kotlin — pull request #392 by wutalman (2014-02-28 05:28:29+00:00)
Title: Intention to simplify boolean expressions with constants

Intention to simplify boolean expressions with constants in them,
issue: KT-4569 (http://youtrack.jetbrains.com/issue/KT-4569)

I used some helper functions, I didn't know if the convention is to nest them inside the functions they're helping or not but when I looked at some other code it seemed that we just have them as private functions in the class so that's what I did

Parentheses handling:
if the binary expression has parentheses in it, and they don't contain any constants, they are kept as to not change what the user wanted to write
example: false || x || (y && z) -> x || (y && z)
if the parentheses have constants in them and so the inner expression is changed, I will remove the parentheses only if there's only one element left: (that is again to keep the user's original intent)
example #1: x || (y && true) -> x || y
example #2: x || (y && z && true) -> x || (y && z)
if at the end of the evaluation the entire expression has parentheses around it, they will be removed:
example: false || (x && y) -> x && y