From 1afdb8d996f134e64a3025ee1af65dc25199a427 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 18 Sep 2015 13:38:41 +0300 Subject: [PATCH] No nested classes auto-import --- .../kotlin/idea/quickfix/KotlinReferenceImporter.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt index 69d365229d8..92a0a93142e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt @@ -23,6 +23,7 @@ import com.intellij.openapi.command.CommandProcessor import com.intellij.openapi.editor.Editor import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiFile +import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.idea.actions.KotlinAddImportAction import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.core.targetDescriptors @@ -50,7 +51,6 @@ public class KotlinReferenceImporter : ReferenceImporter { companion object { // TODO: use in table cell - // TODO: filter out non-top level public fun autoImportReferenceAtCursor(editor: Editor, file: PsiFile, allowCaretNearRef: Boolean): Boolean { if (file !is JetFile) return false @@ -87,10 +87,13 @@ public class KotlinReferenceImporter : ReferenceImporter { val bindingContext = analyze(BodyResolveMode.PARTIAL) if (mainReference.resolveToDescriptors(bindingContext).isNotEmpty()) return false - val suggestions = AutoImportFix.computeSuggestions(this) + var suggestions = AutoImportFix.computeSuggestions(this) if (suggestions.distinctBy { it.importableFqName!! }.size() != 1) return false + // we do not auto-import nested classes because this will probably add qualification into the text and this will confuse the user + if (suggestions.any { it is ClassDescriptor && it.containingDeclaration is ClassDescriptor }) return false + var result = false CommandProcessor.getInstance().runUndoTransparentAction { result = KotlinAddImportAction(project, editor, this, suggestions).execute()