summaryrefslogtreecommitdiff
path: root/plugins/kotlin/fir/src/org/jetbrains/kotlin/idea/completion/KotlinFirIconProvider.kt
blob: 64383763fa210b1ee99a9fb1a8dd1079097b4a9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.

package org.jetbrains.kotlin.idea.completion

import com.intellij.util.PlatformIcons
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
import javax.swing.Icon

internal object KotlinFirIconProvider {
    fun getIconFor(symbol: KtSymbol): Icon? {
        if (symbol is KtFunctionSymbol) {
            val isAbstract = symbol.modality == Modality.ABSTRACT

            return when {
                symbol.isExtension -> {
                    if (isAbstract) KotlinIcons.ABSTRACT_EXTENSION_FUNCTION else KotlinIcons.EXTENSION_FUNCTION
                }
                symbol.symbolKind == KtSymbolKind.CLASS_MEMBER -> {
                    if (isAbstract) PlatformIcons.ABSTRACT_METHOD_ICON else PlatformIcons.METHOD_ICON
                }
                else -> KotlinIcons.FUNCTION
            }
        }

        if (symbol is KtClassOrObjectSymbol) {
            val isAbstract = (symbol as? KtNamedClassOrObjectSymbol)?.modality == Modality.ABSTRACT

            return when (symbol.classKind) {
                KtClassKind.CLASS -> if (isAbstract) KotlinIcons.ABSTRACT_CLASS else KotlinIcons.CLASS
                KtClassKind.ENUM_CLASS, KtClassKind.ENUM_ENTRY -> KotlinIcons.ENUM
                KtClassKind.ANNOTATION_CLASS -> KotlinIcons.ANNOTATION
                KtClassKind.OBJECT, KtClassKind.COMPANION_OBJECT -> KotlinIcons.OBJECT
                KtClassKind.INTERFACE -> KotlinIcons.INTERFACE
                KtClassKind.ANONYMOUS_OBJECT -> KotlinIcons.OBJECT
            }
        }

        if (symbol is KtValueParameterSymbol) return KotlinIcons.PARAMETER

        if (symbol is KtLocalVariableSymbol) return if (symbol.isVal) KotlinIcons.VAL else KotlinIcons.VAR

        if (symbol is KtPropertySymbol) return if (symbol.isVal) KotlinIcons.FIELD_VAL else KotlinIcons.FIELD_VAR

        if (symbol is KtTypeParameterSymbol) return PlatformIcons.CLASS_ICON

        if (symbol is KtTypeAliasSymbol) return KotlinIcons.TYPE_ALIAS

        if (symbol is KtEnumEntrySymbol) return KotlinIcons.ENUM

        return null
    }
}