Extract Method Monitor

I was just doing a routine "extract method" and came up with a novel, and usefull IDEA(tm).

At first, I couldn't complete the extraction as the block of code I selected contained two output fields. Once I'd fixed that, I could now extract, but I have 10 parameters.

Now, heres my idea.... it would great if I could select a block of code for extraction, and select an "extraction mode" monitor, this would open up a tab on the bottom of the editor showing the output fields, and incoming parameters that would be created if the selected block was extracted.

Now, the actual editor would unselect the text, but cover it in say a pale blue background, as I edit the code block, moving declarations inside or outside, the list of output fields and parameters would change, this way I can interactively rework the code to limit the number of parameters passed in.

Once I'm happy with the code block, I can click the extract button in the tab, which does the extraction as normal.

If multiple return values still exist, an option to "extract and create
inner return class" could also be usefull.

This has also just been added in the tracker. Thoughts?

--
Discouragement is a disatisfaction with the past, a distate for the
present, and a distrust of the future - Maree De Jong, CLCA.

7 comments

I think this is cool but too complicated and not all that useful. What would be cool is if you had multiple outputs of the method, IDEA would automatically create a new class that contained a field for each value, and use that in the extracted method (and return it).

0

On Wed, 15 Oct 2003 05:09:21 +0000, Keith Lea wrote:

I think this is cool but too complicated and not all that useful. What
would be cool is if you had multiple outputs of the method, IDEA would
automatically create a new class that contained a field for each value,
and use that in the extracted method (and return it).


Well I did mention that piece at the end of my idea as well.

I was just thinking of ways to easily reduce the number of input
parameters, which is often solved my moving a temp. variable declaration
inside a block. The idea of having a monitored block is so I don't have
to keep reselecting the block and hitting ctrl-alt-m

--
Discouragement is a disatisfaction with the past, a distate for the
present, and a distrust of the future - Maree De Jong, CLCA.

0

Mark Derricutt wrote:

>This has also just been added in the tracker. Thoughts?

>

I'm not sure I understand your idea.
Could you give a little example, and make a stupidly simple mock ui?

Alain


0

On Wed, 15 Oct 2003 07:07:25 -0100, Alain Ravet wrote:

I'm not sure I understand your idea.
Could you give a little example, and make a stupidly simple mock ui?


Well my UI coding rather sucks, so I'll try an example, take the following
code:

public String something() {
String foo;
String bar = someOtherFunction();
bar = manipulate(bar);
....
// Set foo to something, imagine there could be lots of code following
// the assignment.
foo = bar;

return foo;
}

Now, for this exercise, we're looking at the code, and we decide to
extract "the assignment of foo", so we highlight the two comment lines,
and the assignment, hit ctrl-alt-m.

The dialog tells us in order to extract that, bar needs to be passed in as
a parameter, due to its definition falling outside of the selected block.

Normally, we'd either do the extract, the edit the resulting code to move
the calls to someOtherFunction() and manipulate() inside the new method,
removing the requirement of the parameter.

The other option, is to cancel the operation, cut-n-paste the lines
referring to bar to within the region we're extracting ( so that other
code no longer sits between them, in this example, the code before
extraction would look like:

public String something() {
String foo;
....

String bar = someOtherFunction();
bar = manipulate(bar);
// Set foo to something, imagine there could be lots of code following
// the assignment.
foo = bar;

return foo;
}

This time, all the code we want to extract is within one continuous block,
and can be extracted without introducing the unneeded parameter.

Only, we need to then reselect the block of code, in a trivial example
this doesn't really matter, but if the code we wanted to extract was
wanting to introduce 5-6 parameters, or more, you can start to round-trip
the exercise of reorder code, reselect, extract, still 4 params we don't
really need, reorder some more code, repeat, 2 unwanted params, reorder,
done.

The idea I had was, if in this "extract mode", an extraction region is
defined, and as the code is worked on, whatever routine IDEA currently
calls to "identify required parameters" could be called and update a
display in real time, this was, as you move code around, you can see the
required parameters change, and get an interactive feeling for the
impending extraction.

It was just something I thought of this morning refactoring a particularly
nasty large routine that wanted me to introduce about 10 parameters, and 4
return values - the return values wern't used, but were declared outside
the scope, and only modified inside the the extraction region, and the 10
parameters where temporary variables based on fields of the surrounding
class ( substrings, regex manipulations etc. etc. ) - all things that
could easily be handled inside the subroutine I wanted to extract, but
after spending 4-5 minutes tidying up a block of code to move into the
extract region, I'd forgotten what the other block was, I thought "it'd be
nice if IDEA could remind me what it told me earlier in that modal dialog".




