Possible to do batch refactorings with predefined preview choices?

Hi.

I am trying to do some major refactorings using RefactoringFactory.createRename
and RefactoringFactory.createMoveClassesOrPackages.

I am operating on a large number of classes so I would like to do this in a batch mode with no user interaction.

I rename and then move each of these classes. I have come across a couple of problems:

When I invoke the rename action the editor pops up a preview-dialog asking me to confirm the refactoring.

When I confirm the refactoring the editor pops up a dialog stating that classes have changed since usages was found and asks if I would like to perform the usage search again.

My questions are:

1) Is there a way to perform my refactorings in batch mode without getting the preview pop-up?

2) Is there a way for me to 'commit' the changes for the rename refactoring before I perform the move refactoring so that I avoid the pop-up regarding outdated usage search?

Kind regards
Christian Nedregård

1 comment
Comment actions Permalink

1) Yes, there is a way! Try out the following.

final RefactoringFactory factory = JavaRefactoringFactory.getInstance(project); final RenameRefactoring rename = factory.createRename(psiElement, renameString); rename.doRefactoring(rename.findUsages());


This won't show any pop-up to the user. It will perform refactoring directly.

2) I think you should perform the  'rename' refactoring and then perform the 'move' refactoring. That should do it. I think 'commit' happens automatically. So, once you perform 'rename' refactoring, the file is updated automatically.

0

Please sign in to leave a comment.