ClassCastException when opening classfile with no associated source
java.lang.ClassCastException: org.eclipse.jdt.internal.core.ClassFile cannot be cast to scala.tools.eclipse.InteractiveCompilationUnit
at scala.tools.eclipse.ScalaCompilationUnitEditor$class.getInteractiveCompilationUnit(ScalaCompilationUnitEditor.scala:94)
at scala.tools.eclipse.ScalaClassFileEditor.getInteractiveCompilationUnit(ScalaClassFileEditor.scala:20)
at scala.tools.eclipse.semantichighlighting.Presenter$SemanticHighlightingJob.performSemanticHighlighting(Presenter.scala:117)
at scala.tools.eclipse.semantichighlighting.Presenter$SemanticHighlightingJob.run(Presenter.scala:113)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Most likely, this commit is to blame for the problem.
In scala-ide:67c6cfeefaae2fe66cbd6f3be206e6c56ce40e0b `ScalaClassFileEditor` should always hold a `ScalaClassFile`
There doesn't seem to be a good reason for not creating a `ScalaClassFile` when
source attachments cannot be located.
Doing so has two nice consequences:
1) When sources are manually attached to a Scala JAR, and a classfile is opened
in an editor, the source is now correctly syntactically highlighted. This
basically fix half of ticket Re #1001926 (the other half is triggering
semantic highlighting).
2) `ScalaClassFileEditor` instances are now ensured to be always created with
an underlying `ScalaClassFile`. This is an important fact, as
`ScalaClassFileEditor` assumes it (in fact, the `ClassCastException`
reported in ticket Re #1001925 was happening because this implicit contract
was broken, i.e., it was possible that a `ScalaClassFileEditor` could be
created with a (Java) `ClassFile` when no source attachment was found.
By the way, the `ClassCastException` issue mentioned in point 2) could be
reproduced by copying a **Scala** classfile in the root of a project, and then
trying to opening (by double-clicking on it from the Package Explorer view)
would result in an error prompted to the user.
Fixes #1001925