On Fri, 2002-03-15 at 00:09, Jacques Morel wrote:

> I would be nice if the extract method would allow to pick expressions
> within the extracted area to pass as parameter and to keep on the call
> site side.

I've had a similar problem, extracting a method from code looking like
this:

    method(foo.getName(), something.getA().getB());
    other_code();
    ...

If I extract a method here, IDEA generates a method taking foo and
something as arguments:

    newMethod(foo, something);

    public void newMethod(Foo foo, Something something) {
        method(foo.getName(), something.getA().getB());
        other_code();
        ...
    }

But sometimes the reason for extracting the method is that I want to use
it in multiple places and call it with different arguments -- not
necessarily with a Foo and a Something, but (for example) with a name
and an A.  So I'd like it to take foo.getName() and something.getA() as
arguments:

    newMethod(foo.getName(), something.getA());

    public void newMethod(String name, A a) {
        method(name, a.getB());
        other_code();
        ...
    }

As in your example, this means I have to extract variables for
foo.getName() and something.getA(), maybe move the variable declarations
up so that they are outside the block that will become the new method,
extract the method, and then inline the variables into the method call.

On the other hand I can't really envision a simple and intuitive GUI
that lets you do this more easily in a single step...  How would the
parameters be specified?  In my case I guess it would be simple to
select (maybe with a dropdown) whether I want to send something,
something.getA() or something.getA().getB() -- but with a more complex
example you might have the following:

        method(foo.getName(), something.getA().getB());
        other_code(something.getC());

Now what should happen if IDEA initially suggests foo and something as
parameters, and then I select something.getA() instead of something? 
Suddenly it has to add another parameter to the list in order to get
something.getC() to work.

And it seems like it would be difficult to guarantee that the semantics
remains the same, if the refactoring causes you to evaluate expressions
in a different order.



_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://www.intellij.com/mailman/listinfo/eap-features

Reply via email to