How to refresh / invalidate the cache of decompiled files ? Follow
I'm using the extension point ContentBasedClassFileProcessor. The method String obtainFileText(Project project, VirtualFile virtualFile) returns the mirror source as expected. However when toggling some options on our decompiler that changes the output, the extension point is not called again even when reopening the file to decompile.
I tried a few things here and there to refresh the content of the files our extension has decompiled only, though I couldn't achieve that goal. Do you have pointers on how to do that.
Thanks in adavance.
Happy Easter.
Brice
Please sign in to leave a comment.
Please try this:
FileDocumentManager documentManager = FileDocumentManager.getInstance();
((VirtualFileListener)documentManager).contentsChanged(new VirtualFileEvent(null, virtualFile, virtualFile.getName(), virtualFile.getParent()));
Perfect.
For the record, this code is triggered on a UI event. To make this task asynchronous I put this code in a Runnable submitted to the IntelliJ executor : LaterInvocator.invokeLater
Thanks again.
Brice
Hi,
9 years later I’d like to do the same thing, as I’m updating the code of the jd-intellij plug-in for recent IJ (2021.1, earlier versions if that works). However I am facing an issue with the code snippet above. The constructor of `VirtualFileEvent` changed but that’s not big deal.
But the biggest issue is that the `FileDocumentManager` instance don’t implement anymore the `VirtualFileListener` interface.
Is it possible to guide me to the correct way to do that.
Reference issue: https://github.com/bric3/jd-intellij/issues/59
Branch: https://github.com/bric3/jd-intellij/tree/upgrade-jd-core
Thanks in advance !
You can simply cast to `FileDocumentManagerImpl`, the `contentsChanged` method is still there.
@dmitry Thank you so much. It works.
However I wonder if this approach is future proof. Now that this class is not constrained to the `VirtualFileListener` interface.
So I found this API, that could be like a well suited for this job.
Under the hood it uses a `BulkFileListener` to publish the change.
It seem to be doing the job.