Optional Kotlin support in a plugin

Answered

Hi there, I develop a plugin for request mapping https://github.com/viartemev/requestmapper

Currently it supports Kotlin and Java, in current configuration Kotlin plugin is required, but it's doesn't make any sense because the plugin can work only with Java.

If I disable Kotlin plugin in a project, my plugin doesn't work.

I enabled optional support of Kotlin:

<depends optional="true" config-file="requestmapper-kotlin.xml">org.jetbrains.kotlin</depends>

But I don't know what info should be placed in requestmapper-kotlin.xml file.

In this plugin I use FilteringGotoByModel and define my class:

class RequestMappingModel(project: Project) : FilteringGotoByModel<FileType>(project,
arrayOf(RequestMappingByNameContributor(listOf(JavaAnnotationSearcher::search, KotlinAnnotationSearcher::search)))), DumbAware {
...
}

where JavaAnnotationSearcher::search and KotlinAnnotationSearcher::search are util classes for finding all annotations in the project:

object KotlinAnnotationSearcher {

fun search(annotationName: String, project: Project): Sequence<PsiAnnotation> {
return KotlinAnnotationsIndex
.getInstance()
.get(annotationName, project, projectScope(project))
.asSequence()
.mapNotNull { it.toLightAnnotation() }
}
}

How should I configure the project?

Plugin.xml file could be found here: https://github.com/viartemev/requestmapper/blob/master/src/main/resources/META-INF/plugin.xml

0
4 comments

Vyacheslav,

Optional Plugin Dependencies section in our SDK Docs describes the optional parameter and the required configuration for such dependency.

You should place in the Kotlin-specific configuration file all extension points that rely on the plugin's classes. So if the external plugin will not be available, declared EPs would not fail because of the missing dependencies.

0

Jakub, thanks for your answer, I've read the documentation and because of that, I mentioned this optional dependency in my question.

The question is how I can configure XML file to pass a different list of contributors implements ChooseByNameContributor?

For example, I have 2 contributors which used in my model class implements FilteringGotoByModel: JavaRequestMappingByNameContributor and KotlinRequestMappingByNameContributor.

How should I configure requestmapper-kotlin.xml file to pass KotlinRequestMappingByNameContributor and JavaRequestMappingByNameContributor when kotlin plugin exists and only JavaRequestMappingByNameContributor if not.

0

You can implement your own Extension Point for that. Main plugin.xml file will provide such EP, optional Kotlin configuration file will contain another Kotlin related one.

Having the custom EP, you'll be able to retrieve a list of the implemented contributors.

0

Thanks. It works for me.

0

Please sign in to leave a comment.