From 57ff2be9b92fe9999ca0838c15aa976f7301a01f Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 22 Jun 2015 14:57:00 +0300 Subject: [PATCH] Simplified code by introducing one more option in LookupElementFactor --- .../kotlin/idea/completion/CompletionUtils.kt | 16 +--------------- .../idea/completion/LookupElementFactory.kt | 16 +++++++++------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt index cfa29a9cda8..11c32af07c7 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt @@ -351,16 +351,7 @@ fun LookupElementFactory.createLookupElementForType(type: JetType): LookupElemen } else { val classifier = type.getConstructor().getDeclarationDescriptor() ?: return null - val baseLookupElement = createLookupElement(classifier, false) - - var packageName: FqName? = null - var container = classifier.getContainingDeclaration() - while (container is ClassDescriptor) { - container = container.getContainingDeclaration() - } - if (container is PackageFragmentDescriptor) { - packageName = container.fqName - } + val baseLookupElement = createLookupElement(classifier, false, qualifyNestedClasses = true, includeClassTypeArguments = false) val itemText = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type) @@ -368,11 +359,6 @@ fun LookupElementFactory.createLookupElementForType(type: JetType): LookupElemen override fun renderElement(presentation: LookupElementPresentation) { super.renderElement(presentation) presentation.setItemText(itemText) - - presentation.clearTail() - if (packageName != null) { - presentation.appendTailText(" ($packageName)", true) - } } } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt index 5046fbebbdc..bf7422df44a 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt @@ -44,13 +44,14 @@ public class LookupElementFactory( public fun createLookupElement( descriptor: DeclarationDescriptor, boldImmediateMembers: Boolean, - qualifyNestedClasses: Boolean = false + qualifyNestedClasses: Boolean = false, + includeClassTypeArguments: Boolean = true ): LookupElement { val _descriptor = if (descriptor is CallableMemberDescriptor) DescriptorUtils.unwrapFakeOverride(descriptor) else descriptor - var element = createLookupElement(_descriptor, DescriptorToSourceUtils.descriptorToDeclaration(_descriptor), qualifyNestedClasses) + var element = createLookupElement(_descriptor, DescriptorToSourceUtils.descriptorToDeclaration(_descriptor), qualifyNestedClasses, includeClassTypeArguments) val weight = callableWeight(descriptor) if (weight != null) { @@ -99,7 +100,7 @@ public class LookupElementFactory( GRAYED } - public fun createLookupElementForJavaClass(psiClass: PsiClass, qualifyNestedClasses: Boolean = false): LookupElement { + public fun createLookupElementForJavaClass(psiClass: PsiClass, qualifyNestedClasses: Boolean = false, includeClassTypeArguments: Boolean = true): LookupElement { val lookupObject = object : DeclarationLookupObjectImpl(null, psiClass, resolutionFacade) { override fun getIcon(flags: Int) = psiClass.getIcon(flags) } @@ -107,7 +108,7 @@ public class LookupElementFactory( .withInsertHandler(KotlinClassInsertHandler) val typeParams = psiClass.getTypeParameters() - if (typeParams.isNotEmpty()) { + if (includeClassTypeArguments && typeParams.isNotEmpty()) { element = element.appendTailText(typeParams.map { it.getName() }.joinToString(", ", "<", ">"), true) } @@ -138,7 +139,8 @@ public class LookupElementFactory( private fun createLookupElement( descriptor: DeclarationDescriptor, declaration: PsiElement?, - qualifyNestedClasses: Boolean = false + qualifyNestedClasses: Boolean, + includeClassTypeArguments: Boolean ): LookupElement { if (descriptor is ClassifierDescriptor && declaration is PsiClass && @@ -146,7 +148,7 @@ public class LookupElementFactory( // for java classes we create special lookup elements // because they must be equal to ones created in TypesCompletion // otherwise we may have duplicates - return createLookupElementForJavaClass(declaration, qualifyNestedClasses) + return createLookupElementForJavaClass(declaration, qualifyNestedClasses, includeClassTypeArguments) } // for constructor use name and icon of containing class @@ -180,7 +182,7 @@ public class LookupElementFactory( is ClassDescriptor -> { val typeParams = descriptor.getTypeConstructor().getParameters() - if (typeParams.isNotEmpty()) { + if (includeClassTypeArguments && typeParams.isNotEmpty()) { element = element.appendTailText(typeParams.map { it.getName().asString() }.joinToString(", ", "<", ">"), true) }