Danstahr
Danstahr

Reputation: 4319

Method chain refactoring

I've got two static methods in a Java class :

public class MyFoo {
    public static ClassA foo(ParameterA pa, ParameterB pb, ParameterC c)
        // some implementation
    }
    public static ClassB bar(ParameterA pa, ParameterB pb, ParameterC c) {
        // some implementation
    }
}

And an implementation of ClassA with a method :

public class ClassA {
    public ClassB baz() {
        // some implementation
    }
}

Method bar() was introduced as a new feature and basically it replaces MyFoo.foo(a, b, c).baz(). I'd like to refactor such calls to MyFoo.bar(a, b, c). Is it possible to do this in any IDE? I'm using IntelliJ IDEA, but tips for any IDE are welcome.

Upvotes: 0

Views: 617

Answers (3)

Danstahr
Danstahr

Reputation: 4319

IntelliJ IDEA has Structural search and replace functionality, which allows me to reach my goal.

Upvotes: 0

Tim Boudreau
Tim Boudreau

Reputation: 1781

If you have all the code which ever calls bar() - you can open every project in the universe which links against your code, then:

  • Comment out the real bar() method
  • Use your IDE's rename refactoring to rename foo() to bar()
  • Delete the former foo() method
  • Uncomment the real bar() method

Upvotes: 0

Jirka
Jirka

Reputation: 4213

In Netbeans you can use the Inspect and Transform functionality. You can write your custom script doing stuff like that. It can then be run on a set of files or by clicking a sidebar hint. See also this and this blog entry.

Upvotes: 1

Related Questions