Refactor to make implicit parameters explicit
A very nice refactoring would be to convert implicit parameters to explicit ones. For example, suppose you have the following class:
It would be nice if I could select the "y" parameter and say "make explicit". The refactor would then produce
Also, it would be nice to be able to do this for individual invocations, i.e. select the call to "method" and then have the refactor product the following:
I am not a Scala expert, so I'm not sure if this is always easy/possible. It would be nice to do this for implicit def's as well.
object ImplicitTest {
implicit val myImplicit = "implicit string ";
def method(x : Int)(implicit y : String) = {
System.out.println(y + x)
}
def main(args : Array[String]) = {
method(1)
}
}
It would be nice if I could select the "y" parameter and say "make explicit". The refactor would then produce
object ImplicitTest {
implicit val myImplicit = "implicit string ";
def method(x : Int)(y : String) = {
System.out.println(y + x)
}
def main(args : Array[String]) = {
method(1)(myImplicit)
}
}
Also, it would be nice to be able to do this for individual invocations, i.e. select the call to "method" and then have the refactor product the following:
object ImplicitTest {
implicit val myImplicit = "implicit string ";
def method(x : Int)(implicit y : String) = {
System.out.println(y + x)
}
def main(args : Array[String]) = {
method(1)(myImplicit)
}
}
I am not a Scala expert, so I'm not sure if this is always easy/possible. It would be nice to do this for implicit def's as well.
Leave a comment
Thank you for your suggestion; both refactorings shouldn't be too hard to implement; I'll add them to my backlog :-)
on 2014-07-18 18:02 *
By Simon Schäfer
Component changed from Refactoring to Quick Fix
Eclipse version changed from Helios to Kepler - Eclipse 4.3
Version changed from 2.0.0-beta08-29 to 3.0.4-211
Ticket assignment reverted due to inactivity.
on 2015-03-13 16:15 *
By Simon Schäfer
Eclipse version changed from Kepler - Eclipse 4.3 to Luna - Eclipse 4.4
Version changed from 3.0.4-211 to 4.0.0
Milestone changed from Enhancements to -none-