-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add collection element and map k/v type gen for random class instance (…
- Loading branch information
Showing
7 changed files
with
321 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 41 additions & 7 deletions
48
core/src/main/kotlin/io/github/serpro69/kfaker/provider/misc/ParameterInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,59 @@ | ||
package io.github.serpro69.kfaker.provider.misc | ||
|
||
import kotlin.reflect.KCallable | ||
import kotlin.reflect.KParameter | ||
import kotlin.reflect.KType | ||
|
||
/** | ||
* Provides additional information about Class parameter to custom defined generators. | ||
* The reason why KParameter is not used is that you will want to provide | ||
* additional information about parameter that is not available in KParameter class. | ||
* | ||
* @property index 0-based index of this parameter in the parameter list of its containing callable. | ||
* | ||
* @property name Name of this parameter as it was declared in the source code, | ||
* or `null` if the parameter has no name or its name is not available at runtime. | ||
* Examples of nameless parameters include `this` instance for member functions, | ||
* extension receiver for extension functions or properties, parameters of Java methods | ||
* compiled without the debug information, and others. | ||
* | ||
* @property type Type of this parameter. For a `vararg` parameter, this is the type of the corresponding array, | ||
* not the individual element. | ||
* | ||
* @property kind Kind of this parameter. | ||
* Kind represents a particular position of the parameter declaration in the source code, | ||
* such as an instance, an extension receiver parameter or a value parameter. | ||
* | ||
* @property isOptional | ||
* `true` if this parameter is optional and can be omitted when making a call via [KCallable.callBy], or `false` otherwise. | ||
* | ||
* A parameter is optional in any of the two cases: | ||
* 1. The default value is provided at the declaration of this parameter. | ||
* 2. The parameter is declared in a member function and one of the corresponding parameters in the super functions is optional. | ||
* | ||
* @property isVararg | ||
* `true` if this parameter is `vararg`. | ||
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/functions.html#variable-number-of-arguments-varargs) | ||
* for more information. | ||
*/ | ||
data class ParameterInfo( | ||
val index: Int, | ||
val name: String, | ||
val isOptional: Boolean, | ||
val isVararg: Boolean | ||
val isVararg: Boolean, | ||
val type: KType, | ||
val kind: KParameter.Kind, | ||
) | ||
|
||
/** | ||
* Extension function that maps KParameter to ParameterInfo dataclass. | ||
*/ | ||
internal fun KParameter.toParameterInfo() = ParameterInfo( | ||
index = index, | ||
name = name.toString(), | ||
isOptional = isOptional, | ||
isVararg = isVararg | ||
) | ||
internal fun KParameter.toParameterInfo() = | ||
ParameterInfo( | ||
index = index, | ||
name = name.toString(), | ||
isOptional = isOptional, | ||
isVararg = isVararg, | ||
type = type, | ||
kind = kind, | ||
) |
Oops, something went wrong.