// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.completion.ngram

import com.intellij.completion.ngram.slp.modeling.runners.ModelRunner
import com.intellij.lang.Language
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile
import com.intellij.psi.SmartPsiElementPointer

class NGramModelRunnerManager {

  private val myModelRunners: MutableMap<Language, ModelRunnerWithCache> = mutableMapOf()

  fun processFile(filePointer: SmartPsiElementPointer<PsiFile>, language: Language) {
    myModelRunners.getOrPut(language, { ModelRunnerWithCache() }).processFile(filePointer)
  }

  fun getModelRunnerForLanguage(language: Language): ModelRunner? {
    return myModelRunners[language]
  }

  companion object {
    fun getInstance(project: Project): NGramModelRunnerManager {
      return ServiceManager.getService(project, NGramModelRunnerManager::class.java)
    }
  }
}
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.completion.ngram

import com.intellij.completion.ngram.slp.modeling.runners.ModelRunner
import com.intellij.lang.Language
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile
import com.intellij.psi.SmartPsiElementPointer

class NGramModelRunnerManager {

  private val myModelRunners: MutableMap<String, ModelRunnerWithCache> = mutableMapOf()

  fun processFile(filePointer: SmartPsiElementPointer<PsiFile>, language: Language) {
    myModelRunners.getOrPut(language.id, { ModelRunnerWithCache() }).processFile(filePointer)
  }

  fun getModelRunnerForLanguage(language: Language): ModelRunner? {
    return myModelRunners[language.id]
  }

  companion object {
    fun getInstance(project: Project): NGramModelRunnerManager {
      return ServiceManager.getService(project, NGramModelRunnerManager::class.java)
    }
  }
}
Use string instead of Language as map key (to support plugin unloading)
Use string instead of Language as map key (to support plugin unloading)

GitOrigin-RevId: cd8b3540d7bbd7a6b5eeddf5ba33cc247aa58dc3
allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community,allotria/intellij-community