scala-ide/scala-ide — pull request #246 by dotta (2012-12-05 16:24:28+00:00)
Title: Fix #1001202 - Unable to set breakpoint in source attachment

It turns out that setting a breakpoint on a module declaration could sometime
fail badly (an error dialog was displayed to the user).

The reason why this fails is really simple, a call to
``CompilationUnitAdapter.getPackageDeclarations`` is performed while trying to
toggle the line breakpoint in the editor. And, because the existing
implementation of ``CompilationUnitAdapter.getPackageDeclarations`` used to
throw an ``UnsupportedOperationException``, it's not a surpise that this used
to fail badly.

The quick fix was to implement that method so that the ``PackageDeclaration``
for the opened classfile source is returned. And, in the specific case, the
``PackageDeclaration`` is only needed to find the raw package name, which is
why I have only implemented the ``getElementName`` (look at
``ToggleBreakpointAdapter.createQualifiedTypeName``, at some point you will see
a call to ``pd[0].getElementName();``, where ``pd`` is the
``PackageDeclaration``). This seems to be enough for fixing this specific
issue, and all considered, this fix can only improve on the status quo (simply
because the former implementation thrown an exception right away).

This PR doesn't come with test because the functionality is in the editor, and
we currently don't have a way to create UI tests.

That said, the whole logic we use to handle classfile sources looks a bit
broken. First, why do we need ``ScalaClassFile`` to extend
``ScalaCompilationUnit``? That does not quite make sense to me. And the fact
that the JDT ``ClassFile`` does not extend the JDT ``ICompilationUnit`` just
give one more indication that this is likely not needed. And, if we could make
``ScalaClassFile`` not to extends ``ScalaCompilationUnit``, we could then get
rid of the ``CompilationUnitAdapter``. I've been spending a bit of time looking
into this, but unfortunately I don't have time to experiment this any further
at the moment. I've pushed what I have
[here](https://github.com/dotta/scala-ide/tree/wip/classfile-not-a-compilation-unit),
it's not clean but it should give an idea of where I am heading with this (and
hopefully I'll work on this during my spare time some time in the future).