From 66289f0b4ad74a4b91404308745a2836f3a6773e Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 1 Dec 2014 15:16:23 +0300 Subject: [PATCH] Completion: our own lookup elements for java classes --- .../plugin/completion/LookupElementFactory.kt | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/completion/LookupElementFactory.kt b/idea/src/org/jetbrains/jet/plugin/completion/LookupElementFactory.kt index 0aeb7b59f28..cd4575318b0 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/LookupElementFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/LookupElementFactory.kt @@ -31,13 +31,13 @@ import org.jetbrains.jet.renderer.DescriptorRenderer import com.intellij.psi.PsiClass import org.jetbrains.jet.asJava.KotlinLightClass import org.jetbrains.jet.lang.resolve.java.JavaResolverUtils -import com.intellij.codeInsight.completion.JavaPsiClassReferenceElement import com.intellij.codeInsight.lookup.LookupElementDecorator import com.intellij.codeInsight.lookup.LookupElementPresentation import org.jetbrains.jet.lang.types.JetType import org.jetbrains.jet.plugin.caches.resolve.ResolutionFacade import java.awt.Color import org.jetbrains.jet.lang.types.TypeUtils +import com.intellij.codeInsight.lookup.DefaultLookupItemRenderer public open class LookupElementFactory protected() { public open fun createLookupElement(resolutionFacade: ResolutionFacade, descriptor: DeclarationDescriptor): LookupElement { @@ -49,7 +49,29 @@ public open class LookupElementFactory protected() { } public fun createLookupElementForJavaClass(psiClass: PsiClass): LookupElement { - return JavaPsiClassReferenceElement(psiClass).setInsertHandler(KotlinClassInsertHandler) + var element = LookupElementBuilder.create(psiClass, psiClass.getName()).withInsertHandler(KotlinClassInsertHandler) + + val typeParams = psiClass.getTypeParameters() + if (typeParams.isNotEmpty()) { + element = element.appendTailText(typeParams.map { it.getName() }.joinToString(", ", "<", ">"), true) + } + + val qualifiedName = psiClass.getQualifiedName() + val dotIndex = qualifiedName.lastIndexOf('.') + val packageName = if (dotIndex <= 0) "" else qualifiedName.substring(0, dotIndex) + element = element.appendTailText(" ($packageName)", true) + + if (psiClass.isDeprecated()) { + element = element.setStrikeout(true) + } + + // add icon in renderElement only to pass presentation.isReal() + return object : LookupElementDecorator(element) { + override fun renderElement(presentation: LookupElementPresentation) { + super.renderElement(presentation) + presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(element, presentation.isReal())) + } + } } private fun createLookupElement(