Fixed icons for java and compiled classes broken before

This commit is contained in:
Valentin Kipyatkov
2015-06-19 19:41:24 +03:00
parent ecbc7ba5b6
commit fa588ace57
3 changed files with 27 additions and 17 deletions
@@ -17,27 +17,29 @@
package org.jetbrains.kotlin.idea.completion package org.jetbrains.kotlin.idea.completion
import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiDocCommentOwner import com.intellij.psi.PsiDocCommentOwner
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import javax.swing.Icon
/** /**
* Stores information about resolved descriptor and position of that descriptor. * Stores information about resolved descriptor and position of that descriptor.
* Position will be used for sorting * Position will be used for sorting
*/ */
public class DeclarationLookupObjectImpl( public abstract class DeclarationLookupObjectImpl(
public override val descriptor: DeclarationDescriptor?, public final override val descriptor: DeclarationDescriptor?,
public override val psiElement: PsiElement?, public final override val psiElement: PsiElement?,
private val resolutionFacade: ResolutionFacade private val resolutionFacade: ResolutionFacade
): DeclarationLookupObject { ): DeclarationLookupObject {
init { init {
assert(descriptor != null || psiElement != null) assert(descriptor != null || psiElement != null)
} }
override fun toString() = super.toString() + " " + (descriptor ?: psiElement) override fun toString() = super<DeclarationLookupObject>.toString() + " " + (descriptor ?: psiElement)
override fun hashCode(): Int { override fun hashCode(): Int {
return if (descriptor != null) descriptor.getOriginal().hashCode() else psiElement!!.hashCode() return if (descriptor != null) descriptor.getOriginal().hashCode() else psiElement!!.hashCode()
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
import javax.swing.Icon
public class LookupElementFactory( public class LookupElementFactory(
private val resolutionFacade: ResolutionFacade, private val resolutionFacade: ResolutionFacade,
@@ -98,7 +99,9 @@ public class LookupElementFactory(
} }
public fun createLookupElementForJavaClass(psiClass: PsiClass): LookupElement { public fun createLookupElementForJavaClass(psiClass: PsiClass): LookupElement {
val lookupObject = DeclarationLookupObjectImpl(null, psiClass, resolutionFacade) val lookupObject = object : DeclarationLookupObjectImpl(null, psiClass, resolutionFacade) {
override fun getIcon(flags: Int) = psiClass.getIcon(flags)
}
var element = LookupElementBuilder.create(lookupObject, psiClass.getName()) var element = LookupElementBuilder.create(lookupObject, psiClass.getName())
.withInsertHandler(KotlinClassInsertHandler) .withInsertHandler(KotlinClassInsertHandler)
@@ -115,13 +118,7 @@ public class LookupElementFactory(
element = element.setStrikeout(true) element = element.setStrikeout(true)
} }
// add icon in renderElement only to pass presentation.isReal() return element.withIconFromLookupObject()
return object : LookupElementDecorator<LookupElement>(element) {
override fun renderElement(presentation: LookupElementPresentation) {
super.renderElement(presentation)
presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(element, presentation.isReal()))
}
}
} }
private fun createLookupElement( private fun createLookupElement(
@@ -149,11 +146,11 @@ public class LookupElementFactory(
iconDeclaration = declaration iconDeclaration = declaration
} }
val name = nameAndIconDescriptor.getName().asString() val name = nameAndIconDescriptor.getName().asString()
val icon = JetDescriptorIconProvider.getIcon(nameAndIconDescriptor, iconDeclaration, Iconable.ICON_FLAG_VISIBILITY)
val lookupObject = DeclarationLookupObjectImpl(descriptor, declaration, resolutionFacade) val lookupObject = object : DeclarationLookupObjectImpl(descriptor, declaration, resolutionFacade) {
override fun getIcon(flags: Int) = JetDescriptorIconProvider.getIcon(nameAndIconDescriptor, iconDeclaration, flags)
}
var element = LookupElementBuilder.create(lookupObject, name) var element = LookupElementBuilder.create(lookupObject, name)
.withIcon(icon)
when (descriptor) { when (descriptor) {
is FunctionDescriptor -> { is FunctionDescriptor -> {
@@ -213,7 +210,17 @@ public class LookupElementFactory(
element.putUserData(KotlinCompletionCharFilter.ACCEPT_OPENING_BRACE, Unit) element.putUserData(KotlinCompletionCharFilter.ACCEPT_OPENING_BRACE, Unit)
} }
return element return element.withIconFromLookupObject()
}
private fun LookupElement.withIconFromLookupObject(): LookupElement {
// add icon in renderElement only to pass presentation.isReal()
return object : LookupElementDecorator<LookupElement>(this) {
override fun renderElement(presentation: LookupElementPresentation) {
super.renderElement(presentation)
presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(this@withIconFromLookupObject, presentation.isReal()))
}
}
} }
private fun callableWeight(descriptor: DeclarationDescriptor): CallableWeight? { private fun callableWeight(descriptor: DeclarationDescriptor): CallableWeight? {
@@ -16,10 +16,11 @@
package org.jetbrains.kotlin.idea.core.completion package org.jetbrains.kotlin.idea.core.completion
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
public interface DeclarationLookupObject { public interface DeclarationLookupObject : Iconable {
public val psiElement: PsiElement? public val psiElement: PsiElement?
public val descriptor: DeclarationDescriptor? public val descriptor: DeclarationDescriptor?
public val isDeprecated: Boolean public val isDeprecated: Boolean