How to extract a method across files?

slartidan :

In all my java files of my project, I want to replace occurrences of this:

myObject.getName() == null

With that:

myObject.hasName()

Is there any action or strategy to do this with IntelliJ IDEA?

  • I want it to be specific to the getName method of my class MyClass and not to replace code, that refers to methods called getName of other classes.
  • I want it to find as many matches as possible. It should not care about additional spaces, linebreaks, etc. If the variable has another name (like myObj or objX) it should also work. Calls like getObject().getName() should also be found. (The search has to care about semantics).
  • I want it to be fast and not to require me to go through the hundreds of matches one by one.
Bas Leijdekkers :

Use Structural Search & Replace (Edit | Find | Replace Structurally...), it is designed for use cases like this.

Use Search template:

$x$.getName() == null

Replacement template:

$x$.hasName()

Click the Edit Variables... button and specify Expression type (regexp) as MyClass. When searching this will also find your example of getObject().getName() == null

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=435572&siteId=1