Community
Participate
Working Groups
At the moment it is relatively unconvenient: create a local variable, convert it to a field. Also, the new 'Introduce Field' action should optionally replace the same code fragment from different methods.
Move to JDT/UI
I'm not sure if I understood what you suggest: You have an local variable and what it to become a field? -> There is already a refactoring 'Convert Local Variable to Field' I don't see where you can replace similar code fragments. Please give an example. Please reopen if I misunderstood the request.
Example: public class Foo { private final Bar bar; public Foo(Bar bar) { this.bar = bar; } public void doSomething() { doSomethingElse(bar.getBazz()); } public void doSomethingElse(Bazz bazz) {...} } I want to introduce a field 'bazz' for 'bar.getBazz()'. Its not possible right now to do it in one step. Expected result (with constructor initialization): public class Foo { private final Bar bar; private final Bazz bazz; public Foo(Bar bar) { this.bar = bar; this.bazz = bar.getBazz(); } public void doSomething() { doSomethingElse(bazz); } public void doSomethingElse(Bazz bazz) {...} }
*** This bug has been marked as a duplicate of 52791 ***