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

name.remal.gradle_plugins.dsl.reflective_project_plugin.action_param_injector.ActionParamInjector.kt Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package name.remal.gradle_plugins.dsl.reflective_project_plugin.action_param_injector

import com.google.common.reflect.TypeToken
import name.remal.asClass
import name.remal.hierarchy
import name.remal.uncheckedCast
import org.gradle.api.Project
import java.lang.reflect.ParameterizedType

abstract class ActionParamInjector : Comparable> {

    abstract fun createValue(project: Project): ParamType

    open val paramType: Class by lazy {
        val type = TypeToken.of(this.javaClass).getSupertype(ActionParamInjector::class.java).type
        if (type !is ParameterizedType) throw IllegalStateException("$type is not instance of ParameterizedType")
        return@lazy type.actualTypeArguments[0].asClass().uncheckedCast>()
    }

    private val hierarchySize: Int by lazy { paramType.hierarchy.size }

    override fun compareTo(other: ActionParamInjector<*>): Int {
        hierarchySize.compareTo(other.hierarchySize).let { if (it != 0) return it }
        paramType.name.compareTo(other.paramType.name).let { if (it != 0) return it }
        return 0
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy