diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceIteratorForEachWithFor/afterFinalItem.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceIteratorForEachWithFor/afterFinalItem.java new file mode 100644 index 000000000000..6735ae61604f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceIteratorForEachWithFor/afterFinalItem.java @@ -0,0 +1,11 @@ +// "Replace 'for each' loop with iterator 'for' loop" "true" +import java.util.Iterator; + +public class FinalItem { + void foo(Iterator it) { + for (Iterator it1 = it; it1.hasNext(); ) { + final Integer integer = it1.next(); + System.out.println(integer); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceIteratorForEachWithFor/beforeFinalItem.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceIteratorForEachWithFor/beforeFinalItem.java new file mode 100644 index 000000000000..3d5fcd04e072 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceIteratorForEachWithFor/beforeFinalItem.java @@ -0,0 +1,8 @@ +// "Replace 'for each' loop with iterator 'for' loop" "true" +import java.util.Iterator; + +public class FinalItem { + void foo(Iterator it) { + for (Integer integer : it) System.out.println(integer); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ReplaceIteratorForEachLoopWithIteratorForLoopFixTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ReplaceIteratorForEachLoopWithIteratorForLoopFixTest.java index 751f5dd7e95f..cd7f9319a322 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ReplaceIteratorForEachLoopWithIteratorForLoopFixTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/ReplaceIteratorForEachLoopWithIteratorForLoopFixTest.java @@ -15,13 +15,37 @@ */ package com.intellij.codeInsight.daemon.quickFix; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; + /** * @author Pavel.Dolgov */ public class ReplaceIteratorForEachLoopWithIteratorForLoopFixTest extends LightQuickFixParameterizedTestCase { + private boolean myFinalLocals; + public void test() throws Exception { doAllTests(); } + @Override + protected void beforeActionStarted(String testName, String contents) { + super.beforeActionStarted(testName, contents); + if (testName.startsWith("Final")) { + final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()); + myFinalLocals = codeStyleSettings.GENERATE_FINAL_LOCALS; + codeStyleSettings.GENERATE_FINAL_LOCALS = true; + } + } + + @Override + protected void afterActionCompleted(String testName, String contents) { + if (testName.startsWith("Final")) { + final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()); + codeStyleSettings.GENERATE_FINAL_LOCALS = myFinalLocals; + } + super.afterActionCompleted(testName, contents); + } + @Override protected String getBasePath() { return "/codeInsight/daemonCodeAnalyzer/quickFix/replaceIteratorForEachWithFor";