Set Default Selection in Refactoring Dialogs

I am using several of the refactoring handlers in my plugin code, for example the IntroduceFieldHandler in order to launch a refactoring to introduce a new field for a given PsiExpression.

However, the API for this and some of the other handlers appears to be quite limited, i.e. I am only able to start the refactoring (invoke()) but do not get the ability to change some of the parameters. What I would like to do is to make a default selection in the dialog that appears. More specifically, in the case of the IntroduceFieldHandler I would like to preselect "initialize in constructor".

Is there any way to achieve this in this case, and more generally, is there a way to have more control over refactorings than simply starting them?

Thanks,
Simon

4 comments
Comment actions Permalink

Well, the refactoring implementation classes are usually public, and you can call them directly or inherit your own classes from them. For this particular case, the easiest thing you can do is change IntroduceFieldDialog.ourLastInitializerPlace to your desired value before invoking the refactoring.

0
Comment actions Permalink

Hm, sadly in this case it seems as though IntroduceFieldDialog is package local and I cannot set the initialiserPlace myself. Is there any specific reason for this?

0
Comment actions Permalink

Not really, other than that this class wasn't designed as an API - it's just implementation code. You can use reflection to change the field.

0
Comment actions Permalink

Okay, I may use reflection in that case although it's quite hacky... Thanks!

0

Please sign in to leave a comment.