IDEA-110978 Refactors this as null when converting for-each loop to indexed for loop

This commit is contained in:
Anna Kozlova
2013-07-31 01:03:33 +02:00
parent f0ebe56a4a
commit 615ffb9356
4 changed files with 21 additions and 1 deletions

View File

@@ -216,7 +216,7 @@ public class ReplaceForEachLoopWithIndexedForLoopIntention extends Intention {
}
return createVariable(variableName, expression, context);
}
return null;
return expression.getText();
}
private static String createVariable(String variableNameRoot,

View File

@@ -0,0 +1,9 @@
package com.siyeh.ipp.forloop.indexed;
import java.util.*;
class NormalForEachLoop implements List<Integer>{
void foo() {
<caret>for (Integer i : this) {
System.out.println(i);
}
}
}

View File

@@ -0,0 +1,10 @@
package com.siyeh.ipp.forloop.indexed;
import java.util.*;
class NormalForEachLoop implements List<Integer>{
void foo() {
for (int i1 = 0, thisSize = this.size(); i1 < thisSize; i1++) {
Integer i = this.get(i1);
System.out.println(i);
}
}
}

View File

@@ -21,6 +21,7 @@ import com.siyeh.ipp.IPPTestCase;
public class ReplaceForEachLoopWithIndexedForLoopIntentionTest extends IPPTestCase {
public void testLabeledForLoop() { doTest(); }
public void testNormalForeachLoop() { doTest(); }
public void testThisExpr() { doTest(); }
public void testNewArray() { doTest(); }
@Override