KT-17379: Fix J2K removal of parentheses in multiline expressions

When there is multiline polyadic expression with some operators
J2K should keep surrounding parentheses, otherwise
operators will be dangling due resolved to prefix variant

 #KT-17379 fixed
This commit is contained in:
Dimach
2017-07-30 04:49:55 +03:00
committed by Simon Ogorodnik
parent 0920b2574c
commit f0035a7be0
11 changed files with 147 additions and 53 deletions
+40 -19
View File
@@ -1,26 +1,47 @@
object A {
@JvmStatic
fun main(args: Array<String>) {
val ANDAND = true
val ANDAND = (true
&& true
&& true
val OROR = true
&& true)
val OROR = (true
|| true
|| true
val PLUS = 1
+2
+3
val MINUS = 1
-2
-3
val ASTERISK = 1 * 2 * 3
val DIV = 1 / 2 / 3
val PERC = 1 % 2 % 3
val GTGT = 1 shl 2 shl 3
val LTLT = 1 shr 2 shr 3
val XOR = 1 xor 2 xor 3
val AND = 1 and 2 and 3
val OR = 1 % 2 % 3
val GTGTGT = 1 ushr 2 ushr 3
|| true)
val PLUS = (1
+ 2
+ 3)
val MINUS = (1
- 2
- 3)
val ASTERISK = (1
* 2
* 3)
val DIV = (1
/ 2
/ 3)
val PERC = (1
% 2
% 3)
val GTGT = (1
shl 2
shl 3)
val LTLT = (1
shr 2
shr 3)
val XOR = (1
xor 2
xor 3)
val AND = (1
and 2
and 3)
val OR = (1
% 2
% 3)
val GTGTGT = (1
ushr 2
ushr 3)
}
}
+19
View File
@@ -0,0 +1,19 @@
//file
package demo;
class Test {
void test() {
int a = 0;
int b = 1;
int c = 2;
int d = 4;
int y = a // polyadic expression case
+ b // x2
+ c // x3
+ d; // x4
int z = a // binary expression case
+ b; // x4
int j = b +
c;
}
}
+20
View File
@@ -0,0 +1,20 @@
package demo
internal class Test {
fun test() {
val a = 0
val b = 1
val c = 2
val d = 4
val y = (a // polyadic expression case
+ b // x2
+ c // x3
+ d) // x4
val z = (a // binary expression case
+ b) // x4
val j = b + c
}
}
@@ -1,7 +1,6 @@
//file
import kotlinApi.*;
//TODO: Formatter works incorrectly
class A {
int foo(KotlinClass c) {
return c.getNullableProperty().length()
@@ -1,15 +1,14 @@
import kotlinApi.*
//TODO: Formatter works incorrectly
internal class A {
fun foo(c: KotlinClass): Int {
return c.nullableProperty!!.length
+c.property.length
+KotlinClass.nullableStaticVar!!
+KotlinClass.staticVar
+KotlinClass.nullableStaticFun(1)!!
+KotlinClass.staticFun(1)
+nullableGlobalFunction("")!!.length
+globalFunction("").length
return (c.nullableProperty!!.length
+ c.property.length
+ KotlinClass.nullableStaticVar!!
+ KotlinClass.staticVar
+ KotlinClass.nullableStaticFun(1)!!
+ KotlinClass.staticFun(1)
+ nullableGlobalFunction("")!!.length
+ globalFunction("").length)
}
}
@@ -8,4 +8,4 @@ internal class C {
KotlinObject.property1 +
KotlinObject.property2
}
}
}
+3 -3
View File
@@ -4,7 +4,7 @@ object A {
"text3"
val TEXT2 = "text1\n"
+ "text2\n"
+ "text3"
val TEXT2 = ("text1\n"
+ "text2\n"
+ "text3")
}