Search code examples
intellij-ideakotlinintellij-plugin

Intellij IDEA plugin development. Action "create kotlin class"


I want to create a plugin for Intellij IDEA. I need to add an action (AnAction) that will create a class in Kotlin (not Java) in a custom package. I have two questions:

  • How to create files with the desired extension?
  • Or how to create a file with Kotlin class(from some base class) in a custom package?

Solution

  • One possible way to accomplish this is to use PsiFileFactory.createFileFromText() to create an in-memory Kotlin file and then to pass that file as a parameter to PsiDirectory.add() to save it to the filesystem.