Update api in UserFactorsManager
authorVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Thu, 23 Nov 2017 10:00:53 +0000 (13:00 +0300)
committerVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Mon, 27 Nov 2017 16:04:24 +0000 (19:04 +0300)
plugins/stats-collector/src/com/intellij/stats/personalization/UserFactor.kt
plugins/stats-collector/src/com/intellij/stats/personalization/UserFactorsManager.kt
plugins/stats-collector/src/com/intellij/stats/personalization/impl/UserFactorsManagerImpl.kt

index 11c28155ee1008c8259ec207c18b27de92732ec5..e00ea4d541c1efae0034407b7515da7be18a46ca 100644 (file)
@@ -1,13 +1,14 @@
 package com.intellij.stats.personalization
 
-import com.intellij.codeInsight.lookup.LookupElement
-
 /**
  * @author Vitaliy.Bibaev
  */
 interface UserFactor {
     val id: String
 
-    fun store(element: LookupElement)
-    fun extract(element: LookupElement): Comparable<Nothing>
+    fun compute(): String
+
+    interface FeatureFactor : UserFactor {
+        fun update(value: Any?)
+    }
 }
index 30ad88e0f5a05994a2638eeeb07e01c913e3b4fb..ce38300bee7b2af0ca5d306adcda79d380dbc2c8 100644 (file)
@@ -1,16 +1,22 @@
 package com.intellij.stats.personalization
 
 import com.intellij.openapi.project.Project
+import com.intellij.openapi.util.Key
 
 /**
  * @author Vitaliy.Bibaev
  */
 interface UserFactorsManager {
   companion object {
+    val USER_FACTORS_KEY = Key.create<Map<String, String>>("com.intellij.stats.personalization.userFactors")
     fun getInstance(project: Project): UserFactorsManager = project.getComponent(UserFactorsManager::class.java)
   }
 
   fun getAllFactorIds(): List<String>
 
+  fun getAllFactors(): List<UserFactor>
+
+  fun getFeatureFactor(featureName: String): UserFactor.FeatureFactor?
+
   fun getFactor(id: String): UserFactor
 }
index 587db49d8ea829787e09ac9ab2f29b6133081f78..b6d6cfdaae427281cc5ee46b7e2b6ce7a66abcfb 100644 (file)
@@ -1,5 +1,6 @@
 package com.intellij.stats.personalization.impl
 
+import com.intellij.completion.FeatureManager
 import com.intellij.openapi.components.ProjectComponent
 import com.intellij.openapi.diagnostic.Logger
 import com.intellij.openapi.project.Project
@@ -11,19 +12,25 @@ import com.intellij.stats.personalization.UserFactorsManager
  */
 class UserFactorsManagerImpl(project: Project) : UserFactorsManager, ProjectComponent {
     private companion object {
+
         val LOG = Logger.getInstance(UserFactorsManagerImpl::class.java)
     }
-
     private val userFactors = mutableMapOf<String, UserFactor>()
-
     init {
         // TODO: register all factors here
+        FeatureManager.getInstance() // TODO: register feature-derived factors
     }
 
+    override fun getAllFactors(): List<UserFactor> = userFactors.values.toList()
+
     override fun getAllFactorIds(): List<String> = userFactors.keys.toList()
 
     override fun getFactor(id: String): UserFactor = userFactors[id]!!
 
+    override fun getFeatureFactor(featureName: String): UserFactor.FeatureFactor? {
+        return null
+    }
+
     private fun register(factor: UserFactor) {
         val old = userFactors.put(factor.id, factor)
         if (old != null) {