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

main.model.Model.kt Maven / Gradle / Ivy

There is a newer version: 0.76.0
Show newest version
package de.peekandpoke.ultra.meta.model

import com.squareup.kotlinpoet.ClassName
import de.peekandpoke.ultra.meta.GenericUsages
import de.peekandpoke.ultra.meta.ProcessorUtils
import javax.lang.model.element.TypeElement

fun ProcessorUtils.model(types: List) = Model(ctx, types)

class Model(
    override val ctx: ProcessorUtils.Context,
    types: List
) : ProcessorUtils, Iterable {

    val types = types.map { it.toMType() }

    private val genericUsages = GenericUsages(this, types)

    fun getGenericUsages(className: ClassName) = genericUsages.get(className)

    private fun TypeElement.toMType(): MType = MType(
        this@Model,
        this,
        this.asTypeName()
    )

    fun getDirectChildTypes(parent: MType): List {
        return types.filter {
            it.directSuperTypes.any { superType -> superType == parent }
        }
    }

    override fun iterator(): Iterator = types.iterator()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy