Verify Generics
Type parameter vs type argument
To undersigned Konsist API let's look at the difference between generic type parameters
and generic type arguments
:
Type Parameter is the placeholder (like
T
) you write when creating a class or function (declaration site)Type Argument is the actual type (like
String
orInt
) you provide when using that class or function (use site)
Simple Examples:
Verify Type Parameters
Type parameters can be defined, for example, inside class or function.
Check whether a class's generic type parameter has the name UiState
:
UiState
:Check whether function type parameters
has out
modifier:
type parameters
has out
modifier:Verify Type Arguments
Check whether a property generic type argument has the name Service
:
Service
:The flatten()
extension method allows to flatten type parameters structure:
For a type argument like
String
, it returnslistOf()
.For a type argument like
List<String>
, it returnslistOf(String)
.For a type argument like
Map<List<String>, Int>
, it returnslistOf("List, String, Int)
.
Check if all functions parameters are have generic type argument ending with UIState
:
UIState
:Check all parents have `String` type argument:
Last updated