Wolfgang
Wolfgang

Reputation: 2407

Referencing callee when refactoring in eclipse

Let there be a method like this:

public int a() {
   return 1 + b();
}

Is it possible to apply the "Introduce parameter" refactoring in eclipse on the expression b() such that the caller actually calls the method b on the callee? Like this:

o.a()         // old
o.a( o.b() )  // new

When I do it, it basically copy&pastes the string "b()" into the call which doesn't make sense of cause because this method is on the callee, not the caller. But maybe you know a trick?

Or, alternatively, is it possible to use the "Change Method Signature" refactoring and use an expression in the default value which references the callee? So that I could create a new parameter on a() and let it have a default value of something like ${this}.b()?

Upvotes: 1

Views: 295

Answers (1)

artbristol
artbristol

Reputation: 32407

You can do this indirectly:

  1. Introduce Indirection on o.a() (call it a_tmp)
  2. Refactor a_tmp from return o.a() to return o.a(o.b())
  3. Inline a_tmp

Upvotes: 2

Related Questions