Programmatically auto import suggested imports

Answered

I'm aware you can use JavaCodeStyleManager.shortenClassReferences() to automatically add imports for code that is fully qualified, but how would you do something similar with code that is not fully qualified? The suggested imports that are added by doing multiple ALT+ENTER keyboard shortcuts are the imports I would like added automatically.

How can I programmatically allow IntelliJ to apply all suggested imports?

0
3 comments

Do you want to modify the behaviour for Java plugin or create something for your own plugin?

1

I want to create something for my own plugin. Also, I'm curious how a similar situation would work with Kotlin. There isn't a KotlinCodeStyleManager.shortenClassReferences().

0

Java plugin implementation of quickfix com.intellij.codeInsight.daemon.impl.actions.AddImportAction

Python plugin implementation com.jetbrains.python.codeInsight.imports.ImportFromExistingAction

 

See https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010025120-Add-new-parameter-into-kotlin-data-class-from-IDEA-plugin?page=1#community_comment_360002950760 about Kotlin.

0

Please sign in to leave a comment.