KT-1074 Need to avoid unnecessary parenthesis for converted code

This commit is contained in:
Sergey Ignatov
2012-01-19 12:19:51 +04:00
parent 47530f1c62
commit e13b438a69
70 changed files with 113 additions and 87 deletions
@@ -30,6 +30,6 @@ public class BinaryExpression extends Expression {
@Override
public String toKotlin() {
List<String> expressionsWithConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(Arrays.asList(myLeft, myRight)), myConversions);
return "(" + AstUtil.join(expressionsWithConversions, SPACE + myOp + SPACE) + ")";
return AstUtil.join(expressionsWithConversions, SPACE + myOp + SPACE);
}
}
@@ -24,6 +24,6 @@ public class PolyadicExpression extends Expression {
@Override
public String toKotlin() {
List<String> expressionsWithConversions = AstUtil.applyConversions(AstUtil.nodesToKotlin(myExpressions), myConversions);
return "(" + AstUtil.join(expressionsWithConversions, SPACE + myToken + SPACE) + ")";
return AstUtil.join(expressionsWithConversions, SPACE + myToken + SPACE);
}
}
@@ -17,6 +17,6 @@ public class PostfixOperator extends Expression {
@NotNull
@Override
public String toKotlin() {
return "(" + myExpression.toKotlin() + myOp + ")";
return myExpression.toKotlin() + myOp;
}
}
@@ -17,6 +17,6 @@ public class PrefixOperator extends Expression {
@NotNull
@Override
public String toKotlin() {
return "(" + myOp + myExpression.toKotlin() + ")";
return myOp + myExpression.toKotlin();
}
}
@@ -1 +1 @@
x = (x and 2)
x = x and 2
@@ -1 +1 @@
x = (x or 2)
x = x or 2
@@ -1 +1 @@
x = (x shl 2)
x = x shl 2
@@ -1 +1 @@
x = (x shr 2)
x = x shr 2
@@ -1 +1 @@
x = (x ushr 2)
x = x ushr 2
@@ -1 +1 @@
x = (x xor 2)
x = x xor 2
@@ -1 +1 @@
(x and 2)
x and 2
@@ -1 +1 @@
(true && false)
true && false
@@ -1 +1 @@
(true || false)
true || false
@@ -1 +1 @@
(1 / 2)
1 / 2
@@ -1 +1 @@
(1 > 2)
1 > 2
@@ -1 +1 @@
(1 >= 2)
1 >= 2
@@ -1 +1 @@
(1 < 2)
1 < 2
@@ -1 +1 @@
(1 <= 2)
1 <= 2
@@ -1 +1 @@
(1 - 2)
1 - 2
@@ -1 +1 @@
(1 * 2)
1 * 2
@@ -1 +1 @@
(x or 2)
x or 2
@@ -1 +1 @@
(1 + 2)
1 + 2
@@ -1 +1 @@
(1 % 2)
1 % 2
@@ -1 +1 @@
(x shl 2)
x shl 2
@@ -1 +1 @@
(x shr 2)
x shr 2
@@ -1 +1 @@
(x xor 2)
x xor 2
@@ -1,6 +1,6 @@
do
{
var i : Int = 1
i = (i + 1)
i = i + 1
}
while ((a > b))
while (a > b)
@@ -1,3 +1,3 @@
do
i = (i + 1)
i = i + 1
while (true)
@@ -5,7 +5,7 @@ RED
YELLOW
BLUE
override public fun run() : Unit {
System.out?.println(("name()=" + name() + ", toString()=" + toString()))
System.out?.println("name()=" + name() + ", toString()=" + toString())
}
public fun name() : String { return "" }
public fun order() : Int { return 0 }
+1 -1
View File
@@ -4,6 +4,6 @@ open class Test() {
open fun test() : Unit {
var i : Int? = 10
var j : Int? = 10
System.out?.println((i + j))
System.out?.println(i + j)
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
var array : IntArray? = IntArray(10)
for (i in 0..(10 - 1)) {
for (i in 0..10 - 1) {
array[i] = i
}
+1 -1
View File
@@ -1,4 +1,4 @@
var array : IntArray? = IntArray(10)
for (i in 0..(10 - 1)) {
for (i in 0..10 - 1) {
array[i] = i
}
@@ -1,14 +1,14 @@
{
var i : Int = 0
while ((i < 0))
while (i < 0)
{
{
var i : Int = 1
(i++)
i++
}
{
(j++)
(i++)
j++
i++
}
}
}
@@ -1,12 +1,12 @@
{
var i : Int = 0
while ((i < 0))
while (i < 0)
{
{
}
{
(j++)
(i++)
j++
i++
}
}
}
@@ -1 +1 @@
for (i in 0..(0 - 1)) (t++)
for (i in 0..0 - 1) t++
+3 -3
View File
@@ -1,11 +1,11 @@
{
var i : Int = 0
while ((i < 0))
while (i < 0)
{
return i
{
(j++)
(i++)
j++
i++
}
}
}
@@ -1,5 +1,5 @@
for (n : Node? in list)
{
var i : Int = 1
(i++)
i++
}
@@ -1,2 +1,2 @@
for (n : Node? in list)
(i++)
i++
@@ -2,6 +2,6 @@ package demo
open class Test() {
open fun test(var i : Int) : Int {
i = 10
return (i + 20)
return i + 20
}
}
@@ -1,4 +1,4 @@
if ((1 > 0))
if (1 > 0)
{
}
else
@@ -1,4 +1,4 @@
if ((1 > 0))
if (1 > 0)
{
var n : Int = 1
return n
@@ -1,4 +1,4 @@
if ((1 > 0))
if (1 > 0)
{
var n : Int = 1
return n
+13
View File
@@ -0,0 +1,13 @@
package demo;
class Test {
static void subListRangeCheck(int fromIndex, int toIndex, int size) {
if (fromIndex < 0)
throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
if (toIndex > size)
throw new IndexOutOfBoundsException("toIndex = " + toIndex);
if (fromIndex > toIndex)
throw new IllegalArgumentException("fromIndex(" + fromIndex
+ ") > toIndex(" + toIndex + ")");
}
}
+13
View File
@@ -0,0 +1,13 @@
package demo
open class Test() {
class object {
open fun subListRangeCheck(fromIndex : Int, toIndex : Int, size : Int) : Unit {
if (fromIndex < 0)
throw IndexOutOfBoundsException("fromIndex = " + fromIndex)
if (toIndex > size)
throw IndexOutOfBoundsException("toIndex = " + toIndex)
if (fromIndex > toIndex)
throw IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")")
}
}
}
+1 -1
View File
@@ -3,7 +3,7 @@ import java.io.File
public open class Test() {
class object {
open public fun isDir(parent : File?) : Boolean {
if (((parent == null) || (!parent?.exists())))
if (parent == null || !parent?.exists())
{
return false
}
+9 -9
View File
@@ -1,14 +1,14 @@
open class Test() {
open fun test() : Unit {
var res : Boolean = true
res = (res and false)
res = (res or false)
res = (res xor false)
System.out?.println((true and false))
System.out?.println((true or false))
System.out?.println((true xor false))
System.out?.println((!true))
System.out?.println((true && false))
System.out?.println((true || false))
res = res and false
res = res or false
res = res xor false
System.out?.println(true and false)
System.out?.println(true or false)
System.out?.println(true xor false)
System.out?.println(!true)
System.out?.println(true && false)
System.out?.println(true || false)
}
}
+1 -1
View File
@@ -11,6 +11,6 @@ this.code = code
class object {
public var ENGLISH : Language? = Language("en")
public var SWEDISH : Language? = Language("sv")
private val serialVersionUID : Long = (-2442762969929206780)
private val serialVersionUID : Long = -2442762969929206780
}
}
+2 -2
View File
@@ -4,9 +4,9 @@ open fun test() : String? {
var s1 : String? = ""
var s2 : String? = ""
var s3 : String? = ""
if (((s1?.isEmpty()).sure() && (s2?.isEmpty()).sure()))
if ((s1?.isEmpty()).sure() && (s2?.isEmpty()).sure())
return "OK"
if (((s1?.isEmpty()).sure() && (s2?.isEmpty()).sure() && (s3?.isEmpty()).sure()))
if ((s1?.isEmpty()).sure() && (s2?.isEmpty()).sure() && (s3?.isEmpty()).sure())
return "OOOK"
return ""
}
+1 -1
View File
@@ -15,7 +15,7 @@ return 2
return 3
}
else -> {
return (-1)
return -1
}
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
package demo
open class Test() {
open fun test() : Unit {
for (i in 0..(10 - 1)) {
for (i in 0..10 - 1) {
System.out?.println(i)
}
}
+1 -1
View File
@@ -2,6 +2,6 @@ package demo
open class C(a : Int) {
var abc : Int = 0
{
abc = (a * 2)
abc = a * 2
}
}
@@ -2,9 +2,9 @@
var n : Int = substring.length()
var j : Int = i
var k : Int = 0
while (((n--) != 0))
while (n-- != 0)
{
if ((searchMe.charAt((j++)) != substring.charAt((k++))))
if (searchMe.charAt(j++) != substring.charAt(k++))
{
continue@test
}
@@ -1 +1 @@
((1 + 2))
(1 + 2)
@@ -1 +1 @@
((str.toString() + "abc"))
(str.toString() + "abc")
@@ -1 +1 @@
(1 / 2 / 3)
1 / 2 / 3
@@ -1 +1 @@
(1 - 2 - 3)
1 - 2 - 3
@@ -1 +1 @@
(1 * 2 * 3)
1 * 2 * 3
@@ -1 +1 @@
(1 + 2 + 3)
1 + 2 + 3
@@ -1 +1 @@
(1 % 2 % 3)
1 % 2 % 3
@@ -1 +1 @@
(1 ushr 2 ushr 3)
1 ushr 2 ushr 3
@@ -1 +1 @@
(i--)
i--
@@ -1 +1 @@
(i++)
i++
@@ -1 +1 @@
(--i)
--i
@@ -1,2 +1,2 @@
var i : Boolean = true
var j : Boolean = (!i)
var j : Boolean = !i
@@ -1 +1 @@
(++i)
++i
@@ -1,2 +1,2 @@
var i : Int = (10).inv()
var j : Int = (((i * 100))).inv()
var j : Int = ((i * 100)).inv()
@@ -2,6 +2,6 @@ trait INode {
class object {
val IN : String? = "in"
val AT : String? = "@"
val COMMA_WITH_SPACE : String? = (COMMA + SPACE)
val COMMA_WITH_SPACE : String? = COMMA + SPACE
}
}
@@ -2,6 +2,6 @@ public trait INode {
class object {
public val IN : String? = "in"
public val AT : String? = "@"
public val COMMA_WITH_SPACE : String? = (COMMA + SPACE)
public val COMMA_WITH_SPACE : String? = COMMA + SPACE
}
}
@@ -1,5 +1,5 @@
while ((a > b))
while (a > b)
{
var i : Int = 1
i = (i + 1)
i = i + 1
}
@@ -1,2 +1,2 @@
while (true)
i = (i + 1)
i = i + 1