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

godot.annotation.processor.visitor.MetadataAnnotationVisitor.kt Maven / Gradle / Ivy

There is a newer version: 0.10.0-4.3.0
Show newest version
package godot.annotation.processor.visitor

import com.google.devtools.ksp.KspExperimental
import com.google.devtools.ksp.getAnnotationsByType
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSVisitorVoid
import godot.annotation.RegisteredClassMetadata
import godot.annotation.processor.ext.hasCompilationErrors
import godot.entrygenerator.model.RegisteredClassMetadataContainer

/**
 * Collects [RegisteredClassMetadata] annotations for registration file generation by the main compilation of the project
 */
internal class MetadataAnnotationVisitor: KSVisitorVoid() {
    private val _registeredClassMetadataContainers: MutableList = mutableListOf()
    val registeredClassMetadataContainers: List = _registeredClassMetadataContainers

    @OptIn(KspExperimental::class)
    override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) {
        if (!classDeclaration.hasCompilationErrors()) {
            classDeclaration
                .getAnnotationsByType(RegisteredClassMetadata::class)
                .firstOrNull()
                ?.let { annotation ->
                    _registeredClassMetadataContainers.add(
                        RegisteredClassMetadataContainer(
                            registeredName = annotation.registeredName,
                            baseType = annotation.baseType,
                            fqName = annotation.fqName,
                            relativeSourcePath = annotation.relativeSourcePath,
                            compilationTimeRelativeRegistrationFilePath = annotation.compilationTimeRelativeRegistrationFilePath,
                            projectName = annotation.projectName,
                            superTypes = annotation.superTypes,
                            signals = annotation.signals,
                            properties = annotation.properties,
                            functions = annotation.functions,
                        )
                    )
                }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy