Not implemented error during organize imports for ImportSelectorTree
java.lang.RuntimeException: Not implemented! ImportSelectorTree
at scala.sys.package$.error(package.scala:27)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.default(TreePrintingTraversals.scala:88)
at scala.tools.refactoring.sourcegen.PrettyPrinter$prettyPrinter$.default(PrettyPrinter.scala:20)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.ImportSelectorTree(TreePrintingTraversals.scala:139)
at scala.tools.refactoring.sourcegen.PrettyPrinter$prettyPrinter$.ImportSelectorTree(PrettyPrinter.scala:20)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$dispatchToPrinter$1.apply(TreePrintingTraversals.scala:73)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$dispatchToPrinter$1.apply(TreePrintingTraversals.scala:18)
at scala.tools.refactoring.common.SilentTracing$class.context(tracing.scala:99)
at scala.tools.refactoring.MultiStageRefactoring.context(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.dispatchToPrinter(TreePrintingTraversals.scala:18)
at scala.tools.refactoring.sourcegen.PrettyPrinter$prettyPrinter$.dispatchToPrinter(PrettyPrinter.scala:20)
at scala.tools.refactoring.sourcegen.SourceGenerator$class.print(SourceGenerator.scala:160)
at scala.tools.refactoring.MultiStageRefactoring.print(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.printSingleTree(TreePrintingTraversals.scala:194)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.printSingleTree(ReusingPrinter.scala:24)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$2.apply(TreePrintingTraversals.scala:282)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$2.apply(TreePrintingTraversals.scala:280)
at scala.collection.immutable.List$$anonfun$foldRight$1.apply(List.scala:397)
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:124)
at scala.collection.immutable.List.foldLeft(List.scala:84)
at scala.collection.immutable.List.foldRight(List.scala:397)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.printManyTrees(TreePrintingTraversals.scala:280)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.printManyTrees(ReusingPrinter.scala:24)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.pp(TreePrintingTraversals.scala:174)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.pp(ReusingPrinter.scala:24)
at scala.tools.refactoring.sourcegen.ReusingPrinter$ImportPrinters$class.Import(ReusingPrinter.scala:764)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.Import(ReusingPrinter.scala:24)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$dispatchToPrinter$1.apply(TreePrintingTraversals.scala:32)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$dispatchToPrinter$1.apply(TreePrintingTraversals.scala:18)
at scala.tools.refactoring.common.SilentTracing$class.context(tracing.scala:99)
at scala.tools.refactoring.MultiStageRefactoring.context(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.dispatchToPrinter(TreePrintingTraversals.scala:18)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.dispatchToPrinter(ReusingPrinter.scala:50)
at scala.tools.refactoring.sourcegen.SourceGenerator$class.print(SourceGenerator.scala:158)
at scala.tools.refactoring.MultiStageRefactoring.print(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.printSingleTree(TreePrintingTraversals.scala:194)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.printSingleTree(ReusingPrinter.scala:24)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$2.apply(TreePrintingTraversals.scala:282)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$2.apply(TreePrintingTraversals.scala:280)
at scala.collection.immutable.List$$anonfun$foldRight$1.apply(List.scala:397)
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:124)
at scala.collection.immutable.List.foldLeft(List.scala:84)
at scala.collection.immutable.List.foldRight(List.scala:397)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.printManyTrees(TreePrintingTraversals.scala:280)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.printManyTrees(ReusingPrinter.scala:24)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.pp(TreePrintingTraversals.scala:174)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.pp(ReusingPrinter.scala:24)
at scala.tools.refactoring.sourcegen.ReusingPrinter$PackagePrinters$class.PackageDef(ReusingPrinter.scala:821)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.PackageDef(ReusingPrinter.scala:24)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$dispatchToPrinter$1.apply(TreePrintingTraversals.scala:25)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$$anonfun$dispatchToPrinter$1.apply(TreePrintingTraversals.scala:18)
at scala.tools.refactoring.common.SilentTracing$class.context(tracing.scala:99)
at scala.tools.refactoring.MultiStageRefactoring.context(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.TreePrintingTraversals$TreePrinting$class.dispatchToPrinter(TreePrintingTraversals.scala:18)
at scala.tools.refactoring.sourcegen.ReusingPrinter$reusingPrinter$.dispatchToPrinter(ReusingPrinter.scala:50)
at scala.tools.refactoring.sourcegen.SourceGenerator$class.print(SourceGenerator.scala:158)
at scala.tools.refactoring.MultiStageRefactoring.print(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.SourceGenerator$class.generate(SourceGenerator.scala:89)
at scala.tools.refactoring.MultiStageRefactoring.generate(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.SourceGenerator$$anonfun$generateFragmentsFromTrees$4.apply(SourceGenerator.scala:119)
at scala.tools.refactoring.sourcegen.SourceGenerator$$anonfun$generateFragmentsFromTrees$4.apply(SourceGenerator.scala:115)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.immutable.List.map(List.scala:285)
at scala.tools.refactoring.sourcegen.SourceGenerator$class.generateFragmentsFromTrees(SourceGenerator.scala:115)
at scala.tools.refactoring.MultiStageRefactoring.generateFragmentsFromTrees(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.SourceGenerator$$anonfun$createChanges$1.apply(SourceGenerator.scala:33)
at scala.tools.refactoring.sourcegen.SourceGenerator$$anonfun$createChanges$1.apply(SourceGenerator.scala:33)
at scala.tools.refactoring.common.SilentTracing$class.context(tracing.scala:99)
at scala.tools.refactoring.MultiStageRefactoring.context(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.sourcegen.SourceGenerator$class.createChanges(SourceGenerator.scala:32)
at scala.tools.refactoring.MultiStageRefactoring.createChanges(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.Refactoring$$anonfun$refactor$1.apply(Refactoring.scala:32)
at scala.tools.refactoring.Refactoring$$anonfun$refactor$1.apply(Refactoring.scala:31)
at scala.tools.refactoring.common.SilentTracing$class.context(tracing.scala:99)
at scala.tools.refactoring.MultiStageRefactoring.context(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.Refactoring$class.refactor(Refactoring.scala:31)
at scala.tools.refactoring.MultiStageRefactoring.refactor(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.Refactoring$class.transformFile(Refactoring.scala:41)
at scala.tools.refactoring.MultiStageRefactoring.transformFile(MultiStageRefactoring.scala:14)
at scala.tools.refactoring.implementations.OrganizeImports.perform(OrganizeImports.scala:471)
at scala.tools.refactoring.implementations.OrganizeImports.perform(OrganizeImports.scala:79)
at org.scalaide.refactoring.internal.ScalaIdeRefactoring$$anonfun$6$$anonfun$7.apply(ScalaIdeRefactoring.scala:177)
at org.scalaide.refactoring.internal.ScalaIdeRefactoring$$anonfun$6$$anonfun$7.apply(ScalaIdeRefactoring.scala:177)
at scala.tools.nsc.util.InterruptReq.execute(InterruptReq.scala:26)
at scala.tools.nsc.interactive.Global$$anonfun$pollForWork$1.apply$mcV$sp(Global.scala:457)
at scala.util.control.Breaks.breakable(Breaks.scala:38)
at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:431)
at scala.tools.nsc.interactive.PresentationCompilerThread.run(PresentationCompilerThread.scala:22)
Leave a comment
on 2016-02-27 20:22 *
By Simon Schäfer
Follow up of #1002476
Do not throw exception when imports are collapsed to wildcard import
It is kind of difficult to describe why this exception is thrown and the
fact that it took me an entire working day to fix it should speak for
itself. But I will try nevertheless to give a description:
The problem starts in the class `OrganizeImports.AlwaysUseWildcards`. If
the "collapse to wildcard import" option is enabled, this class replaces
all imports that are matched by a wildcard import with such a wildcard
import. Even though the wildcard import is generated it has positions
since the position of the first matching import are set to it. This
means that `ReusingPrinter` is used to print the import. However, in
order to print import selectors the refactoring logic needs to generate
its own trees, called `ImportSelectorTree`. This is necessary, since
import selectors are not trees by default and therefore it wouldn't be
easily possible to print them through the current tree printing
algorithm. Since the `ImportSelectorTree` is synthetic, it doesn't have
positions and is therefore forwarded to `PrettyPrinter`, therefore
`PrettyPrinter` contains the bug fix.
I didn't add the same logic to ReusingPrinter, since I don't see how
such an implementation could ever be called there (there can't be a
reusing part in a synthetic tree). Furthermore, the fix is more
powerful, than what the test can cover. In theory it can even print
rename imports but I was not able to come up with a test case that would
invoke this logic, therefore we have no guarantee that this part of the
implementation is correct or even necessary.
Fixes #1002654
Branch: master
Commit: scala-ide:744c006d26
It is kind of difficult to describe why this exception is thrown and the
fact that it took me an entire working day to fix it should speak for
itself. But I will try nevertheless to give a description:
The problem starts in the class `OrganizeImports.AlwaysUseWildcards`. If
the "collapse to wildcard import" option is enabled, this class replaces
all imports that are matched by a wildcard import with such a wildcard
import. Even though the wildcard import is generated it has positions
since the position of the first matching import are set to it. This
means that `ReusingPrinter` is used to print the import. However, in
order to print import selectors the refactoring logic needs to generate
its own trees, called `ImportSelectorTree`. This is necessary, since
import selectors are not trees by default and therefore it wouldn't be
easily possible to print them through the current tree printing
algorithm. Since the `ImportSelectorTree` is synthetic, it doesn't have
positions and is therefore forwarded to `PrettyPrinter`, therefore
`PrettyPrinter` contains the bug fix.
I didn't add the same logic to ReusingPrinter, since I don't see how
such an implementation could ever be called there (there can't be a
reusing part in a synthetic tree). Furthermore, the fix is more
powerful, than what the test can cover. In theory it can even print
rename imports but I was not able to come up with a test case that would
invoke this logic, therefore we have no guarantee that this part of the
implementation is correct or even necessary.
Fixes #1002654
Branch: master
Commit: scala-ide:744c006d26