Search code examples
kotlinintellij-plugin

How to modify class source to annotate Kotlin class by custom Intellij Idea plugin


How to write IntelliJ plugin that modify Kotlin class to annotate it with @RunWith(MockitoJUnitRunner.class) ?

I've tried the following code:

KtPsiFactory(ktFile.project).createAnnotationEntry("@RunWith(MockitoJUnitRunner.class)")

but it throws

0 declarations in @RunWith(MockitoJUnitRunner.class) val x java.lang.AssertionError: 0 declarations in @RunWith(MockitoJUnitRunner.class) val x at org.jetbrains.kotlin.psi.KtPsiFactory.createDeclaration(KtPsiFactory.kt:288)

However it works for @Ignore


Solution

  • Ah.. It should be @RunWith(MockitoJUnitRunner::class)