source Declaration
Represents the source declaration associated with this type.
The sourceDeclaration
property provides access to the declaration of the type within the Kotlin codebase. It allows retrieving additional information about the declaration, such as its properties, functions, annotations, and other relevant metadata.
It points to an instance of KoSourceDeclaration, which serves as the base interface for various types:
KoClassDeclaration
represents classKoInterfaceDeclaration
represents interfaceKoObjectDeclaration
represents objectKoTypeAliasDeclaration
represents type aliasKoImportAliasDeclaration
represents import aliasKoKotlinTypeDeclaration
represents Kotlin basic types and collectionsKoFunctionDeclaration
represents function typeKoExternalDeclaration
represents declaration which is not defined in the project
For import statements, sourceDeclaration
refers to the declaration being imported. Similarly, for an import alias, sourceDeclaration
also refers to the declaration being imported, allowing direct access to the original declaration.
Example usage:
scope
.properties()
.types
.assertTrue { it.isInterface }