Project: JDT
Bug 48231 extract local variable could be smarter and introduce a block [refactoring] [extract local]
Reported: 2003-12-07 11:32:06 | Status: verified fixed

In the folowing code code snippet extract the expression a[i] public void testFoo() { int a[]= new int[20]; for (int i= 0; i < a.length; i++) System.out.println(a[i]); } You get the error message that i cannot be resolved (this message is confusing). Then when I say proceed, incorrect code is generated: public void testFoo() { int a[]= new int[20]; int j= a[i]; for (int i= 0; i < a.length; i++) System.out.println(j); } The code I would have expected is: public void testFoo() { int a[]= new int[20]; for (int i= 0; i < a.length; i++) { int j= a[i]; System.out.println(j); } } This means the refactoring should be smart enough to introduce the local variable in the correct scope and to also introduce a new block.

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test14_out.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test15_out.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test16_out.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test62_out.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test63_out.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test64_out.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test95_in.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test95_out.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test96_in.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test96_out.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test97_in.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test97_out.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractTempRefactoring.java