--
"It's all in the heat of the moment, it's all in the pain..." Devy.
Mark Derricutt @ mark@talios.com @ talios.blog-city.com
Now Playing: %s

0

Mark, I think this is an excellent idea ((tm) or not).
I just wonder whether the APIs are rich enough to implement
it as a plugin. Having it as an IDEA first class feature
would be of course much (WAY MUCH) better.

r.


Mark Derricutt wrote:

I was just doing a routine "extract method" and came up with a novel, and usefull IDEA(tm).

At first, I couldn't complete the extraction as the block of code I selected contained two output fields. Once I'd fixed that, I could now extract, but I have 10 parameters.

Now, heres my idea.... it would great if I could select a block of code for extraction, and select an "extraction mode" monitor, this would open up a tab on the bottom of the editor showing the output fields, and incoming parameters that would be created if the selected block was extracted.

Now, the actual editor would unselect the text, but cover it in say a pale blue background, as I edit the code block, moving declarations inside or outside, the list of output fields and parameters would change, this way I can interactively rework the code to limit the number of parameters passed in.

Once I'm happy with the code block, I can click the extract button in the tab, which does the extraction as normal.

If multiple return values still exist, an option to "extract and create
inner return class" could also be usefull.

This has also just been added in the tracker. Thoughts?


0

Mr, Derricutt,
I think I understand your proposal. It sounds useful and promising. I have
recently tried to use extract method and wound up doing it by hand for just
that reason -- the code was looked straightforward to extract, but the
computer couldn't figure that out (not without a little help).
Alas, I think a prototype would be necessary in order to see how workable it
is in practice.
It wouldbe_ great if the the plugin API supported just this sort of add
in. ( I don't know if it does or does not.)

"Richard Nemec" <rndzank@attbi.com> wrote in message
news:bmjao1$udc$1@is.intellij.net...

Mark, I think this is an excellent idea ((tm) or not).
I just wonder whether the APIs are rich enough to implement
it as a plugin. Having it as an IDEA first class feature
would be of course much (WAY MUCH) better.

>

r.

>
>

Mark Derricutt wrote:

I was just doing a routine "extract method" and came up with a novel,

and usefull IDEA(tm).

>

At first, I couldn't complete the extraction as the block of code I

selected contained two output fields. Once I'd fixed that, I could now
extract, but I have 10 parameters.

>

Now, heres my idea.... it would great if I could select a block of code

for extraction, and select an "extraction mode" monitor, this would open up
a tab on the bottom of the editor showing the output fields, and incoming
parameters that would be created if the selected block was extracted.

>

Now, the actual editor would unselect the text, but cover it in say a

pale blue background, as I edit the code block, moving declarations inside
or outside, the list of output fields and parameters would change, this way
I can interactively rework the code to limit the number of parameters passed
in.

>

Once I'm happy with the code block, I can click the extract button in

the tab, which does the extraction as normal.

>

If multiple return values still exist, an option to "extract and create
inner return class" could also be usefull.

>

This has also just been added in the tracker. Thoughts?

>

>


0

On Wed, 15 Oct 2003 10:35:04 -0700, Charles Eubanks wrote:

Mr, Derricutt,
I think I understand your proposal. It sounds useful and promising. I
have recently tried to use extract method and wound up doing it by hand
for just that reason -- the code was looked straightforward to extract,
but the computer couldn't figure that out (not without a little help).


I just also had the thought of "extraction intentions", intentions that
are specific to extraction regions. like "combine parameters into inner
class", or something like that.

Alas, I think a prototype would be necessary in order to see how
workable it is in practice.


I could look at a prototype, don't have much time at the moment thou as
I'm moving house tomorrow.

It wouldbe_ great if the the plugin API supported just this sort of
add in. ( I don't know if it does or does not.)


It would heavily use the PSI code ( my guess ), which currently isn't part
of the OpenAPI - is this (unofficially) documented anywhere at all?

Mark


--
Discouragement is a disatisfaction with the past, a distate for the
present, and a distrust of the future - Maree De Jong, CLCA.

0

Please sign in to leave a comment.