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

net.bjoernpetersen.musicbot.api.plugin.management.DependencyFinder.kt Maven / Gradle / Ivy

There is a newer version: 0.25.0
Show newest version
package net.bjoernpetersen.musicbot.api.plugin.management

import com.google.inject.spi.InjectionPoint
import net.bjoernpetersen.musicbot.spi.plugin.Plugin
import kotlin.reflect.KClass
import kotlin.reflect.full.isSubclassOf

/**
 * Find the immediate dependencies of a plugin.
 */
fun Plugin.findDependencies(): Set> {
    return InjectionPoint.forInstanceMethodsAndFields(this::class.java)
        .asSequence()
        .flatMap { it.dependencies.asSequence() }
        .map { it.key }
        .map { it.typeLiteral.rawType }
        .map { it as Class }
        .map { it.kotlin }
        .filter { it.isSubclassOf(Plugin::class) }
        .map {
            @Suppress("UNCHECKED_CAST")
            it as KClass
        }
        .toSet()
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy