Does AnnotationHolder.newAnnotation(..) support backward compatibility?

已回答

Currently, I'm working on an IntelliJ IDEA plugin which uses the bellow method.

annotationHolder.createInfoAnnotation(..)

But since IntelliJ IDEA 2020 version this method is deprecated. In the JetBrains/intellij-community GitHub repository mentioned to use an alternative implementation,

https://github.com/JetBrains/intellij-community/blob/cf73d6191477d457a624d2556c8a3b12f38b724a/platform/analysis-api/src/com/intellij/lang/annotation/AnnotationHolder.java#L148

which is,

annotationHolder.newAnnotation(..)

But this implementation couldn't able to find in previous SDK's(2019 and lower). I would like to know is there any other alternative implementation for this?

0

That API isn't backward compatible. You can use the old API until it gets removed in a future version.

In my plugin, I have a set of compatibility APIs for the different IntelliJ versions. For each IntelliJ version, I have a native (for >= version) and compat (for < version) folders with appropriate implementations enabled in build.gradle:

if (ext.intellij_version >= 201) {
sourceSets.main.java.srcDirs += 'src/201/native'
} else {
sourceSets.main.java.srcDirs += 'src/201/compat'
}

I have annotation compatibility APIs in https://github.com/rhdunn/xquery-intellij-plugin/tree/master/src/intellij-compat/src/201/native/com/intellij/compat/lang/annotation and https://github.com/rhdunn/xquery-intellij-plugin/tree/master/src/intellij-compat/src/201/compat/com/intellij/compat/lang/annotation.

1

Just keep using the old (deprecated) method until you move your minimum required target platform to the one containing new API. These methods are unlikely to be removed in the coming years as they're widely used.

1

请先登录再写评论。