Summary: | [extract method] offer variables to be made parameters | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Barry Kaplan <groups1> |
Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
Status: | ASSIGNED --- | QA Contact: | |
Severity: | enhancement | ||
Priority: | P3 | CC: | reprogrammer |
Version: | 3.1 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Barry Kaplan
2005-06-01 11:04:22 EDT
Not for 3.1 since we are in a mode where we only fix critical bugs. You can add the parameters "back" by introducing parameter. Yes, I know it won't make into 3.1. But I wanted to capture this for possible scheduling into a future release. The current solution is to first create local variables for these elements and then use extract local. Constant expressions like '(Runnable)null', 'AFTER_FILL_DELAY', 'TimeUnit.SECONDS' can be turned into parameters any time, using 'Introduce Parameter'. Things like 'mockScheduledFuture.object' and 'mocks' can only be turned into parameter if it is sure that they are constant during the calling sequence. There is one problem with Introducing parameter after Extract. I get some code from a programmer who prefers the cut&paste&slightly_modify approach to building similar looking code pieces instead of bundling stuff into functions. Now if I have something (simplified case here) like: void f() { JPanel p=new JPanel(); JButton b1=new JButton("foo"); JButton b2=new JButton("bar"); p.add(b1); p.add(b2); } and I do an Extract Method on p.add(b1) Extract method makes b1 into a parameter, and then recognizes that p.add(b2) can be replaced as well. If I have the case JPanel p=new JPanel(); JButton b1=new JButton("foo"); JButton b2=new JButton("bar"); void f() { p.add(b1); p.add(b2); } Extract method will turn it into void f() { g(); p.add(b2); } void g() { p.add(b1); } Using "Introduce parameter" on b1 in method g will then turn this into f() { g(b1); p.add(b2); } private void g(JButton button) { p.add(button); } but I miss the opportunity to have eclipse change all other cases like p.add(b2) to g(b2). So Extract Method + Introduce Parameter is not a full substitute to an Extract method which gives me the possibility to tell right what variables I want to add as parameters. ...unless refactoring is augmented by "Apply method wherever it fits" which I could execute after "Introduce Parameter". |