-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d50b3f8
commit ad14f2e
Showing
35 changed files
with
180 additions
and
115 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
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
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
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
31 changes: 31 additions & 0 deletions
31
kotlin-code-generation-test/src/main/kotlin/_reflection.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.toolisticon.kotlin.generation.test | ||
|
||
import kotlin.reflect.KClass | ||
import kotlin.reflect.full.createInstance | ||
import kotlin.reflect.full.primaryConstructor | ||
|
||
|
||
/** | ||
* Create instance of type `<T>` from [KClass]. | ||
*/ | ||
inline fun <reified T : Any> KClass<out Any>.callPrimaryConstructor(vararg params: Any): T { | ||
// TODO "call" is not resolvable | ||
return if (params.isEmpty()) { | ||
this.createInstance() | ||
} else { | ||
val pc = requireNotNull(this.primaryConstructor) | ||
pc.call(*params) | ||
} as T | ||
} | ||
|
||
/** | ||
* Get value of type `T` of field. | ||
* | ||
* @param name name of the field | ||
* @return value T | ||
*/ | ||
// TODO looking for a pure kotlin reflect solution | ||
inline fun <reified T : Any> Any.getFieldValue(name: String): T = this::class.java | ||
.getDeclaredField(name) | ||
.apply { isAccessible = true } | ||
.get(this) as T |
Oops, something went wrong.