Opening a class file in the JD-Eclipse Realign editor involves the following steps:
- Check whether a source mapper is already installed for the container jar.
- If one already exists use that to get the source for this class file.
- If one does not exist create a new one, register it with the container jar and then use it to get the source for this class file.
My original JD-Eclipse Realign editor changes fixed this by de-registering the source mapper when you close the editor. This still meant that while a single JD-Eclipse Realign editor was open you could still get decompiled source in the standard Class File Viewer. I tried to address this once and for all by removing the source mapper as soon as the JD-Eclipse Realign editor was opened. Unfortunately this had unforeseen consequences. It turns out that navigating to a particular element (e.g. from the Outline view) relies on a source mapper being available.
In light of all of this I concluded that having a special JD-Eclipse editor was actually the wrong approach. A better solution is to treat enabling class decompilation the same way as attaching real source code. To enable this I reworked the Open Class With menu which I had already added to work slightly differently.
- When there is no source attached and decompilation is disabled:
- When there is no source attached and decompilation is enabled:
- When there is source attached:
In this last case the menu doesn't allow decompilation to be directly enabled for dull implementation reasons. In all cases when the source attachment/decompilation state changes all open class file viewers are updated.
With the addition of these new menu options I have also removed the JD-Eclipse Realign editor. My code is packaged as a fragment that extends the base JD Eclipse plugin so I can't remove the vanilla JD Eclipse editor. However, on every startup my fragment will check whether the JD Eclipse editor has been associated with class files (or class files without source) and revert any such associations to use the standard Class File Viewer.
An updated version of JD Eclipse Realign is available from my update site now: http://mchr3k-eclipse.appspot.com/
If you have any issues please do raise it here.