Hi Tom
On Monday 15 April 2013 11:38:50 Tom Howland wrote:
> I'm checking the Eclipse help pages on
> refactoring<
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt
> .doc.user%2Freference%2Fref-menu-refactor.htm>. Java has the refactoring
>
> Introduce Indirection: Creates a static indirection method delegating to
> the selected method.
> Available:Methods or on text selection resolving to a methodOptions:Enable
> 'Redirect all method invocations' to replace all calls to the original
> method by calls to the indirection method.
>
> Unfortunately, there is no Scala equivalent for this. We desperately need
> this.
>
> 1. Any chance this is in the works?
Nope, not to my knowledge.
> 2. If we were to implement it, how would we go about it?
I think we can break this refactoring down into several steps:
1) Create a new "redirection" method that takes a parameter and calls the
original method on that parameter.
2) Put that method into the companion object, creating the companion object if
it doesn't exist yet.
3) Search for calls to the original Method and replace them with a call to the
new redirection method.
For 1) and 2), a new AddMethod refactoring has just landed in scala-
refactoring that creates a method and inserts it into a class or companion.
This could create as a starting point.
https://github.com/scala-ide/scala-refactoring/commit/59c40d583acbef09cd99d9f3d786f8f2e045398a
3) For 3, you first need to find all occurrences and then change them. This is
not too different from renaming, so the rename refactoring could give you some
hints:
https://github.com/scala-ide/scala-refactoring/blob/master/org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/implementations/Rename.scala
This is the scala-refactoring side, after that you also need to integrate it
into the Scala IDE similarly to the existing refactorings (providing the GUI
and handling user interaction).
I'm looking forward to your contribution :-)
Cheers
Mirko
--
Mirko Stocker |
m...@misto.ch
Work:
http://ifs.hsr.ch |
http://infoq.com
Personal:
http://misto.ch |
http://twitter.com/m_st