Intellj Idea refactoring replace one interface with another

292 views Asked by At

I found 2 similar interfaces. I'd like to replace all usages one interface with another in 1 click (refactoring). Refactoring is more safe due it aware of context change rather than plain regexp replace.

But I cannot find fit refactoring in IntelliJ Idea.

1

There are 1 answers

1
kukido On

You need to use Structural Search and Replace. It is available in Ultimate edition.

Edit > Find > Replace Structurally

Rationale: Imagine that we have a large source code-base that we need to browse or modify it. For instance, we might want to use a library and find out how it works, or we might need to get acquainted with existing code and to modify it. Yet another example is that a new JDK becomes available and we are keen to see the changes in the standard Java libraries and so on. Conventional tools like find and replace text may not completely address these goals because when we use them, it is easy to find or replace too much or too little. Of course, if someone already knows the source code well, then using the whole words option and regular expressions may help make our find-and-replace queries smarter.

The problem of the conventional approach, even with regular expressions, is that they just do not know anything about the syntax and semantics of the source code we are using. This is why we combined the search-and-replace feature with knowledge about the source code, producing the Structural Search and Replace (SSR) feature.

enter image description here

SSR is a very powerful feature, I recommend Basics of working with structural search tutorial to get started.