Using older methods in API that no longer exist

I am working on a VCS plugin and am trying to make the plugin compatible for both older and newer versions of IntelliJ IDEA (specifically Pycharm). There is a method that has changed between these versions and I am not sure how to include it in my code.

I am implementing the "Log" tab under the "Version Control" tab. In an older version of IntelliJ IDEA, there is a function:
         (#1)   VcsLogStructureFilter.getFiles(VirtualFile);

But in newer versions, this has been replaced with:
         (#2)   VcsLogStructureFilter.getFiles();


I have written my code based on a newer version of IntelliJ IDEA so I am using function (#2). When I try to run my plugin with an older version of Pycharm, I get "NoSuchMethodError" because the IDE is looking for function (#1).


I tried writing this:

try {     
     filterFiles = filterCollection.getStructureFilter().getFiles();
} catch (NoSuchMethodError e) {
     filterFiles = filterCollection.getStructureFilter().getFiles(root);
}

but I cannot get my project to compile and build since the method in the catch block does not exist with the current source code of IntelliJ IDEA that I am working with. Is there any way around this?

3 comments
Comment actions Permalink

The simplest option is to invoke this API through reflection. The more complicated option, which is however more scalable if you need to deal with multiple different APIs, is to create a facade interface and to provide two implementations for it in two different modules, targeting two versions of PyCharm. Then you can compile two versions of your plugin with different implementations of the facade interface.

0
Comment actions Permalink

Allow me to plug my YouTrack issue for exactly this problem: https://youtrack.jetbrains.com/issue/IDEA-141248


0
Comment actions Permalink

Thank you! Invoking through reflection worked well.

0

Please sign in to leave a comment.