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

com.dailystudio.devbricksx.ksp.utils.InMemoryCompanionUtils.kt Maven / Gradle / Ivy

package com.dailystudio.devbricksx.ksp.utils

import com.google.devtools.ksp.getAllSuperTypes
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSType
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.ksp.toClassName
import com.squareup.kotlinpoet.ksp.toTypeName

object InMemoryCompanionUtils {

    fun findInMemoryObjectInSuperTypes(symbol: KSClassDeclaration): KSType? {
        val typeOfInMemoryObject = TypeNameUtils.typeOfInMemoryObject()
        symbol.getAllSuperTypes().forEach {
            val classNameOfSupertype = it.toClassName()
            if (classNameOfSupertype == typeOfInMemoryObject) {
                return it
            }
        }

        return null
    }

    fun getKeyForInMemoryObject(symbol: KSClassDeclaration): TypeName? {
        val found = findInMemoryObjectInSuperTypes(symbol)

        return found?.arguments?.first()?.toTypeName()
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy