refactor: Introduce Indirection

254 views
Skip to first unread message

Tom Howland

unread,
Apr 15, 2013, 2:38:50 PM4/15/13
to scala-i...@googlegroups.com
I'm checking the Eclipse help pages on refactoring. 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 method
Options: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?
  2. If we were to implement it, how would we go about it?

Mirco Dotta

unread,
Apr 16, 2013, 8:36:54 AM4/16/13
to scala-i...@googlegroups.com
Hi Tom,

All refactoring in the Scala IDE are provided by a third-party library, scala-refactoring; Mirko Stocker is the author. He usually hangs around this mailing list, hopefully you'll get his feedback.

Cheers,
  Mirco

--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


---------------
Mirco Dotta
PSE-D, 1015 Lausanne, Switzerland
Twitter: @mircodotta

See you at Scala Days 2013 in NYC!
June 10th - June 12th








Mirko Stocker

unread,
Apr 22, 2013, 8:44:18 AM4/22/13
to scala-i...@googlegroups.com, Tom Howland
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
Reply all
Reply to author
Forward
0 new messages