Extract method fail with NoSuchElementException
class Foo {
def foo = {
2
}
def bar = {
List(1,2,3).mkString(",") // <- set the cursor inside the expression, and try to extract method
}
}
Try extract method, the following exception is logged in the Eclipse Error Log view
java.util.NoSuchElementException
at scala.collection.LinearSeqOptimized$class.last(LinearSeqOptimized.scala:135)
at scala.collection.immutable.List.last(List.scala:76)
at scala.tools.refactoring.transformation.TreeFactory$class.mkDefDef(TreeFactory.scala:123)
at scala.tools.refactoring.MultiStageRefactoring.mkDefDef(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.implementations.ExtractMethod.perform(ExtractMethod.scala:46)
at scala.tools.refactoring.implementations.ExtractMethod.perform(ExtractMethod.scala:16)
at scala.tools.eclipse.refactoring.ScalaIdeRefactoring$$anonfun$5$$anonfun$apply$7.apply(ScalaIdeRefactoring.scala:158)
at scala.tools.eclipse.refactoring.ScalaIdeRefactoring$$anonfun$5$$anonfun$apply$7.apply(ScalaIdeRefactoring.scala:157)
at scala.tools.nsc.util.InterruptReq.liftedTree1$1(InterruptReq.scala:20)
at scala.tools.nsc.util.InterruptReq.execute(InterruptReq.scala:19)
at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:330)
at scala.tools.nsc.interactive.PresentationCompilerThread.run(PresentationCompilerThread.scala:22)
Leave a comment
on 2012-07-01 09:25 *
By Mirco Dotta
Oh, I see why it's happening. It expects a valid region to be selected, while I thought the region could have been inferred.
I've added a better check that doesn't allow the refactoring if the selection is not good enough, but I'm leaving this ticket open to fix it properly. There are other things I don't like about extract method, like that it always creates a private "sibling" method, so I plan to write an improved version sometime.
on 2012-07-03 05:54 *
By Mirco Dotta
Coolio. Thanks!
Ticket assignment reverted due to inactivity.
on 2015-12-01 08:25 *
By wpopielarski769697
Version changed from 2.1.0-nightly-29 to 4.3.0
Milestone set to No Milestone Backlog
Can't reproduce anymore.