Structural Search and Rename Refactoring instead of Simple Replace

Answered

Hi,

I'm playing around with Structural Search and Replace, and it's really nice. There's one thing that I expected to be able to do that I wasn't immediately able to figure out.

My goal is to introduce a new naming convention for mock object instances. For example, if we have @Mock private WidgetService widgetService;, I wan to to find all occurrences matching this pattern and rename the member being declared to mockWidgetService.

I was able to find the occurrences I care about and replace them using the templates pictured, and it worked insofar as it changed the declarations in the way I wanted.

However, now I've still got to track down all the usages of these objects and fixup the name. I was hoping there would be a way to find these and automatically apply the Rename refactoring in a formulaic way, so that all occurrences would become mockWidgetService, with no manual fixup. (Parameterized types would still require another round of finagling, but that's ok. For example @Mock Provider<Foo> should become mockFooProvider, not mockProvider<Foo> ideally).

Is there a way to do this, or to export some kind of template (like with fully scoped variable names or file/line numbers) to do a batch rename?

Thanks,
Jay

0
2 comments

Hi Jay,

Batch rename is currently not easily possible. You may want to vote for and add your comments to https://youtrack.jetbrains.com/issue/IDEA-12246

 

Bas

0

Thanks. I wonder what the next best thing is.

It's a shame to have two systems so powerful but not be able to use them in tandem.

-Jay

0

Please sign in to leave a comment.