Simplified code by introducing one more option in LookupElementFactor
This commit is contained in:
@@ -351,16 +351,7 @@ fun LookupElementFactory.createLookupElementForType(type: JetType): LookupElemen
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val classifier = type.getConstructor().getDeclarationDescriptor() ?: return null
|
val classifier = type.getConstructor().getDeclarationDescriptor() ?: return null
|
||||||
val baseLookupElement = createLookupElement(classifier, false)
|
val baseLookupElement = createLookupElement(classifier, false, qualifyNestedClasses = true, includeClassTypeArguments = false)
|
||||||
|
|
||||||
var packageName: FqName? = null
|
|
||||||
var container = classifier.getContainingDeclaration()
|
|
||||||
while (container is ClassDescriptor) {
|
|
||||||
container = container.getContainingDeclaration()
|
|
||||||
}
|
|
||||||
if (container is PackageFragmentDescriptor) {
|
|
||||||
packageName = container.fqName
|
|
||||||
}
|
|
||||||
|
|
||||||
val itemText = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type)
|
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) {
|
override fun renderElement(presentation: LookupElementPresentation) {
|
||||||
super.renderElement(presentation)
|
super.renderElement(presentation)
|
||||||
presentation.setItemText(itemText)
|
presentation.setItemText(itemText)
|
||||||
|
|
||||||
presentation.clearTail()
|
|
||||||
if (packageName != null) {
|
|
||||||
presentation.appendTailText(" ($packageName)", true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-7
@@ -44,13 +44,14 @@ public class LookupElementFactory(
|
|||||||
public fun createLookupElement(
|
public fun createLookupElement(
|
||||||
descriptor: DeclarationDescriptor,
|
descriptor: DeclarationDescriptor,
|
||||||
boldImmediateMembers: Boolean,
|
boldImmediateMembers: Boolean,
|
||||||
qualifyNestedClasses: Boolean = false
|
qualifyNestedClasses: Boolean = false,
|
||||||
|
includeClassTypeArguments: Boolean = true
|
||||||
): LookupElement {
|
): LookupElement {
|
||||||
val _descriptor = if (descriptor is CallableMemberDescriptor)
|
val _descriptor = if (descriptor is CallableMemberDescriptor)
|
||||||
DescriptorUtils.unwrapFakeOverride(descriptor)
|
DescriptorUtils.unwrapFakeOverride(descriptor)
|
||||||
else
|
else
|
||||||
descriptor
|
descriptor
|
||||||
var element = createLookupElement(_descriptor, DescriptorToSourceUtils.descriptorToDeclaration(_descriptor), qualifyNestedClasses)
|
var element = createLookupElement(_descriptor, DescriptorToSourceUtils.descriptorToDeclaration(_descriptor), qualifyNestedClasses, includeClassTypeArguments)
|
||||||
|
|
||||||
val weight = callableWeight(descriptor)
|
val weight = callableWeight(descriptor)
|
||||||
if (weight != null) {
|
if (weight != null) {
|
||||||
@@ -99,7 +100,7 @@ public class LookupElementFactory(
|
|||||||
GRAYED
|
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) {
|
val lookupObject = object : DeclarationLookupObjectImpl(null, psiClass, resolutionFacade) {
|
||||||
override fun getIcon(flags: Int) = psiClass.getIcon(flags)
|
override fun getIcon(flags: Int) = psiClass.getIcon(flags)
|
||||||
}
|
}
|
||||||
@@ -107,7 +108,7 @@ public class LookupElementFactory(
|
|||||||
.withInsertHandler(KotlinClassInsertHandler)
|
.withInsertHandler(KotlinClassInsertHandler)
|
||||||
|
|
||||||
val typeParams = psiClass.getTypeParameters()
|
val typeParams = psiClass.getTypeParameters()
|
||||||
if (typeParams.isNotEmpty()) {
|
if (includeClassTypeArguments && typeParams.isNotEmpty()) {
|
||||||
element = element.appendTailText(typeParams.map { it.getName() }.joinToString(", ", "<", ">"), true)
|
element = element.appendTailText(typeParams.map { it.getName() }.joinToString(", ", "<", ">"), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +139,8 @@ public class LookupElementFactory(
|
|||||||
private fun createLookupElement(
|
private fun createLookupElement(
|
||||||
descriptor: DeclarationDescriptor,
|
descriptor: DeclarationDescriptor,
|
||||||
declaration: PsiElement?,
|
declaration: PsiElement?,
|
||||||
qualifyNestedClasses: Boolean = false
|
qualifyNestedClasses: Boolean,
|
||||||
|
includeClassTypeArguments: Boolean
|
||||||
): LookupElement {
|
): LookupElement {
|
||||||
if (descriptor is ClassifierDescriptor &&
|
if (descriptor is ClassifierDescriptor &&
|
||||||
declaration is PsiClass &&
|
declaration is PsiClass &&
|
||||||
@@ -146,7 +148,7 @@ public class LookupElementFactory(
|
|||||||
// for java classes we create special lookup elements
|
// for java classes we create special lookup elements
|
||||||
// because they must be equal to ones created in TypesCompletion
|
// because they must be equal to ones created in TypesCompletion
|
||||||
// otherwise we may have duplicates
|
// otherwise we may have duplicates
|
||||||
return createLookupElementForJavaClass(declaration, qualifyNestedClasses)
|
return createLookupElementForJavaClass(declaration, qualifyNestedClasses, includeClassTypeArguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for constructor use name and icon of containing class
|
// for constructor use name and icon of containing class
|
||||||
@@ -180,7 +182,7 @@ public class LookupElementFactory(
|
|||||||
|
|
||||||
is ClassDescriptor -> {
|
is ClassDescriptor -> {
|
||||||
val typeParams = descriptor.getTypeConstructor().getParameters()
|
val typeParams = descriptor.getTypeConstructor().getParameters()
|
||||||
if (typeParams.isNotEmpty()) {
|
if (includeClassTypeArguments && typeParams.isNotEmpty()) {
|
||||||
element = element.appendTailText(typeParams.map { it.getName().asString() }.joinToString(", ", "<", ">"), true)
|
element = element.appendTailText(typeParams.map { it.getName().asString() }.joinToString(", ", "<", ">"), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user