IllegalArgumentException: Top-level trees cannot have a NoPosition because we need to get the source file.
When I try to to quick fix the import of FileUtils in
I've got
What Can I do to fix / workaround / fallback ?
def prepare(s: Selection): Either[PreparationError, PreparationResult] = Right(new PreparationResult)
def perform(selection: Selection, prepared: PreparationResult, params: RefactoringParameters): Either[RefactoringError, List[Change]] = {
Right(List(new Change(FileUtils.toAbstractFile(file.file), 0, file.getSource.length-1, createText(selection.root)))) // <------- try to quick fix import here
// Right(refactor(List(selection.root)))
}
}
I've got
java.lang.IllegalArgumentException: Top-level trees cannot have a NoPosition because we need to get the source file.
at scala.tools.refactoring.sourcegen.SourceGenerator$class.generateFragmentsFromTrees(SourceGenerator.scala:56)
at scala.tools.refactoring.implementations.AddImportStatement.generateFragmentsFromTrees(AddImportStatement.scala:12)
at scala.tools.refactoring.sourcegen.SourceGenerator$$anonfun$createChanges$1.apply(SourceGenerator.scala:30)
at scala.tools.refactoring.sourcegen.SourceGenerator$$anonfun$createChanges$1.apply(SourceGenerator.scala:30)
at scala.tools.refactoring.common.Tracing$class.context(tracing.scala:30)
at scala.tools.refactoring.implementations.AddImportStatement.context(AddImportStatement.scala:12)
at scala.tools.refactoring.sourcegen.SourceGenerator$class.createChanges(SourceGenerator.scala:29)
at scala.tools.refactoring.implementations.AddImportStatement.createChanges(AddImportStatement.scala:12)
at scala.tools.refactoring.Refactoring$$anonfun$refactor$1.apply(Refactoring.scala:21)
at scala.tools.refactoring.Refactoring$$anonfun$refactor$1.apply(Refactoring.scala:21)
at scala.tools.refactoring.common.Tracing$class.context(tracing.scala:30)
at scala.tools.refactoring.implementations.AddImportStatement.context(AddImportStatement.scala:12)
at scala.tools.refactoring.Refactoring$class.refactor(Refactoring.scala:20)
at scala.tools.refactoring.implementations.AddImportStatement.refactor(AddImportStatement.scala:12)
at scala.tools.refactoring.implementations.AddImportStatement.addImport(AddImportStatement.scala:40)
at scala.tools.refactoring.implementations.AddImportStatement.addImport(AddImportStatement.scala:19)
at scala.tools.eclipse.quickfix.ImportCompletionProposal$$anonfun$applyByASTTransfo$1$$anonfun$1.apply(ImportCompletionProposal.scala:63)
at scala.tools.eclipse.quickfix.ImportCompletionProposal$$anonfun$applyByASTTransfo$1$$anonfun$1.apply(ImportCompletionProposal.scala:49)
at scala.tools.eclipse.ScalaPresentationCompiler.withSourceFile(ScalaPresentationCompiler.scala:67)
at scala.tools.eclipse.ScalaProject$$anonfun$withSourceFile$1.apply(ScalaProject.scala:352)
at scala.tools.eclipse.ScalaProject$$anonfun$withSourceFile$1.apply(ScalaProject.scala:351)
at scala.Either$RightProjection.map(Either.scala:283)
at scala.tools.eclipse.util.Cached$class.apply(Cached.scala:114)
at scala.tools.eclipse.ScalaProject$$anon$2.apply(ScalaProject.scala:35)
at scala.tools.eclipse.ScalaProject.withPresentationCompiler(ScalaProject.scala:337)
at scala.tools.eclipse.ScalaProject.withSourceFile(ScalaProject.scala:353)
at scala.tools.eclipse.javaelements.ScalaCompilationUnit$class.withSourceFile(ScalaCompilationUnit.scala:50)
at scala.tools.eclipse.javaelements.ScalaSourceFile.withSourceFile(ScalaSourceFile.scala:38)
at scala.tools.eclipse.quickfix.ImportCompletionProposal$$anonfun$applyByASTTransfo$1.apply(ImportCompletionProposal.scala:64)
at scala.tools.eclipse.quickfix.ImportCompletionProposal$$anonfun$applyByASTTransfo$1.apply(ImportCompletionProposal.scala:47)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withScalaFileAndSelection$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(EditorHelpers.scala:53)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withScalaFileAndSelection$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(EditorHelpers.scala:52)
at scala.Option.flatMap(Option.scala:142)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withScalaFileAndSelection$1$$anonfun$apply$4$$anonfun$apply$5.apply(EditorHelpers.scala:52)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withScalaFileAndSelection$1$$anonfun$apply$4$$anonfun$apply$5.apply(EditorHelpers.scala:51)
at scala.Option.flatMap(Option.scala:142)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withScalaFileAndSelection$1$$anonfun$apply$4.apply(EditorHelpers.scala:51)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withScalaFileAndSelection$1$$anonfun$apply$4.apply(EditorHelpers.scala:50)
at scala.Option.flatMap(Option.scala:142)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withScalaFileAndSelection$1.apply(EditorHelpers.scala:50)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withScalaFileAndSelection$1.apply(EditorHelpers.scala:49)
at scala.Option.flatMap(Option.scala:142)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withCurrentEditor$1$$anonfun$apply$1$$anonfun$apply$2.apply(EditorHelpers.scala:34)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withCurrentEditor$1$$anonfun$apply$1$$anonfun$apply$2.apply(EditorHelpers.scala:34)
at scala.Option.flatMap(Option.scala:142)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withCurrentEditor$1$$anonfun$apply$1.apply(EditorHelpers.scala:33)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withCurrentEditor$1$$anonfun$apply$1.apply(EditorHelpers.scala:33)
at scala.Option.flatMap(Option.scala:142)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withCurrentEditor$1.apply(EditorHelpers.scala:32)
at scala.tools.eclipse.refactoring.EditorHelpers$$anonfun$withCurrentEditor$1.apply(EditorHelpers.scala:32)
at scala.Option.flatMap(Option.scala:142)
at scala.tools.eclipse.refactoring.EditorHelpers$.withCurrentEditor(EditorHelpers.scala:31)
at scala.tools.eclipse.refactoring.EditorHelpers$.withScalaFileAndSelection(EditorHelpers.scala:49)
at scala.tools.eclipse.quickfix.ImportCompletionProposal.applyByASTTransfo(ImportCompletionProposal.scala:47)
at scala.tools.eclipse.quickfix.ImportCompletionProposal.apply(ImportCompletionProposal.scala:36)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:931)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:877)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1304)
at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:806)
at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:489)
at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:62)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1200)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1185)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1025)
at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5840)
at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:5542)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1200)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1185)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1212)
at org.eclipse.swt.widgets.Widget.gtk_key_press_event(Widget.java:706)
at org.eclipse.swt.widgets.Control.gtk_key_press_event(Control.java:2837)
at org.eclipse.swt.widgets.Composite.gtk_key_press_event(Composite.java:703)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1570)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4594)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4191)
at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:7603)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1185)
at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1860)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3110)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
What Can I do to fix / workaround / fallback ?
Leave a comment
Thanks for reporting; I'll have a look at it!
on 2011-03-04 09:42 *
By Mirko Stocker
Hm, I wanted to reproduce this, but I cannot find the code you mention. Where exactly is it located? Could it be that you haven't pushed that yet :-) ?
on 2011-03-04 09:47 *
By David Bernard
The code about FileUtils.toAbstractFile is in a private branch.
The code where I tried to call quick fix is scala.tools.eclipse.refactoring.RegenerateAction
The code where I tried to call quick fix is scala.tools.eclipse.refactoring.RegenerateAction
on 2011-03-04 09:50 *
By Mirko Stocker
Ah, got it. Thanks!
on 2011-03-06 09:18 *
By Mirko Stocker
I'm sorry but I failed at reproducing this. I built the latest versions of wip_exp_backport and scala-refactoring, and I can add an import for FileUtils at the same location you did (well, it adds an incorrect import to just "util.FileUtils", but still, I don't get the exception).
on 2011-03-06 12:23 *
By David Bernard
Thanks for time. It did the import at end, and removed it later (after a refactor)
If I've got the issue again, what information can I capture to help ?
If I've got the issue again, what information can I capture to help ?
Updating tickets (#1000199, #1000200, #1000201, #1000204, #1000205, #1000209, #1000210, #1000211, #1000212, #1000215, #1000217, #1000218, #1000220, #1000222, #1000226, #1000227, #1000228, #1000230, #1000231, #1000232, #1000233, #1000235, #1000236, #1000237, #1000239, #1000240, #1000241, #1000242, #1000243, #1000244, #1000248, #1000249, #1000252, #1000253, #1000254, #1000255, #1000256, #1000258, #1000259, #1000032, #1000059, #1000062, #1000163, #1000197, #1000216, #1000221, #1000224, #1000121, #1000175, #1000219, #1000251, #1000069, #1000195, #1000213, #1000223, #1000006, #1000021, #1000038, #1000048, #1000051, #1000052, #1000075, #1000103, #1000109, #1000115, #1000119, #1000156, #1000186, #1000207, #1000238, #1000262, #1000263, #380, #389, #683, #1238, #1331, #1635, #1645, #1715, #1729, #1744, #1783, #1839, #1869, #1885, #1890, #1902, #1918, #1919, #1924, #1925, #1946, #1964, #1991, #2131, #2233, #2342, #2348, #2408)
I don't think this should happen again, if it does, please reopen the ticket (I've also added some more information to the exception message).