Fix AIOOBE when completion started on empty file
[idea/community.git] / plugins / stats-collector / src / com / intellij / completion / FeatureManagerImpl.kt
1 /*
2  * Copyright 2000-2017 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.intellij.completion
18
19 import com.intellij.openapi.application.ApplicationManager
20 import com.intellij.openapi.components.ApplicationComponent
21 import com.jetbrains.completion.feature.*
22 import com.jetbrains.completion.feature.impl.CompletionFactors
23 import com.jetbrains.completion.feature.impl.FeatureInterpreterImpl
24 import com.jetbrains.completion.feature.impl.FeatureManagerFactory
25 import com.jetbrains.completion.feature.impl.FeatureReader
26
27 /**
28  * @author Vitaliy.Bibaev
29  */
30 class FeatureManagerImpl : FeatureManager, ApplicationComponent {
31     companion object {
32         fun getInstance(): FeatureManager = ApplicationManager.getApplication().getComponent(FeatureManager::class.java)
33     }
34
35     private lateinit var manager: FeatureManager
36
37     override val binaryFactors: List<BinaryFeature> get() = manager.binaryFactors
38     override val doubleFactors: List<DoubleFeature> get() = manager.doubleFactors
39     override val categorialFactors: List<CatergorialFeature> get() = manager.categorialFactors
40     override val ignoredFactors: Set<String> get() = manager.ignoredFactors
41     override val completionFactors: CompletionFactors get() = manager.completionFactors
42     override val featureOrder: Map<String, Int> get() = manager.featureOrder
43
44     override fun createTransformer(): Transformer {
45         return manager.createTransformer()
46     }
47
48     override fun isUserFeature(name: String): Boolean = false
49
50     override fun initComponent() {
51         manager = FeatureManagerFactory().createFeatureManager(FeatureReader, FeatureInterpreterImpl())
52     }
53
54     override fun allFeatures(): List<Feature> = manager.allFeatures()
55 }