From 900c7b47ba9a328f03f42841e865ba8892b3f542 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sun, 15 Apr 2012 18:57:28 +0400 Subject: [PATCH] KT-1754 Intrinsic kotlin types and function don't have icons in completion #KT-1754 fixed --- .../jet/plugin/JetDescriptorIconProvider.java | 70 +++++++++++++++++++ .../completion/DescriptorLookupConverter.java | 7 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/JetDescriptorIconProvider.java diff --git a/idea/src/org/jetbrains/jet/plugin/JetDescriptorIconProvider.java b/idea/src/org/jetbrains/jet/plugin/JetDescriptorIconProvider.java new file mode 100644 index 00000000000..cf1b7adc0a6 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/JetDescriptorIconProvider.java @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.PlatformIcons; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.*; + +import javax.swing.*; + +/** + * @author Nikolay Krasko + */ +public final class JetDescriptorIconProvider { + + private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.compiler.JetCompiler"); + + private JetDescriptorIconProvider() { + } + + public static Icon getIcon(@NotNull DeclarationDescriptor descriptor) { + if (descriptor instanceof NamespaceDescriptor) { + return PlatformIcons.PACKAGE_OPEN_ICON; + } + if (descriptor instanceof FunctionDescriptor) { + return JetIcons.FUNCTION; + } + if (descriptor instanceof ClassDescriptor) { + switch (((ClassDescriptor)descriptor).getKind()) { + case TRAIT: + return JetIcons.TRAIT; + case ENUM_CLASS: + return PlatformIcons.ENUM_ICON; + case ENUM_ENTRY: + return PlatformIcons.ENUM_ICON; + case ANNOTATION_CLASS: + return PlatformIcons.ANNOTATION_TYPE_ICON; + case OBJECT: + return JetIcons.OBJECT; + case CLASS: + return PlatformIcons.CLASS_ICON; + default: + LOG.warn("No icon for descriptor: " + descriptor); + return null; + } + } + + if (descriptor instanceof PropertyDescriptor) { + return ((PropertyDescriptor)descriptor).isVar() ? JetIcons.VAR : JetIcons.VAL; + } + + LOG.warn("No icon for descriptor: " + descriptor); + return null; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/completion/DescriptorLookupConverter.java b/idea/src/org/jetbrains/jet/plugin/completion/DescriptorLookupConverter.java index d3be08e37c5..1345adc3df5 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/DescriptorLookupConverter.java +++ b/idea/src/org/jetbrains/jet/plugin/completion/DescriptorLookupConverter.java @@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.plugin.JetDescriptorIconProvider; import org.jetbrains.jet.plugin.completion.handlers.JetClassInsertHandler; import org.jetbrains.jet.plugin.completion.handlers.JetFunctionInsertHandler; import org.jetbrains.jet.resolve.DescriptorRenderer; @@ -50,7 +51,8 @@ public final class DescriptorLookupConverter { private DescriptorLookupConverter() {} @NotNull - public static LookupElement createLookupElement(@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor, @Nullable PsiElement declaration) { + public static LookupElement createLookupElement(@NotNull BindingContext bindingContext, + @NotNull DeclarationDescriptor descriptor, @Nullable PsiElement declaration) { LookupElementBuilder element = LookupElementBuilder.create( new JetLookupObject(descriptor, bindingContext, declaration), descriptor.getName()); @@ -106,6 +108,9 @@ public final class DescriptorLookupConverter { if (declaration != null) { element = element.setIcon(declaration.getIcon(Iconable.ICON_FLAG_OPEN | Iconable.ICON_FLAG_VISIBILITY)); } + else { + element = element.setIcon(JetDescriptorIconProvider.getIcon(descriptor)); + } return element; }