sourceDeclaration

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 class

  • KoInterfaceDeclaration represents interface

  • KoObjectDeclaration represents object

  • KoTypeAliasDeclaration represents type alias

  • KoImportAliasDeclaration represents import alias

  • KoKotlinTypeDeclaration represents Kotlin basic types and collections

  • KoFunctionDeclaration represents function type

  • KoExternalDeclaration 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 }