Project: JDT
Bug 393098 [extract method] Extracted method should be declared static if extracted expression is also used in another static method
Reported: 2012-10-29 16:55:34 | Status: resolved fixed

Extracted method should be declared static if extracted expression is also used in another static method. Steps to reproduce: 1. In the example below invoke "Extract Method" on "shared()" expression in non-static method (nsm). 2. New method will not be declared as static. 3. There will be a compilation error because non-static method is invoked from static context. Note: Originally the bug was encountered when extracting "getTestConstructor(theClass)" on line 136 in junit.framework.TestSuite, JUnit commit e8b91fa9f797dfe16aff66ed6ad5d6104e5133fe. public class ExtractMethodBug { public static void sm() { // Compilation error will be on the next line shared(); } public void nsm() { // Invoke Extract Method refactoring on the "shared()" expression shared(); } public static void shared() { } }

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/duplicates_in/A_test988.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/duplicates_in/A_test989.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/duplicates_out/A_test988.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/duplicates_out/A_test989.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/SnippetFinder.java org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/code/ExtractMethodInputPage.java