All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.itangcent.intellij.extend.guice.EncounterProvider.kt Maven / Gradle / Ivy

Go to download

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 }
                }
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy