Custom stubIndex for java/kotlin

Is it possible to add custom stub indexes for non-custom languages? For example, I’d like to add an index based on the method’s return type to quickly find all methods with a specific return type. Ideally, I’d even like to be able to intervene in the index building logic, adding only indexes to specific methods, such as those that must be production code or have a certain annotation.

Probably not stub, but just implement any additional FileBasedIndexExtensions as you want. Stubs are unfortunately fully tied to language PSI and parser.

Why would you need stub index specifically for your tasks?

My current idea is to be able to quickly search for methods whose return type is this type name by type name. However, I found that the existing method index only has the method name and parameter list, but lacks the return type.

It is like this because return type requires resolve, it cannot be statically inferred during indexing. You can do it with a regular file based index, don’t really need any stub extension for that