intention to dechain chains of death

i stumple across a lot of code which looks like:


the longer the chain, the more time consuming it is to find the null element. an intention that extracts every return value as a local variable would be fine.

what do you think?

5 comments
Comment actions Permalink

Have you tried the "Chained method calls" inspection? It has a quick fix that introduces a local variable.

Bas

0
Comment actions Permalink

yes, i did just know. the quickfix is not really effective. it's the same as pressing ctrlaltv. i still have to do it for every element of the chain. the same goes for method calls like


i have another problem here: it's difficult to debug, because f8 steps over the method call, and f7 steps into the parameter-calls that are of no interest to me. therefore, i usually extract everything, so f7 steps directly into the method. and becuase it's done usually, there could be a more effective quickfix for it.

0
Comment actions Permalink

CtrlAltV usually needs a selection to work (or do you have the SmartIntroduce plugin installed?), so the intention should save some work. Doing it for all chained calls at once would mean all variable names would be automatically generated. Those names then probably will need to be changed afterwards, making that not a very good solution.

Also, for method calls there is the "Nested method call" inspection.

Bas

0
Comment actions Permalink

A reasonable implementation might be to add another quickfix to the "Chained Method Call" and "Nested Method Call" inspections, which would do the full unsnarling. A similar quickfix might also make sense for "Overly Complex Arithmetic Expression" and "Overly Complex Boolean Inspection", although the value there is less clear. Let me play around with it a bit, and see how it works out.

--Dave Griffith

0
Comment actions Permalink

Well, introduce variable prompts you for a name; why not make it flexible enough to introduce N variables at once? Personally, I only change the suggested name half the time, and even if I changed them all, the sequence (e.g. for three chained method calls):

F2; Alt-Enter; (select quickfix); (change name); tab; (change name); tab; (change name); Enter

Is much faster (for me) than:

F2; Alt-Enter; (select quickfix); (change name); enter; F2; Alt-Enter; (select quickfix); (change name); enter; F2; Alt-Enter; (select quickfix); (change name); enter;

For me, it's all about saving unnecessary repetition, and this is an easy change, so why not?

-Bill

P.S. If this does get picked up as an enhancement at some point, I'd like to suggest that the dialog resizable, maximizable, and scrollable; you never know what madness you'll come across and want to fix when editing other people's code. :)

0

Please sign in to leave a comment.