Project: JDT
Bug 21815 Refactor: should be able to extract local variable from expression used as statement
Reported: 2002-07-23 11:44:42 | Status: resolved fixed

Enter the following class: public class Foo { public static void main(String[] arguments) { new String(); } } Select 'new String()' and choose 'Refactor'->'Extract local variable'. An error message appears saying: 'Cannot extract expressions used as statements.' This seems like an unnecessary restriction. I would like this action to generate: public class Foo { public static void main(String[] arguments) { String temp = new String(); } } This would be useful when you are not sure of the return type of an expression, for instance.

Files changed in fix:
org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractTempRefactoring.java