rearranger request: Support 'create method' intention

It would seem that the exact same behaviors for 'extract method'
refactoring would apply to the 'create method' intention.

7 comments
Comment actions Permalink

Barry,

Can you supply an example? I'm confused. 'Extract method' refactoring creates a private method below the method being edited. (And is not a part of the Rearranger.) If it is doing something that the intention isn't, seems like this would be a feature request for IDEA.

Thanks,
-Dave

0
Comment actions Permalink

Maybe it I that is confused as I have just started to try out
rearranger, let me try to explain.

My understanding is that when doing an extract method, rearranger will
position the newly extracted method within the class (eg, in call order
below the method from which it was extracted). If this is wrong, stop me
here.

Creating a new method via an intention is similar to extract method. The
only difference being that there is no code to populate the new method.
eg, I type 'doSomething()' and idea shows that the method does not
exist. I trigger intention and the method is created. I would like that
newly created method to be positioned by rearranger in the same way that
an extracted method would be positioned.

Am I making sense?

-bk

Dave Kriewall wrote:

Barry,

Can you supply an example? I'm confused. 'Extract method' refactoring creates a private method below the method being edited. (And is not a part of the Rearranger.) If it is doing something that the intention isn't, seems like this would be a feature request for IDEA.

Thanks,
-Dave


0
Comment actions Permalink

Unfortunately, Rearranger doesn't play a part in 'Extract Method' refactoring. That is IDEA's functionality, and it does nothing more than place the extracted method immediately below the method where the cursor is. Actually, that was one of the reasons the plugin was written; folks had the same criticism for many of the other field & method generators (generate constructor, getters/setters, introduce variable/field/constant).

I'm not aware of a way to hook that behavior. Perhaps someone else does. If that were possible, Rearranger might be able to be more proactive (as you describe in your 2nd paragraph).

But for the moment, Rearranger only runs when you explicitly invoke it from the menu or with Ctrl-Shift-Alt-R (default).

0
Comment actions Permalink


Dave Kriewall wrote:

Unfortunately, Rearranger doesn't play a part in 'Extract Method' refactoring. That is IDEA's functionality, and it does nothing more than place the extracted method immediately below the method where the cursor is.


Yes, exactly. That's how I understand it. Now if it could just place the
method created by the 'create method' intention in the same way. I'm
only talking about placement, not the actual functionality.

But for the moment, Rearranger only runs when you explicitly invoke it from the menu or with Ctrl-Shift-Alt-R (default).


Hmm, I'm confused. If rearranger does not trigger on the extract method
refactoring, then how does it know how to rearrange the extracted
methods? What does it mean to 'Options controlling arrangement of
extract methods'? Or in other words, how does it know that a method was
extracted from another if it only runs on demand?

Or is rearranger's definition of an extract method simply a method
called from another method?

0
Comment actions Permalink

1) If so, you should submit an IDEA SCR for the 'create method' intention.

2) Pretty close. An extracted method is determined based on the method call hierarchy and protection level attributes. Rearranger analyzes the method calls and build a tree for every top-level (un-called) method. The tree contains all the methods it calls, in original (file) order, alphabetical order, or in order of invocation. If there are multiple callers of a method, the callee is placed under the first or last caller (configurable). Then the methods are emitted in depth-first or breadth-first order. A called, private method is clearly an extracted method. Configuration controls whether non-private methods are considered extracted or not.

This dynamic determination of extracted methods has the advantage that methods inserted by hand or in some other context (pasted from another source file, etc.) are arranged as the formally "Refactoring.." extracted methods are.

0
Comment actions Permalink


Dave Kriewall wrote:

1) If so, you should submit an IDEA SCR for the 'create method' intention.


I'm not sure what you mean. 'create method' intention exists. Simply
code a call to a method that does not exist -- theNewMethod() or
someobject.theNewMethod() -- and idea will provide an intention to
create that method.


2) Pretty close. An extracted method is determined based on the method call hierarchy and protection level attributes. Rearranger analyzes the method calls and build a tree for every top-level (un-called) method. The tree contains all the methods it calls, in original (file) order, alphabetical order, or in order of invocation. If there are multiple callers of a method, the callee is placed under the first or last caller (configurable). Then the methods are emitted in depth-first or breadth-first order. A called, private method is clearly an extracted method. Configuration controls whether non-private methods are considered extracted or not.


Ok, then I really have no request. As rearranger will handle methods
created via extract-method or the create-method-intention the same.

But it would really be cool if rearranger could detect when the
refactoring or intention just occured and move the method immediatly.

This dynamic determination of extracted methods has the advantage that methods inserted by hand or in some other context (pasted from another source file, etc.) are arranged as the formally "Refactoring.." extracted methods are.


Yes, but immediate and inferred could coexist nicely I would think.

thanks Dave!!

0
Comment actions Permalink

1) I just meant you should file a feature request for IDEA to position the method created by intention as you described. Sorry I was unclear.

2)

Yes, but immediate and inferred could coexist nicely I would think.


I agree. I'll "take it under advisement" ;) - if I ever find a way to hook those actions we can consider it.

0

Please sign in to leave a comment.