test for "Replace 'for each' loop with indexed 'for' loop"
authorBas Leijdekkers <basleijdekkers@gmail.com>
Mon, 23 Jan 2012 13:02:35 +0000 (14:02 +0100)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Mon, 23 Jan 2012 13:02:35 +0000 (14:02 +0100)
plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/LabeledForLoop.java [new file with mode: 0644]
plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/LabeledForLoop_after.java [new file with mode: 0644]
plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NewArray.java [new file with mode: 0644]
plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NewArray_after.java [new file with mode: 0644]
plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NormalForeachLoop.java [new file with mode: 0644]
plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NormalForeachLoop_after.java [new file with mode: 0644]
plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntentionTest.java [new file with mode: 0644]

diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/LabeledForLoop.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/LabeledForLoop.java
new file mode 100644 (file)
index 0000000..ecb0061
--- /dev/null
@@ -0,0 +1,10 @@
+package com.siyeh.ipp.forloop.indexed;
+
+class LabeledForLoop {
+
+    int[] getArr() {
+        Label:
+        <caret>for (int x: getArr()) {}
+        return new int[]{1};
+    }
+}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/LabeledForLoop_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/LabeledForLoop_after.java
new file mode 100644 (file)
index 0000000..3630dc6
--- /dev/null
@@ -0,0 +1,13 @@
+package com.siyeh.ipp.forloop.indexed;
+
+class LabeledForLoop {
+
+    int[] getArr() {
+        int[] arr = getArr();
+        Label:
+        for (int i = 0, arrLength = arr.length; i < arrLength; i++) {
+            int x = arr[i];
+        }
+        return new int[]{1};
+    }
+}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NewArray.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NewArray.java
new file mode 100644 (file)
index 0000000..132e95f
--- /dev/null
@@ -0,0 +1,8 @@
+package com.siyeh.ipp.forloop.indexed;
+
+class NewArray {
+    void foo() {
+        <caret>for (int k : new int[3]) {
+        }
+    }
+}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NewArray_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NewArray_after.java
new file mode 100644 (file)
index 0000000..5dfc3e6
--- /dev/null
@@ -0,0 +1,10 @@
+package com.siyeh.ipp.forloop.indexed;
+
+class NewArray {
+    void foo() {
+        int[] ints = new int[3];
+        for (int i = 0, intsLength = ints.length; i < intsLength; i++) {
+            int k = ints[i];
+        }
+    }
+}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NormalForeachLoop.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NormalForeachLoop.java
new file mode 100644 (file)
index 0000000..670b33d
--- /dev/null
@@ -0,0 +1,9 @@
+package com.siyeh.ipp.forloop.indexed;
+
+class NormalForEachLoop {
+    void foo(int[] is) {
+        <caret>for (int i : is) {
+            System.out.println(i);
+        }
+    }
+}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NormalForeachLoop_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/forloop/indexed/NormalForeachLoop_after.java
new file mode 100644 (file)
index 0000000..5bf04ed
--- /dev/null
@@ -0,0 +1,10 @@
+package com.siyeh.ipp.forloop.indexed;
+
+class NormalForEachLoop {
+    void foo(int[] is) {
+        for (int i1 = 0, isLength = is.length; i1 < isLength; i1++) {
+            int i = is[i1];
+            System.out.println(i);
+        }
+    }
+}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntentionTest.java
new file mode 100644 (file)
index 0000000..4155af6
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.siyeh.ipp.forloop;
+
+import com.siyeh.IntentionPowerPackBundle;
+import com.siyeh.ipp.IPPTestCase;
+
+public class ReplaceForEachLoopWithIndexedForLoopIntentionTest extends IPPTestCase {
+  public void testLabeledForLoop() { doTest(); }
+  public void testNormalForeachLoop() { doTest(); }
+  public void testNewArray() { doTest(); }
+
+  @Override
+  protected String getIntentionName() {
+    return IntentionPowerPackBundle.message("replace.for.each.loop.with.indexed.for.loop.intention.name");
+  }
+
+  @Override
+  protected String getRelativePath() {
+    return "forloop/indexed";
+  }
+}