Search code examples
android-studiointellij-ideapluginskotlinintellij-plugin

how to create kotlin class when developing intellij idea plugin?


When developing Intellij Idea plugin creating java classes can be done with JavaDirectoryService which creates PsiClasses according to file templates. Is there any way to create kotlin classes with similar method?


Solution

  • You can use FileTemplateUtil.createFromTemplate() to create a file of any type from a template, including a Kotlin class.

    val fileTemplate = FileTemplateManager.getInstance().getTemplate("Kotlin Class")
    FileTemplateUtil.createFromTemplate(template, fileName, null, psiDirectory)