Skip to content

dpreussler/KuperReflect

Repository files navigation

Release Build Status codecov

KuperReflect

Easy reflection with Kotlin

in short

  • set private and final variables
  • syntax comparable to Kotlin Reflect (no dependency to it)
  • infix notation available

in detail

In Java world there is SuperReflect (a fork of jOOQ/jOOR) for fluent reflection.

Kotlin reflect offers a nice syntax itself but is limited in functionality compared.

KuperReflect combines both worlds: nice syntax including more variations and being able to set private or even final fields.

examples:

set non private on the property like Kotlin Reflect:

    val myClass = SomeClass()
    SomeClass::variable.set(tested, "something")

set non private on the instance itself:

    SomeClass().set(SomeClass::variable).to("something")

    SomeClass().set(SomeClass::variable) to "something"

    SomeClass().apply {
        set(SomeClass::variable) to "something"
    }

set private on the instance itself:

    SomeClass().set("variable").to("something")

    SomeClass().set("variable") to "something"

    SomeClass().apply {
        set("variable") to "something"
    }

use infix all the way:

    on(myClass) set "variable" to "something"
        
    on(myClass) set SomeClass::variable to "something"

Gradle

...
repositories {
    maven {url "https://jitpack.io"}
}

testCompile 'com.github.dpreussler:KuperReflect:v0.1'

About

set private and final variables with fluent kotlin syntax

Resources

License

Stars

Watchers

Forks

Packages

No packages published