type Arguments
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).
In
List<String>
,String
is a type argument forList
.In
Map<String, Int>
, bothString
andInt
are type arguments forMap
.In
List<Set<String>>
,Set<String>
is a type argument forList
. It has a nested type argumentString
.For a non-generic type like
String
, this property would returnnull
.
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.