com.itangcent.intellij.extend.guice.EncounterProvider.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guice-action Show documentation
Show all versions of guice-action Show documentation
Help for developing plugins for JetBrains products.
KotlinAnAction:provide ActionContext(support inject guice) for actionPerformed
The newest version!
package com.itangcent.intellij.extend.guice
import com.google.inject.Key
import com.google.inject.Provider
import com.google.inject.spi.TypeEncounter
/**
* Like a [com.google.inject.Provider] but which is also given an [TypeEncounter]
*
* @version $Revision: 1.1 $
*/
abstract class EncounterProvider {
abstract operator fun get(encounter: TypeEncounter<*>): Provider
companion object {
/**
* Returns a new encounter provider for the given key
*/
fun encounterProvider(key: Key): EncounterProvider {
return object : EncounterProvider() {
override fun get(encounter: TypeEncounter<*>): Provider {
return encounter.getProvider(key)
}
}
}
/**
* Returns a new encounter provider for the given type
*/
fun encounterProvider(type: Class): EncounterProvider {
return object : EncounterProvider() {
override fun get(encounter: TypeEncounter<*>): Provider {
return encounter.getProvider(type)
}
}
}
/**
* Returns a new encounter provider for the given instance
*/
fun encounterProvider(instance: T): EncounterProvider {
return object : EncounterProvider() {
override fun get(encounter: TypeEncounter<*>): Provider {
return Provider { instance }
}
}
}
}
}