Verify Source Declarations
The source declaration (sourceDeclaration property) holds the reference to the actual type declaration such as class or interface.
Konsist API allows verifying properties of such types, e.g.:
Check if property type implements certain interface
Check if function return type name ends with
RepositoryCheck if parent class is annotated with given annotation
Every type used by a declaration (e.g. property type, function return type, parent) exposes the sourceDeclaration property.
Let's look at a few examples:
Verify Property Source Declaration
Check if the current property has a type which is a class declaration having the internal modifier:
// Code Snippet
internal class Engine
val current: Engine? = null
// Konsist test
Konsist
.scopeFromProject()
.properties()
.assertTrue {
it
.type
?.sourceDeclaration
?.asClassDeclaration()
?.hasInternalModifier // true
}
Verify Function Return Type Source Declaration
Check if function return type is a basic Kotlin type:
Verify Class Has Interface Source Declaration
Check if all class parents are interfaces:
Last updated