ServiceLoader alternative for plugin SDK
Answered
I'm curious how can I create a facade class that keeps a collection of instantiated classes implementing a particular class.
So I can further filter these implementations and return specific one everwhere in the code.
Thank you.
Please sign in to leave a comment.
Please explain your use case and where/how you need it in your plugin.
Yann Cebron Hi!
I use PsiAugmentProvider in my plugin to generate some light elements in a class.
The provider works with built-in logic that it can return a List of generated elements of a particular type ONLY. e.g. List of fields or List of methods, but not both in one list...
I have an interface Processor:
And two implementations: Processor1 and Processor2
After that I use them in getAugments(...) looks like this:
The problem is when new Processor is added then I need to add this scary duplications every time in my provider.
So I want this to look something like this:
Where processors is a list that is loaded with singleton instances of every existing Processor implementation.
This would be classical use-case of custom Extension Point https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html, but it probably makes no sense given you're the only consumer of this interface. Not aware of any similar "code-only" API in IntelliJ Platform.