J2K: transform loops with double, float and char range with while

#KT-899 Fixed
This commit is contained in:
Natalia Ukhorskaya
2015-12-18 13:59:07 +03:00
parent ecdef71580
commit 513c4a4562
3 changed files with 69 additions and 6 deletions
@@ -154,6 +154,10 @@ class ForConverter(
val left = condition.lOperand as? PsiReferenceExpression ?: return null
val right = condition.rOperand ?: return null
if (right.type == PsiType.DOUBLE || right.type == PsiType.FLOAT || right.type == PsiType.CHAR) {
return null
}
if (left.resolve() == loopVar) {
val start = loopVar.initializer ?: return null
val operationType = (update as? PsiExpressionStatement)?.expression?.isVariableIncrementOrDecrement(loopVar)
+28 -3
View File
@@ -1,7 +1,32 @@
//file
class Test {
public void printNumbers(int number) {
for(int i = 2; i < Math.sqrt(number) + 1; i++)
System.out.println(i);
public void printNumbers() {
for(int i1 = 0; i1 < 1; i1++)
System.out.println(i1);
byte b = 1;
for(int i2 = 0; i2 < b; i2++)
System.out.println(i2);
short s = 1;
for(int i3 = 0; i3 < s; i3++)
System.out.println(i3);
long l = 1L;
for(int i4 = 0; i4 < l; i4++)
System.out.println(i4);
double d = 1.0;
for(int i5 = 0; i5 < d; i5++)
System.out.println(i5);
float f = 1.0f;
for(int i6 = 0; i6 < f; i6++)
System.out.println(i6);
char c = 1;
for(int i7 = 0; i7 < c; i7++)
System.out.println(i7);
}
}
+37 -3
View File
@@ -1,6 +1,40 @@
internal class Test {
fun printNumbers(number: Int) {
for (i in 2..Math.sqrt(number.toDouble()) + 1 - 1)
println(i)
fun printNumbers() {
for (i1 in 0..0)
println(i1)
val b: Byte = 1
for (i2 in 0..b - 1)
println(i2)
val s: Short = 1
for (i3 in 0..s - 1)
println(i3)
val l = 1L
for (i4 in 0..l - 1)
println(i4)
val d = 1.0
var i5 = 0
while (i5 < d) {
println(i5)
i5++
}
val f = 1.0f
var i6 = 0
while (i6 < f) {
println(i6)
i6++
}
val c: Char = 1.toChar()
var i7 = 0
while (i7 < c.toInt()) {
println(i7)
i7++
}
}
}