Project: JDT
Bug 102288 [refactoring] Convert anonymous: generates fields for constants
Reported: 2005-06-30 06:26:43 | Status: resolved fixed

In 3.1. Consider code: public class Foo { private static final int SEVEN = 7; private static final int FIVE = 5; public static void main(String[] args) { Runnable runnable = new Runnable() { public void run() { System.out.println("The answer is " + (FIVE * SEVEN)); } }; runnable.run(); } } Select the anonymous Runnable, and execute Convert Anonymous Class to Nested. The result: public class Foo { private static class Twelve implements Runnable { private final int fFive; private final int fSeven; private Twelve(int five, int seven) { super(); fFive = five; fSeven = seven; } public void run() { System.out.println("The answer is " + (fFive * fSeven)); } } private static final int SEVEN = 7; private static final int FIVE = 5; public static void main(String[] args) { Runnable runnable = new Twelve(FIVE, SEVEN); runnable.run(); } } I never want this behavior--I want the constants to be used as constants.

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test29_in.java org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test29_out.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ConvertAnonymousToNestedRefactoring.java