typeArguments

A list of type arguments associated with this declaration, if any. If there are no type arguments, this returns null.

Type arguments are used to specify concrete types for generic type parameters. They appear within angle brackets <> after a generic type name. Every type argument may contain nested type arguments (typeArguments property).

  1. In List<String>, String is a type argument for List.

  2. In Map<String, Int>, both String and Int are type arguments for Map.

  3. In List<Set<String>>, Set<String> is a type argument for List. It has a nested type argument String.

  4. For a non-generic type like String, this property would return null.

Kotlin snippet:

val sampleProperty: Map<String, Int> = emptyList()

Konsist:

Konsist
scopeFromProject()
.properties()
.first()
.type
?.typeArguments
?.map { it.name } // listOf("String", "Int")

The flattened list of type arguments can be obtained using the flatten extension function:

Kotlin snippet:

val sampleProperty: List<String, Map<Int, Boolean>> = emptyList()

Konsist:

Konsist
scopeFromProject()
.properties()
.first()
.type
.typeArguments // listOf("String", "Map<Int, Boolean>")
.flatten() // listOf("String", "Map", "Int", "Boolean")

Return

A list of KoTypeArgumentDeclaration representing the type arguments, or null if there are no type arguments.

See also